Skip to content

Commit ecb99f9

Browse files
committed
Reverted rust-analyser based on Ralph's comments
1 parent af3283f commit ecb99f9

File tree

5 files changed

+113
-130
lines changed

5 files changed

+113
-130
lines changed

src/tools/rust-analyzer/crates/hir-ty/src/consteval/tests.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2527,8 +2527,9 @@ fn const_transfer_memory() {
25272527
fn anonymous_const_block() {
25282528
check_number(
25292529
r#"
2530-
#[rustc_intrinsic]
2531-
pub fn size_of<T>() -> usize;
2530+
extern "rust-intrinsic" {
2531+
pub fn size_of<T>() -> usize;
2532+
}
25322533
25332534
const fn f<T>() -> usize {
25342535
let r = const { size_of::<T>() };

src/tools/rust-analyzer/crates/hir-ty/src/consteval/tests/intrinsics.rs

+95-116
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,12 @@ fn const_eval_select() {
204204
check_number(
205205
r#"
206206
//- minicore: fn
207-
#[rustc_intrinsic]
208-
pub unsafe fn const_eval_select<ARG, F, G, RET>(arg: ARG, called_in_const: F, called_at_rt: G) -> RET
209-
where
210-
G: FnOnce<ARG, Output = RET>,
211-
F: FnOnce<ARG, Output = RET>;
212-
207+
extern "rust-intrinsic" {
208+
pub fn const_eval_select<ARG, F, G, RET>(arg: ARG, called_in_const: F, called_at_rt: G) -> RET
209+
where
210+
G: FnOnce<ARG, Output = RET>,
211+
F: FnOnce<ARG, Output = RET>;
212+
}
213213
214214
const fn in_const(x: i32, y: i32) -> i32 {
215215
x + y
@@ -229,9 +229,9 @@ fn const_eval_select() {
229229
fn wrapping_add() {
230230
check_number(
231231
r#"
232-
#[rustc_intrinsic]
233-
pub unsafe fn wrapping_add<T>(a: T, b: T) -> T;
234-
232+
extern "rust-intrinsic" {
233+
pub fn wrapping_add<T>(a: T, b: T) -> T;
234+
}
235235
236236
const GOAL: u8 = wrapping_add(10, 250);
237237
"#,
@@ -244,12 +244,10 @@ fn ptr_offset_from() {
244244
check_number(
245245
r#"
246246
//- minicore: index, slice, coerce_unsized
247-
248-
#[rustc_intrinsic]
249-
pub unsafe fn ptr_offset_from<T>(ptr: *const T, base: *const T) -> isize;
250-
251-
#[rustc_intrinsic]
252-
pub unsafe fn ptr_offset_from_unsigned<T>(ptr: *const T, base: *const T) -> usize;
247+
extern "rust-intrinsic" {
248+
pub fn ptr_offset_from<T>(ptr: *const T, base: *const T) -> isize;
249+
pub fn ptr_offset_from_unsigned<T>(ptr: *const T, base: *const T) -> usize;
250+
}
253251
254252
const GOAL: isize = {
255253
let x = [1, 2, 3, 4, 5i32];
@@ -267,26 +265,29 @@ fn ptr_offset_from() {
267265
fn saturating() {
268266
check_number(
269267
r#"
270-
#[rustc_intrinsic]
271-
pub unsafe fn saturating_add<T>(a: T, b: T) -> T;
268+
extern "rust-intrinsic" {
269+
pub fn saturating_add<T>(a: T, b: T) -> T;
270+
}
272271
273272
const GOAL: u8 = saturating_add(10, 250);
274273
"#,
275274
255,
276275
);
277276
check_number(
278277
r#"
279-
#[rustc_intrinsic]
280-
pub unsafe fn saturating_sub<T>(a: T, b: T) -> T;
278+
extern "rust-intrinsic" {
279+
pub fn saturating_sub<T>(a: T, b: T) -> T;
280+
}
281281
282282
const GOAL: bool = saturating_sub(5u8, 7) == 0 && saturating_sub(8u8, 4) == 4;
283283
"#,
284284
1,
285285
);
286286
check_number(
287287
r#"
288-
#[rustc_intrinsic]
289-
pub unsafe fn saturating_add<T>(a: T, b: T) -> T;
288+
extern "rust-intrinsic" {
289+
pub fn saturating_add<T>(a: T, b: T) -> T;
290+
}
290291
291292
const GOAL: i8 = saturating_add(5, 8);
292293
"#,
@@ -329,17 +330,19 @@ fn allocator() {
329330
fn overflowing_add() {
330331
check_number(
331332
r#"
332-
#[rustc_intrinsic]
333-
pub unsafe fn add_with_overflow<T>(x: T, y: T) -> (T, bool);
333+
extern "rust-intrinsic" {
334+
pub fn add_with_overflow<T>(x: T, y: T) -> (T, bool);
335+
}
334336
335337
const GOAL: u8 = add_with_overflow(1, 2).0;
336338
"#,
337339
3,
338340
);
339341
check_number(
340342
r#"
341-
#[rustc_intrinsic]
342-
pub unsafe fn add_with_overflow<T>(x: T, y: T) -> (T, bool);
343+
extern "rust-intrinsic" {
344+
pub fn add_with_overflow<T>(x: T, y: T) -> (T, bool);
345+
}
343346
344347
const GOAL: u8 = add_with_overflow(1, 2).1 as u8;
345348
"#,
@@ -352,9 +355,9 @@ fn needs_drop() {
352355
check_number(
353356
r#"
354357
//- minicore: copy, sized
355-
#[rustc_intrinsic]
356-
pub unsafe fn needs_drop<T: ?Sized>() -> bool;
357-
358+
extern "rust-intrinsic" {
359+
pub fn needs_drop<T: ?Sized>() -> bool;
360+
}
358361
struct X;
359362
const GOAL: bool = !needs_drop::<i32>() && needs_drop::<X>();
360363
"#,
@@ -368,9 +371,9 @@ fn discriminant_value() {
368371
r#"
369372
//- minicore: discriminant, option
370373
use core::marker::DiscriminantKind;
371-
#[rustc_intrinsic]
372-
pub unsafe fn discriminant_value<T>(v: &T) -> <T as DiscriminantKind>::Discriminant;
373-
374+
extern "rust-intrinsic" {
375+
pub fn discriminant_value<T>(v: &T) -> <T as DiscriminantKind>::Discriminant;
376+
}
374377
const GOAL: bool = {
375378
discriminant_value(&Some(2i32)) == discriminant_value(&Some(5i32))
376379
&& discriminant_value(&Some(2i32)) != discriminant_value(&None::<i32>)
@@ -405,15 +408,11 @@ fn floating_point() {
405408
// FIXME(#17451): Add `f16` and `f128` tests once intrinsics are added.
406409
check_number(
407410
r#"
408-
409-
#[rustc_intrinsic]
410-
pub unsafe fn sqrtf32(x: f32) -> f32;
411-
412-
#[rustc_intrinsic]
413-
pub unsafe fn powf32(a: f32, x: f32) -> f32;
414-
415-
#[rustc_intrinsic]
416-
pub unsafe fn fmaf32(a: f32, b: f32, c: f32) -> f32;
411+
extern "rust-intrinsic" {
412+
pub fn sqrtf32(x: f32) -> f32;
413+
pub fn powf32(a: f32, x: f32) -> f32;
414+
pub fn fmaf32(a: f32, b: f32, c: f32) -> f32;
415+
}
417416
418417
const GOAL: f32 = sqrtf32(1.2) + powf32(3.4, 5.6) + fmaf32(-7.8, 1.3, 2.4);
419418
"#,
@@ -425,15 +424,11 @@ fn floating_point() {
425424
#[allow(unknown_lints, clippy::unnecessary_min_or_max)]
426425
check_number(
427426
r#"
428-
429-
#[rustc_intrinsic]
430-
pub unsafe fn powif64(a: f64, x: i32) -> f64;
431-
432-
#[rustc_intrinsic]
433-
pub unsafe fn sinf64(x: f64) -> f64;
434-
435-
#[rustc_intrinsic]
436-
pub unsafe fn minnumf64(x: f64, y: f64) -> f64;
427+
extern "rust-intrinsic" {
428+
pub fn powif64(a: f64, x: i32) -> f64;
429+
pub fn sinf64(x: f64) -> f64;
430+
pub fn minnumf64(x: f64, y: f64) -> f64;
431+
}
437432
438433
const GOAL: f64 = powif64(1.2, 5) + sinf64(3.4) + minnumf64(-7.8, 1.3);
439434
"#,
@@ -449,45 +444,21 @@ fn atomic() {
449444
check_number(
450445
r#"
451446
//- minicore: copy
452-
453-
#[rustc_intrinsic]
454-
pub unsafe fn atomic_load_seqcst<T: Copy>(src: *const T) -> T;
455-
456-
#[rustc_intrinsic]
457-
pub unsafe fn atomic_xchg_acquire<T: Copy>(dst: *mut T, src: T) -> T;
458-
459-
#[rustc_intrinsic]
460-
pub unsafe fn atomic_cxchg_release_seqcst<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
461-
462-
#[rustc_intrinsic]
463-
pub unsafe fn atomic_cxchgweak_acquire_acquire<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
464-
465-
#[rustc_intrinsic]
466-
pub unsafe fn atomic_store_release<T: Copy>(dst: *mut T, val: T);
467-
468-
#[rustc_intrinsic]
469-
pub unsafe fn atomic_xadd_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
470-
471-
#[rustc_intrinsic]
472-
pub unsafe fn atomic_xsub_seqcst<T: Copy>(dst: *mut T, src: T) -> T;
473-
474-
#[rustc_intrinsic]
475-
pub unsafe fn atomic_and_acquire<T: Copy>(dst: *mut T, src: T) -> T;
476-
477-
#[rustc_intrinsic]
478-
pub unsafe fn atomic_nand_seqcst<T: Copy>(dst: *mut T, src: T) -> T;
479-
480-
#[rustc_intrinsic]
481-
pub unsafe fn atomic_or_release<T: Copy>(dst: *mut T, src: T) -> T;
482-
483-
#[rustc_intrinsic]
484-
pub unsafe fn atomic_xor_seqcst<T: Copy>(dst: *mut T, src: T) -> T;
485-
486-
#[rustc_intrinsic]
487-
pub unsafe fn atomic_fence_seqcst();
488-
489-
#[rustc_intrinsic]
490-
pub unsafe fn atomic_singlethreadfence_acqrel();
447+
extern "rust-intrinsic" {
448+
pub fn atomic_load_seqcst<T: Copy>(src: *const T) -> T;
449+
pub fn atomic_xchg_acquire<T: Copy>(dst: *mut T, src: T) -> T;
450+
pub fn atomic_cxchg_release_seqcst<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
451+
pub fn atomic_cxchgweak_acquire_acquire<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
452+
pub fn atomic_store_release<T: Copy>(dst: *mut T, val: T);
453+
pub fn atomic_xadd_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
454+
pub fn atomic_xsub_seqcst<T: Copy>(dst: *mut T, src: T) -> T;
455+
pub fn atomic_and_acquire<T: Copy>(dst: *mut T, src: T) -> T;
456+
pub fn atomic_nand_seqcst<T: Copy>(dst: *mut T, src: T) -> T;
457+
pub fn atomic_or_release<T: Copy>(dst: *mut T, src: T) -> T;
458+
pub fn atomic_xor_seqcst<T: Copy>(dst: *mut T, src: T) -> T;
459+
pub fn atomic_fence_seqcst();
460+
pub fn atomic_singlethreadfence_acqrel();
461+
}
491462
492463
fn should_not_reach() {
493464
_ // fails the test if executed
@@ -523,12 +494,10 @@ fn offset() {
523494
check_number(
524495
r#"
525496
//- minicore: coerce_unsized, index, slice
526-
527-
#[rustc_intrinsic]
528-
pub unsafe fn offset<Ptr, Delta>(dst: Ptr, offset: Delta) -> Ptr;
529-
530-
#[rustc_intrinsic]
531-
pub unsafe fn arith_offset<T>(dst: *const T, offset: isize) -> *const T;
497+
extern "rust-intrinsic" {
498+
pub fn offset<Ptr, Delta>(dst: Ptr, offset: Delta) -> Ptr;
499+
pub fn arith_offset<T>(dst: *const T, offset: isize) -> *const T;
500+
}
532501
533502
const GOAL: i32 = unsafe {
534503
let ar: &[(i32, i32, i32)] = &[
@@ -554,8 +523,9 @@ fn arith_offset() {
554523
check_number(
555524
r#"
556525
//- minicore: coerce_unsized, index, slice
557-
#[rustc_intrinsic]
558-
pub unsafe fn arith_offset<T>(dst: *const T, offset: isize) -> *const T;
526+
extern "rust-intrinsic" {
527+
pub fn arith_offset<T>(dst: *const T, offset: isize) -> *const T;
528+
}
559529
560530
const GOAL: u8 = unsafe {
561531
let ar: &[(u8, u8, u8)] = &[
@@ -579,8 +549,9 @@ fn arith_offset() {
579549
fn copy_nonoverlapping() {
580550
check_number(
581551
r#"
582-
#[rustc_intrinsic]
583-
pub unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
552+
extern "rust-intrinsic" {
553+
pub fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
554+
}
584555
585556
const GOAL: u8 = unsafe {
586557
let mut x = 2;
@@ -597,8 +568,9 @@ fn copy_nonoverlapping() {
597568
fn write_bytes() {
598569
check_number(
599570
r#"
600-
#[rustc_intrinsic]
601-
unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
571+
extern "rust-intrinsic" {
572+
fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
573+
}
602574
603575
const GOAL: i32 = unsafe {
604576
let mut x = 2;
@@ -614,8 +586,9 @@ fn write_bytes() {
614586
fn write_via_move() {
615587
check_number(
616588
r#"
617-
#[rustc_intrinsic]
618-
unsafe fn write_via_move<T>(ptr: *mut T, value: T);
589+
extern "rust-intrinsic" {
590+
fn write_via_move<T>(ptr: *mut T, value: T);
591+
}
619592
620593
const GOAL: i32 = unsafe {
621594
let mut x = 2;
@@ -632,8 +605,9 @@ fn copy() {
632605
check_number(
633606
r#"
634607
//- minicore: coerce_unsized, index, slice
635-
#[rustc_intrinsic]
636-
pub unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize);
608+
extern "rust-intrinsic" {
609+
pub fn copy<T>(src: *const T, dst: *mut T, count: usize);
610+
}
637611
638612
const GOAL: i32 = unsafe {
639613
let mut x = [1i32, 2, 3, 4, 5];
@@ -651,8 +625,9 @@ fn copy() {
651625
fn ctpop() {
652626
check_number(
653627
r#"
654-
#[rustc_intrinsic]
655-
pub unsafe fn ctpop<T: Copy>(x: T) -> T;
628+
extern "rust-intrinsic" {
629+
pub fn ctpop<T: Copy>(x: T) -> T;
630+
}
656631
657632
const GOAL: i64 = ctpop(-29);
658633
"#,
@@ -664,8 +639,9 @@ fn ctpop() {
664639
fn ctlz() {
665640
check_number(
666641
r#"
667-
#[rustc_intrinsic]
668-
pub unsafe fn ctlz<T: Copy>(x: T) -> T;
642+
extern "rust-intrinsic" {
643+
pub fn ctlz<T: Copy>(x: T) -> T;
644+
}
669645
670646
const GOAL: u8 = ctlz(0b0001_1100_u8);
671647
"#,
@@ -677,8 +653,9 @@ fn ctlz() {
677653
fn cttz() {
678654
check_number(
679655
r#"
680-
#[rustc_intrinsic]
681-
pub unsafe fn cttz<T: Copy>(x: T) -> T;
656+
extern "rust-intrinsic" {
657+
pub fn cttz<T: Copy>(x: T) -> T;
658+
}
682659
683660
const GOAL: i64 = cttz(-24);
684661
"#,
@@ -690,26 +667,28 @@ fn cttz() {
690667
fn rotate() {
691668
check_number(
692669
r#"
693-
#[rustc_intrinsic]
694-
pub unsafe fn rotate_left<T: Copy>(x: T, y: T) -> T;
670+
extern "rust-intrinsic" {
671+
pub fn rotate_left<T: Copy>(x: T, y: T) -> T;
672+
}
695673
696674
const GOAL: i64 = rotate_left(0xaa00000000006e1i64, 12);
697675
"#,
698676
0x6e10aa,
699677
);
700678
check_number(
701679
r#"
702-
#[rustc_intrinsic]
703-
pub unsafe fn rotate_right<T: Copy>(x: T, y: T) -> T;
680+
extern "rust-intrinsic" {
681+
pub fn rotate_right<T: Copy>(x: T, y: T) -> T;
682+
}
704683
705684
const GOAL: i64 = rotate_right(0x6e10aa, 12);
706685
"#,
707686
0xaa00000000006e1,
708687
);
709688
check_number(
710689
r#"
711-
#[rustc_intrinsic]
712-
pub unsafe fn rotate_left<T: Copy>(x: T, y: T) -> T;
690+
extern "rust-intrinsic" {
691+
pub fn rotate_left<T: Copy>(x: T, y: T) -> T;
713692
}
714693
715694
const GOAL: i8 = rotate_left(129, 2);

0 commit comments

Comments
 (0)