@@ -204,12 +204,12 @@ fn const_eval_select() {
204
204
check_number (
205
205
r#"
206
206
//- 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
+ }
213
213
214
214
const fn in_const(x: i32, y: i32) -> i32 {
215
215
x + y
@@ -229,9 +229,9 @@ fn const_eval_select() {
229
229
fn wrapping_add ( ) {
230
230
check_number (
231
231
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
+ }
235
235
236
236
const GOAL: u8 = wrapping_add(10, 250);
237
237
"# ,
@@ -244,12 +244,10 @@ fn ptr_offset_from() {
244
244
check_number (
245
245
r#"
246
246
//- 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
+ }
253
251
254
252
const GOAL: isize = {
255
253
let x = [1, 2, 3, 4, 5i32];
@@ -267,26 +265,29 @@ fn ptr_offset_from() {
267
265
fn saturating ( ) {
268
266
check_number (
269
267
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
+ }
272
271
273
272
const GOAL: u8 = saturating_add(10, 250);
274
273
"# ,
275
274
255 ,
276
275
) ;
277
276
check_number (
278
277
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
+ }
281
281
282
282
const GOAL: bool = saturating_sub(5u8, 7) == 0 && saturating_sub(8u8, 4) == 4;
283
283
"# ,
284
284
1 ,
285
285
) ;
286
286
check_number (
287
287
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
+ }
290
291
291
292
const GOAL: i8 = saturating_add(5, 8);
292
293
"# ,
@@ -329,17 +330,19 @@ fn allocator() {
329
330
fn overflowing_add ( ) {
330
331
check_number (
331
332
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
+ }
334
336
335
337
const GOAL: u8 = add_with_overflow(1, 2).0;
336
338
"# ,
337
339
3 ,
338
340
) ;
339
341
check_number (
340
342
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
+ }
343
346
344
347
const GOAL: u8 = add_with_overflow(1, 2).1 as u8;
345
348
"# ,
@@ -352,9 +355,9 @@ fn needs_drop() {
352
355
check_number (
353
356
r#"
354
357
//- 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
+ }
358
361
struct X;
359
362
const GOAL: bool = !needs_drop::<i32>() && needs_drop::<X>();
360
363
"# ,
@@ -368,9 +371,9 @@ fn discriminant_value() {
368
371
r#"
369
372
//- minicore: discriminant, option
370
373
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
+ }
374
377
const GOAL: bool = {
375
378
discriminant_value(&Some(2i32)) == discriminant_value(&Some(5i32))
376
379
&& discriminant_value(&Some(2i32)) != discriminant_value(&None::<i32>)
@@ -405,15 +408,11 @@ fn floating_point() {
405
408
// FIXME(#17451): Add `f16` and `f128` tests once intrinsics are added.
406
409
check_number (
407
410
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
+ }
417
416
418
417
const GOAL: f32 = sqrtf32(1.2) + powf32(3.4, 5.6) + fmaf32(-7.8, 1.3, 2.4);
419
418
"# ,
@@ -425,15 +424,11 @@ fn floating_point() {
425
424
#[ allow( unknown_lints, clippy:: unnecessary_min_or_max) ]
426
425
check_number (
427
426
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
+ }
437
432
438
433
const GOAL: f64 = powif64(1.2, 5) + sinf64(3.4) + minnumf64(-7.8, 1.3);
439
434
"# ,
@@ -449,45 +444,21 @@ fn atomic() {
449
444
check_number (
450
445
r#"
451
446
//- 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
+ }
491
462
492
463
fn should_not_reach() {
493
464
_ // fails the test if executed
@@ -523,12 +494,10 @@ fn offset() {
523
494
check_number (
524
495
r#"
525
496
//- 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
+ }
532
501
533
502
const GOAL: i32 = unsafe {
534
503
let ar: &[(i32, i32, i32)] = &[
@@ -554,8 +523,9 @@ fn arith_offset() {
554
523
check_number (
555
524
r#"
556
525
//- 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
+ }
559
529
560
530
const GOAL: u8 = unsafe {
561
531
let ar: &[(u8, u8, u8)] = &[
@@ -579,8 +549,9 @@ fn arith_offset() {
579
549
fn copy_nonoverlapping ( ) {
580
550
check_number (
581
551
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
+ }
584
555
585
556
const GOAL: u8 = unsafe {
586
557
let mut x = 2;
@@ -597,8 +568,9 @@ fn copy_nonoverlapping() {
597
568
fn write_bytes ( ) {
598
569
check_number (
599
570
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
+ }
602
574
603
575
const GOAL: i32 = unsafe {
604
576
let mut x = 2;
@@ -614,8 +586,9 @@ fn write_bytes() {
614
586
fn write_via_move ( ) {
615
587
check_number (
616
588
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
+ }
619
592
620
593
const GOAL: i32 = unsafe {
621
594
let mut x = 2;
@@ -632,8 +605,9 @@ fn copy() {
632
605
check_number (
633
606
r#"
634
607
//- 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
+ }
637
611
638
612
const GOAL: i32 = unsafe {
639
613
let mut x = [1i32, 2, 3, 4, 5];
@@ -651,8 +625,9 @@ fn copy() {
651
625
fn ctpop ( ) {
652
626
check_number (
653
627
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
+ }
656
631
657
632
const GOAL: i64 = ctpop(-29);
658
633
"# ,
@@ -664,8 +639,9 @@ fn ctpop() {
664
639
fn ctlz ( ) {
665
640
check_number (
666
641
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
+ }
669
645
670
646
const GOAL: u8 = ctlz(0b0001_1100_u8);
671
647
"# ,
@@ -677,8 +653,9 @@ fn ctlz() {
677
653
fn cttz ( ) {
678
654
check_number (
679
655
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
+ }
682
659
683
660
const GOAL: i64 = cttz(-24);
684
661
"# ,
@@ -690,26 +667,28 @@ fn cttz() {
690
667
fn rotate ( ) {
691
668
check_number (
692
669
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
+ }
695
673
696
674
const GOAL: i64 = rotate_left(0xaa00000000006e1i64, 12);
697
675
"# ,
698
676
0x6e10aa ,
699
677
) ;
700
678
check_number (
701
679
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
+ }
704
683
705
684
const GOAL: i64 = rotate_right(0x6e10aa, 12);
706
685
"# ,
707
686
0xaa00000000006e1 ,
708
687
) ;
709
688
check_number (
710
689
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;
713
692
}
714
693
715
694
const GOAL: i8 = rotate_left(129, 2);
0 commit comments