Skip to content

Commit 6eea027

Browse files
committed
remove support for rustc_intrinsic_must_be_overridden from the compiler
1 parent 5a58a92 commit 6eea027

File tree

24 files changed

+70
-203
lines changed

24 files changed

+70
-203
lines changed

compiler/rustc_codegen_cranelift/example/mini_core.rs

+13-52
Original file line numberDiff line numberDiff line change
@@ -620,70 +620,31 @@ pub union MaybeUninit<T> {
620620

621621
pub mod intrinsics {
622622
#[rustc_intrinsic]
623-
#[rustc_intrinsic_must_be_overridden]
624-
pub fn abort() -> ! {
625-
loop {}
626-
}
623+
pub fn abort() -> !;
627624
#[rustc_intrinsic]
628-
#[rustc_intrinsic_must_be_overridden]
629-
pub fn size_of<T>() -> usize {
630-
loop {}
631-
}
625+
pub fn size_of<T>() -> usize;
632626
#[rustc_intrinsic]
633-
#[rustc_intrinsic_must_be_overridden]
634-
pub unsafe fn size_of_val<T: ?::Sized>(_val: *const T) -> usize {
635-
loop {}
636-
}
627+
pub unsafe fn size_of_val<T: ?::Sized>(_val: *const T) -> usize;
637628
#[rustc_intrinsic]
638-
#[rustc_intrinsic_must_be_overridden]
639-
pub fn min_align_of<T>() -> usize {
640-
loop {}
641-
}
629+
pub fn min_align_of<T>() -> usize;
642630
#[rustc_intrinsic]
643-
#[rustc_intrinsic_must_be_overridden]
644-
pub unsafe fn min_align_of_val<T: ?::Sized>(_val: *const T) -> usize {
645-
loop {}
646-
}
631+
pub unsafe fn min_align_of_val<T: ?::Sized>(_val: *const T) -> usize;
647632
#[rustc_intrinsic]
648-
#[rustc_intrinsic_must_be_overridden]
649-
pub unsafe fn copy<T>(_src: *const T, _dst: *mut T, _count: usize) {
650-
loop {}
651-
}
633+
pub unsafe fn copy<T>(_src: *const T, _dst: *mut T, _count: usize);
652634
#[rustc_intrinsic]
653-
#[rustc_intrinsic_must_be_overridden]
654-
pub unsafe fn transmute<T, U>(_e: T) -> U {
655-
loop {}
656-
}
635+
pub unsafe fn transmute<T, U>(_e: T) -> U;
657636
#[rustc_intrinsic]
658-
#[rustc_intrinsic_must_be_overridden]
659-
pub unsafe fn ctlz_nonzero<T>(_x: T) -> u32 {
660-
loop {}
661-
}
637+
pub unsafe fn ctlz_nonzero<T>(_x: T) -> u32;
662638
#[rustc_intrinsic]
663-
#[rustc_intrinsic_must_be_overridden]
664-
pub fn needs_drop<T: ?::Sized>() -> bool {
665-
loop {}
666-
}
639+
pub fn needs_drop<T: ?::Sized>() -> bool;
667640
#[rustc_intrinsic]
668-
#[rustc_intrinsic_must_be_overridden]
669-
pub fn bitreverse<T>(_x: T) -> T {
670-
loop {}
671-
}
641+
pub fn bitreverse<T>(_x: T) -> T;
672642
#[rustc_intrinsic]
673-
#[rustc_intrinsic_must_be_overridden]
674-
pub fn bswap<T>(_x: T) -> T {
675-
loop {}
676-
}
643+
pub fn bswap<T>(_x: T) -> T;
677644
#[rustc_intrinsic]
678-
#[rustc_intrinsic_must_be_overridden]
679-
pub unsafe fn write_bytes<T>(_dst: *mut T, _val: u8, _count: usize) {
680-
loop {}
681-
}
645+
pub unsafe fn write_bytes<T>(_dst: *mut T, _val: u8, _count: usize);
682646
#[rustc_intrinsic]
683-
#[rustc_intrinsic_must_be_overridden]
684-
pub unsafe fn unreachable() -> ! {
685-
loop {}
686-
}
647+
pub unsafe fn unreachable() -> !;
687648
}
688649

689650
pub mod libc {

compiler/rustc_codegen_gcc/example/mini_core.rs

+13-52
Original file line numberDiff line numberDiff line change
@@ -591,70 +591,31 @@ pub union MaybeUninit<T> {
591591

592592
pub mod intrinsics {
593593
#[rustc_intrinsic]
594-
#[rustc_intrinsic_must_be_overridden]
595-
pub fn abort() -> ! {
596-
loop {}
597-
}
594+
pub fn abort() -> !;
598595
#[rustc_intrinsic]
599-
#[rustc_intrinsic_must_be_overridden]
600-
pub fn size_of<T>() -> usize {
601-
loop {}
602-
}
596+
pub fn size_of<T>() -> usize;
603597
#[rustc_intrinsic]
604-
#[rustc_intrinsic_must_be_overridden]
605-
pub unsafe fn size_of_val<T: ?::Sized>(_val: *const T) -> usize {
606-
loop {}
607-
}
598+
pub unsafe fn size_of_val<T: ?::Sized>(_val: *const T) -> usize;
608599
#[rustc_intrinsic]
609-
#[rustc_intrinsic_must_be_overridden]
610-
pub fn min_align_of<T>() -> usize {
611-
loop {}
612-
}
600+
pub fn min_align_of<T>() -> usize;
613601
#[rustc_intrinsic]
614-
#[rustc_intrinsic_must_be_overridden]
615-
pub unsafe fn min_align_of_val<T: ?::Sized>(_val: *const T) -> usize {
616-
loop {}
617-
}
602+
pub unsafe fn min_align_of_val<T: ?::Sized>(_val: *const T) -> usize;
618603
#[rustc_intrinsic]
619-
#[rustc_intrinsic_must_be_overridden]
620-
pub unsafe fn copy<T>(_src: *const T, _dst: *mut T, _count: usize) {
621-
loop {}
622-
}
604+
pub unsafe fn copy<T>(_src: *const T, _dst: *mut T, _count: usize);
623605
#[rustc_intrinsic]
624-
#[rustc_intrinsic_must_be_overridden]
625-
pub unsafe fn transmute<T, U>(_e: T) -> U {
626-
loop {}
627-
}
606+
pub unsafe fn transmute<T, U>(_e: T) -> U;
628607
#[rustc_intrinsic]
629-
#[rustc_intrinsic_must_be_overridden]
630-
pub unsafe fn ctlz_nonzero<T>(_x: T) -> u32 {
631-
loop {}
632-
}
608+
pub unsafe fn ctlz_nonzero<T>(_x: T) -> u32;
633609
#[rustc_intrinsic]
634-
#[rustc_intrinsic_must_be_overridden]
635-
pub fn needs_drop<T: ?::Sized>() -> bool {
636-
loop {}
637-
}
610+
pub fn needs_drop<T: ?::Sized>() -> bool;
638611
#[rustc_intrinsic]
639-
#[rustc_intrinsic_must_be_overridden]
640-
pub fn bitreverse<T>(_x: T) -> T {
641-
loop {}
642-
}
612+
pub fn bitreverse<T>(_x: T) -> T;
643613
#[rustc_intrinsic]
644-
#[rustc_intrinsic_must_be_overridden]
645-
pub fn bswap<T>(_x: T) -> T {
646-
loop {}
647-
}
614+
pub fn bswap<T>(_x: T) -> T;
648615
#[rustc_intrinsic]
649-
#[rustc_intrinsic_must_be_overridden]
650-
pub unsafe fn write_bytes<T>(_dst: *mut T, _val: u8, _count: usize) {
651-
loop {}
652-
}
616+
pub unsafe fn write_bytes<T>(_dst: *mut T, _val: u8, _count: usize);
653617
#[rustc_intrinsic]
654-
#[rustc_intrinsic_must_be_overridden]
655-
pub unsafe fn unreachable() -> ! {
656-
loop {}
657-
}
618+
pub unsafe fn unreachable() -> !;
658619
}
659620

660621
pub mod libc {

compiler/rustc_codegen_gcc/tests/run/abort1.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ mod intrinsics {
3636

3737
#[rustc_nounwind]
3838
#[rustc_intrinsic]
39-
#[rustc_intrinsic_must_be_overridden]
40-
pub fn abort() -> ! {
41-
loop {}
42-
}
39+
pub fn abort() -> !;
4340
}
4441

4542
/*

compiler/rustc_codegen_gcc/tests/run/abort2.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ mod intrinsics {
3636

3737
#[rustc_nounwind]
3838
#[rustc_intrinsic]
39-
#[rustc_intrinsic_must_be_overridden]
40-
pub fn abort() -> ! {
41-
loop {}
42-
}
39+
pub fn abort() -> !;
4340
}
4441

4542
/*

compiler/rustc_codegen_gcc/tests/run/assign.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,7 @@ mod libc {
5959
mod intrinsics {
6060
#[rustc_nounwind]
6161
#[rustc_intrinsic]
62-
#[rustc_intrinsic_must_be_overridden]
63-
pub fn abort() -> ! {
64-
loop {}
65-
}
62+
pub fn abort() -> !;
6663
}
6764

6865
#[lang = "panic"]

compiler/rustc_codegen_gcc/tests/run/mut_ref.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,7 @@ mod libc {
6161
mod intrinsics {
6262
#[rustc_nounwind]
6363
#[rustc_intrinsic]
64-
#[rustc_intrinsic_must_be_overridden]
65-
pub fn abort() -> ! {
66-
loop {}
67-
}
64+
pub fn abort() -> !;
6865
}
6966

7067
#[lang = "panic"]

compiler/rustc_codegen_gcc/tests/run/operations.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,7 @@ mod libc {
6767
mod intrinsics {
6868
#[rustc_nounwind]
6969
#[rustc_intrinsic]
70-
#[rustc_intrinsic_must_be_overridden]
71-
pub fn abort() -> ! {
72-
loop {}
73-
}
70+
pub fn abort() -> !;
7471
}
7572

7673
#[lang = "panic"]

compiler/rustc_codegen_gcc/tests/run/static.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ mod intrinsics {
4949

5050
#[rustc_nounwind]
5151
#[rustc_intrinsic]
52-
#[rustc_intrinsic_must_be_overridden]
53-
pub fn abort() -> ! {
54-
loop {}
55-
}
52+
pub fn abort() -> !;
5653
}
5754

5855
mod libc {

compiler/rustc_error_codes/src/error_codes/E0094.md

+3-11
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@ Erroneous code example:
77
#![allow(internal_features)]
88
99
#[rustc_intrinsic]
10-
#[rustc_intrinsic_must_be_overridden]
11-
fn size_of<T, U>() -> usize // error: intrinsic has wrong number
12-
// of type parameters
13-
{
14-
loop {}
15-
}
10+
fn size_of<T, U>() -> usize; // error: intrinsic has wrong number
11+
// of type parameters
1612
```
1713

1814
Please check that you provided the right number of type parameters
@@ -24,9 +20,5 @@ Example:
2420
#![allow(internal_features)]
2521
2622
#[rustc_intrinsic]
27-
#[rustc_intrinsic_must_be_overridden]
28-
fn size_of<T>() -> usize // ok!
29-
{
30-
loop {}
31-
}
23+
fn size_of<T>() -> usize; // ok!
3224
```

compiler/rustc_feature/src/builtin_attrs.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1005,10 +1005,6 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
10051005
rustc_intrinsic, Normal, template!(Word), ErrorFollowing, EncodeCrossCrate::Yes, intrinsics,
10061006
"the `#[rustc_intrinsic]` attribute is used to declare intrinsics as function items",
10071007
),
1008-
gated!(
1009-
rustc_intrinsic_must_be_overridden, Normal, template!(Word), ErrorFollowing, EncodeCrossCrate::Yes, intrinsics,
1010-
"the `#[rustc_intrinsic_must_be_overridden]` attribute is used to declare intrinsics without real bodies",
1011-
),
10121008
rustc_attr!(
10131009
rustc_no_mir_inline, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::Yes,
10141010
"#[rustc_no_mir_inline] prevents the MIR inliner from inlining a function while not affecting codegen"

compiler/rustc_middle/src/ty/util.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -1755,13 +1755,12 @@ pub fn intrinsic_raw(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ty::Intrinsi
17551755
&& (matches!(tcx.fn_sig(def_id).skip_binder().abi(), ExternAbi::RustIntrinsic)
17561756
|| tcx.has_attr(def_id, sym::rustc_intrinsic))
17571757
{
1758-
let must_be_overridden = tcx.has_attr(def_id, sym::rustc_intrinsic_must_be_overridden)
1759-
|| match tcx.hir_node_by_def_id(def_id) {
1760-
hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn { has_body, .. }, .. }) => {
1761-
!has_body
1762-
}
1763-
_ => true,
1764-
};
1758+
let must_be_overridden = match tcx.hir_node_by_def_id(def_id) {
1759+
hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn { has_body, .. }, .. }) => {
1760+
!has_body
1761+
}
1762+
_ => true,
1763+
};
17651764
Some(ty::IntrinsicDef {
17661765
name: tcx.item_name(def_id.into()),
17671766
must_be_overridden,

compiler/rustc_span/src/symbol.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1764,7 +1764,6 @@ symbols! {
17641764
rustc_insignificant_dtor,
17651765
rustc_intrinsic,
17661766
rustc_intrinsic_const_stable_indirect,
1767-
rustc_intrinsic_must_be_overridden,
17681767
rustc_layout,
17691768
rustc_layout_scalar_valid_range_end,
17701769
rustc_layout_scalar_valid_range_start,

src/doc/unstable-book/src/language-features/intrinsics.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,19 @@ These must be implemented by all backends.
6262

6363
### `#[rustc_intrinsic]` declarations
6464

65-
These are written like intrinsics with fallback bodies, but the body is irrelevant.
66-
Use `loop {}` for the body or call the intrinsic recursively and add
67-
`#[rustc_intrinsic_must_be_overridden]` to the function to ensure that backends don't
68-
invoke the body.
65+
These are written without a body:
66+
```rust
67+
#![feature(intrinsics)]
68+
#![allow(internal_features)]
69+
70+
#[rustc_intrinsic]
71+
pub fn abort() -> !;
72+
```
6973

7074
### Legacy extern ABI based intrinsics
7175

76+
*This style is deprecated, always prefer the above form.*
77+
7278
These are imported as if they were FFI functions, with the special
7379
`rust-intrinsic` ABI. For example, if one was in a freestanding
7480
context, but wished to be able to `transmute` between types, and

tests/assembly/rust-abi-arg-attr.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,7 @@ enum Ordering {
5151
}
5252

5353
#[rustc_intrinsic]
54-
#[rustc_intrinsic_must_be_overridden]
55-
fn three_way_compare<T: Copy>(lhs: T, rhs: T) -> Ordering {
56-
loop {}
57-
}
54+
fn three_way_compare<T: Copy>(lhs: T, rhs: T) -> Ordering;
5855

5956
// ^^^^^ core
6057

tests/rustdoc/const-intrinsic.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,13 @@
99
#[stable(since="1.0.0", feature="rust1")]
1010
#[rustc_const_stable(feature = "const_transmute", since = "1.56.0")]
1111
#[rustc_intrinsic]
12-
#[rustc_intrinsic_must_be_overridden]
13-
pub const unsafe fn transmute<T, U>(_: T) -> U {
14-
loop {}
15-
}
12+
pub const unsafe fn transmute<T, U>(_: T) -> U;
1613

1714
//@ has 'foo/fn.unreachable.html'
1815
//@ has - '//pre[@class="rust item-decl"]' 'pub unsafe fn unreachable() -> !'
1916
#[stable(since="1.0.0", feature="rust1")]
2017
#[rustc_intrinsic]
21-
#[rustc_intrinsic_must_be_overridden]
22-
pub unsafe fn unreachable() -> ! {
23-
loop {}
24-
}
18+
pub unsafe fn unreachable() -> !;
2519

2620
extern "C" {
2721
//@ has 'foo/fn.needs_drop.html'

tests/rustdoc/safe-intrinsic.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,8 @@ trait Sized {}
1111
//@ has 'foo/fn.abort.html'
1212
//@ has - '//pre[@class="rust item-decl"]' 'pub fn abort() -> !'
1313
#[rustc_intrinsic]
14-
#[rustc_intrinsic_must_be_overridden]
15-
pub fn abort() -> ! {
16-
loop {}
17-
}
14+
pub fn abort() -> !;
1815
//@ has 'foo/fn.unreachable.html'
1916
//@ has - '//pre[@class="rust item-decl"]' 'pub unsafe fn unreachable() -> !'
2017
#[rustc_intrinsic]
21-
#[rustc_intrinsic_must_be_overridden]
22-
pub unsafe fn unreachable() -> ! {
23-
loop {}
24-
}
18+
pub unsafe fn unreachable() -> !;

tests/ui-fulldeps/stable-mir/check_intrinsics.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,11 @@ fn test_intrinsics() -> ControlFlow<()> {
5151

5252
/// This check is unfortunately tight to the implementation of intrinsics.
5353
///
54-
/// We want to ensure that StableMIR can handle intrinsics with and without fallback body.
54+
/// We want to ensure that StableMIR can handle intrinsics with and without fallback body:
55+
/// for intrinsics without a body, obviously we cannot expose anything.
5556
///
5657
/// If by any chance this test breaks because you changed how an intrinsic is implemented, please
5758
/// update the test to invoke a different intrinsic.
58-
///
59-
/// In StableMIR, we only expose intrinsic body if they are not marked with
60-
/// `rustc_intrinsic_must_be_overridden`.
6159
fn check_instance(instance: &Instance) {
6260
assert_eq!(instance.kind, InstanceKind::Intrinsic);
6361
let name = instance.intrinsic_name().unwrap();

0 commit comments

Comments
 (0)