Skip to content

Commit df8a3d5

Browse files
committed
stabilize naked_functions
1 parent 49e5e4e commit df8a3d5

File tree

53 files changed

+165
-294
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+165
-294
lines changed

compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
1-
#![feature(
2-
no_core,
3-
lang_items,
4-
never_type,
5-
linkage,
6-
extern_types,
7-
naked_functions,
8-
thread_local,
9-
repr_simd
10-
)]
1+
#![feature(no_core, lang_items, never_type, linkage, extern_types, thread_local, repr_simd)]
112
#![no_core]
123
#![allow(dead_code, non_camel_case_types, internal_features)]
134

compiler/rustc_error_codes/src/error_codes/E0787.md

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ An unsupported naked function definition.
33
Erroneous code example:
44

55
```compile_fail,E0787
6-
#![feature(naked_functions)]
7-
86
#[unsafe(naked)]
97
pub extern "C" fn f() -> u32 {
108
42

compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ declare_features! (
300300
/// Allows patterns with concurrent by-move and by-ref bindings.
301301
/// For example, you can write `Foo(a, ref b)` where `a` is by-move and `b` is by-ref.
302302
(accepted, move_ref_pattern, "1.49.0", Some(68354)),
303+
/// Allows using `#[naked]` on functions.
304+
(accepted, naked_functions, "CURRENT_RUSTC_VERSION", Some(90957)),
303305
/// Allows specifying modifiers in the link attribute: `#[link(modifiers = "...")]`
304306
(accepted, native_link_modifiers, "1.61.0", Some(81490)),
305307
/// Allows specifying the bundle link modifier

compiler/rustc_feature/src/builtin_attrs.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
443443
ungated!(unsafe(Edition2024) no_mangle, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No),
444444
ungated!(used, Normal, template!(Word, List: "compiler|linker"), WarnFollowing, EncodeCrossCrate::No),
445445
ungated!(link_ordinal, Normal, template!(List: "ordinal"), ErrorPreceding, EncodeCrossCrate::Yes),
446+
ungated!(unsafe naked, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No),
446447

447448
// Limits:
448449
ungated!(
@@ -515,12 +516,6 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
515516
// Unstable attributes:
516517
// ==========================================================================
517518

518-
// Linking:
519-
gated!(
520-
unsafe naked, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No,
521-
naked_functions, experimental!(naked)
522-
),
523-
524519
// Testing:
525520
gated!(
526521
test_runner, CrateLevel, template!(List: "path"), ErrorFollowing,

compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,6 @@ declare_features! (
563563
(unstable, must_not_suspend, "1.57.0", Some(83310)),
564564
/// Allows `mut ref` and `mut ref mut` identifier patterns.
565565
(incomplete, mut_ref, "1.79.0", Some(123076)),
566-
/// Allows using `#[naked]` on functions.
567-
(unstable, naked_functions, "1.9.0", Some(90957)),
568566
/// Allows using `#[naked]` on `extern "Rust"` functions.
569567
(unstable, naked_functions_rustic_abi, "CURRENT_RUSTC_VERSION", Some(138997)),
570568
/// Allows using `#[target_feature(enable = "...")]` on `#[naked]` on functions.

compiler/rustc_passes/src/check_attr.rs

-7
Original file line numberDiff line numberDiff line change
@@ -690,13 +690,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
690690
}
691691
}
692692
}
693-
// FIXME(#80564): We permit struct fields, match arms and macro defs to have an
694-
// `#[naked]` attribute with just a lint, because we previously
695-
// erroneously allowed it and some crates used it accidentally, to be compatible
696-
// with crates depending on them, we can't throw an error here.
697-
Target::Field | Target::Arm | Target::MacroDef => {
698-
self.inline_attr_str_error_with_macro_def(hir_id, attr, "naked")
699-
}
700693
_ => {
701694
self.dcx().emit_err(errors::AttrShouldBeAppliedToFn {
702695
attr_span: attr.span(),

library/core/src/arch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub macro asm("assembly template", $(operands,)* $(options($(option),*))?) {
3232
///
3333
/// [Rust By Example]: https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html
3434
/// [reference]: https://doc.rust-lang.org/nightly/reference/inline-assembly.html
35-
#[unstable(feature = "naked_functions", issue = "90957")]
35+
#[stable(feature = "naked_functions", since = "CURRENT_RUSTC_VERSION")]
3636
#[rustc_builtin_macro]
3737
pub macro naked_asm("assembly template", $(operands,)* $(options($(option),*))?) {
3838
/* compiler built-in */

src/doc/unstable-book/src/compiler-flags/sanitizer.md

-2
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,6 @@ See the [Clang ControlFlowIntegrity documentation][clang-cfi] for more details.
245245
## Example 1: Redirecting control flow using an indirect branch/call to an invalid destination
246246
247247
```rust,ignore (making doc tests pass cross-platform is hard)
248-
#![feature(naked_functions)]
249-
250248
use std::arch::naked_asm;
251249
use std::mem;
252250

tests/assembly/naked-functions/aarch64-naked-fn-no-bti-prolog.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//@ only-aarch64
55

66
#![crate_type = "lib"]
7-
#![feature(naked_functions)]
7+
88
use std::arch::naked_asm;
99

1010
// The problem at hand: Rust has adopted a fairly strict meaning for "naked functions",

tests/assembly/naked-functions/aix.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//@[aix] needs-llvm-components: powerpc
1010

1111
#![crate_type = "lib"]
12-
#![feature(no_core, naked_functions, asm_experimental_arch, f128, linkage, fn_align)]
12+
#![feature(no_core, asm_experimental_arch, f128, linkage, fn_align)]
1313
#![no_core]
1414

1515
// tests that naked functions work for the `powerpc64-ibm-aix` target.

tests/assembly/naked-functions/wasm32.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//@ [wasm32-wasip1] needs-llvm-components: webassembly
1010

1111
#![crate_type = "lib"]
12-
#![feature(no_core, naked_functions, asm_experimental_arch, f128, linkage, fn_align)]
12+
#![feature(no_core, asm_experimental_arch, f128, linkage, fn_align)]
1313
#![no_core]
1414

1515
extern crate minicore;

tests/assembly/naked-functions/x86_64-naked-fn-no-cet-prolog.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//@ only-x86_64
55

66
#![crate_type = "lib"]
7-
#![feature(naked_functions)]
7+
88
use std::arch::naked_asm;
99

1010
// The problem at hand: Rust has adopted a fairly strict meaning for "naked functions",

tests/auxiliary/minicore.rs

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
negative_impls,
2323
rustc_attrs,
2424
decl_macro,
25-
naked_functions,
2625
f16,
2726
f128,
2827
asm_experimental_arch,

tests/codegen/cffi/c-variadic-naked.rs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#![crate_type = "lib"]
77
#![feature(c_variadic)]
8-
#![feature(naked_functions)]
98
#![no_std]
109

1110
#[unsafe(naked)]

tests/codegen/naked-asan.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#![crate_type = "lib"]
88
#![no_std]
9-
#![feature(abi_x86_interrupt, naked_functions)]
9+
#![feature(abi_x86_interrupt)]
1010

1111
pub fn caller() {
1212
page_fault_handler(1, 2);

tests/codegen/naked-fn/aligned.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//@ ignore-arm no "ret" mnemonic
44

55
#![crate_type = "lib"]
6-
#![feature(naked_functions, fn_align)]
6+
#![feature(fn_align)]
77
use std::arch::naked_asm;
88

99
// CHECK: .balign 16

tests/codegen/naked-fn/generics.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//@ only-x86_64
33

44
#![crate_type = "lib"]
5-
#![feature(naked_functions, asm_const)]
65

76
use std::arch::naked_asm;
87

tests/codegen/naked-fn/instruction-set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//@ [thumb-mode] needs-llvm-components: arm
77

88
#![crate_type = "lib"]
9-
#![feature(no_core, lang_items, rustc_attrs, naked_functions)]
9+
#![feature(no_core, lang_items, rustc_attrs)]
1010
#![no_core]
1111

1212
extern crate minicore;

tests/codegen/naked-fn/min-function-alignment.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//@ needs-asm-support
33
//@ ignore-arm no "ret" mnemonic
44

5-
#![feature(naked_functions, fn_align)]
5+
#![feature(fn_align)]
66
#![crate_type = "lib"]
77

88
// functions without explicit alignment use the global minimum

tests/codegen/naked-fn/naked-functions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//@[thumb] needs-llvm-components: arm
1414

1515
#![crate_type = "lib"]
16-
#![feature(no_core, lang_items, rustc_attrs, naked_functions)]
16+
#![feature(no_core, lang_items, rustc_attrs)]
1717
#![no_core]
1818

1919
extern crate minicore;

tests/run-make/naked-symbol-visibility/a_rust_dylib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(naked_functions, linkage)]
1+
#![feature(linkage)]
22
#![crate_type = "dylib"]
33

44
use std::arch::naked_asm;

tests/ui/asm/naked-asm-outside-naked-fn.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//@ ignore-nvptx64
44
//@ ignore-spirv
55

6-
#![feature(naked_functions)]
76
#![crate_type = "lib"]
87

98
use std::arch::naked_asm;

tests/ui/asm/naked-asm-outside-naked-fn.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
error: the `naked_asm!` macro can only be used in functions marked with `#[unsafe(naked)]`
2-
--> $DIR/naked-asm-outside-naked-fn.rs:21:5
2+
--> $DIR/naked-asm-outside-naked-fn.rs:20:5
33
|
44
LL | naked_asm!("")
55
| ^^^^^^^^^^^^^^
66

77
error: the `naked_asm!` macro can only be used in functions marked with `#[unsafe(naked)]`
8-
--> $DIR/naked-asm-outside-naked-fn.rs:26:9
8+
--> $DIR/naked-asm-outside-naked-fn.rs:25:9
99
|
1010
LL | (|| naked_asm!(""))()
1111
| ^^^^^^^^^^^^^^
1212

1313
error: the `naked_asm!` macro can only be used in functions marked with `#[unsafe(naked)]`
14-
--> $DIR/naked-asm-outside-naked-fn.rs:32:9
14+
--> $DIR/naked-asm-outside-naked-fn.rs:31:9
1515
|
1616
LL | naked_asm!("");
1717
| ^^^^^^^^^^^^^^

tests/ui/asm/naked-functions-ffi.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//@ check-pass
22
//@ needs-asm-support
3-
#![feature(naked_functions)]
43
#![crate_type = "lib"]
54

65
use std::arch::naked_asm;

tests/ui/asm/naked-functions-ffi.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: `extern` fn uses type `char`, which is not FFI-safe
2-
--> $DIR/naked-functions-ffi.rs:9:28
2+
--> $DIR/naked-functions-ffi.rs:8:28
33
|
44
LL | pub extern "C" fn naked(p: char) -> u128 {
55
| ^^^^ not FFI-safe
@@ -9,7 +9,7 @@ LL | pub extern "C" fn naked(p: char) -> u128 {
99
= note: `#[warn(improper_ctypes_definitions)]` on by default
1010

1111
warning: `extern` fn uses type `u128`, which is not FFI-safe
12-
--> $DIR/naked-functions-ffi.rs:9:37
12+
--> $DIR/naked-functions-ffi.rs:8:37
1313
|
1414
LL | pub extern "C" fn naked(p: char) -> u128 {
1515
| ^^^^ not FFI-safe

tests/ui/asm/naked-functions-inline.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//@ needs-asm-support
2-
#![feature(naked_functions)]
32
#![crate_type = "lib"]
43

54
use std::arch::naked_asm;

tests/ui/asm/naked-functions-inline.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
error[E0736]: attribute incompatible with `#[unsafe(naked)]`
2-
--> $DIR/naked-functions-inline.rs:13:1
2+
--> $DIR/naked-functions-inline.rs:12:1
33
|
44
LL | #[unsafe(naked)]
55
| ---------------- function marked with `#[unsafe(naked)]` here
66
LL | #[inline]
77
| ^^^^^^^^^ the `inline` attribute is incompatible with `#[unsafe(naked)]`
88

99
error[E0736]: attribute incompatible with `#[unsafe(naked)]`
10-
--> $DIR/naked-functions-inline.rs:20:1
10+
--> $DIR/naked-functions-inline.rs:19:1
1111
|
1212
LL | #[unsafe(naked)]
1313
| ---------------- function marked with `#[unsafe(naked)]` here
1414
LL | #[inline(always)]
1515
| ^^^^^^^^^^^^^^^^^ the `inline` attribute is incompatible with `#[unsafe(naked)]`
1616

1717
error[E0736]: attribute incompatible with `#[unsafe(naked)]`
18-
--> $DIR/naked-functions-inline.rs:27:1
18+
--> $DIR/naked-functions-inline.rs:26:1
1919
|
2020
LL | #[unsafe(naked)]
2121
| ---------------- function marked with `#[unsafe(naked)]` here
2222
LL | #[inline(never)]
2323
| ^^^^^^^^^^^^^^^^ the `inline` attribute is incompatible with `#[unsafe(naked)]`
2424

2525
error[E0736]: attribute incompatible with `#[unsafe(naked)]`
26-
--> $DIR/naked-functions-inline.rs:34:19
26+
--> $DIR/naked-functions-inline.rs:33:19
2727
|
2828
LL | #[unsafe(naked)]
2929
| ---------------- function marked with `#[unsafe(naked)]` here

tests/ui/asm/naked-functions-instruction-set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//@ build-pass
66

77
#![crate_type = "lib"]
8-
#![feature(no_core, naked_functions)]
8+
#![feature(no_core)]
99
#![no_core]
1010

1111
extern crate minicore;

tests/ui/asm/naked-functions-rustic-abi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//@ build-pass
77
//@ needs-asm-support
88

9-
#![feature(naked_functions, naked_functions_rustic_abi, rust_cold_cc)]
9+
#![feature(naked_functions_rustic_abi, rust_cold_cc)]
1010
#![crate_type = "lib"]
1111

1212
use std::arch::{asm, naked_asm};

tests/ui/asm/naked-functions-target-feature.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ build-pass
22
//@ needs-asm-support
33

4-
#![feature(naked_functions, naked_functions_target_feature)]
4+
#![feature(naked_functions_target_feature)]
55
#![crate_type = "lib"]
66

77
use std::arch::{asm, naked_asm};

tests/ui/asm/naked-functions-testattrs.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//@ needs-asm-support
22
//@ compile-flags: --test
33

4-
#![feature(naked_functions)]
54
#![feature(test)]
65
#![crate_type = "lib"]
76

tests/ui/asm/naked-functions-testattrs.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
error[E0736]: cannot use `#[unsafe(naked)]` with testing attributes
2-
--> $DIR/naked-functions-testattrs.rs:11:1
2+
--> $DIR/naked-functions-testattrs.rs:10:1
33
|
44
LL | #[test]
55
| ------- function marked with testing attribute here
66
LL | #[unsafe(naked)]
77
| ^^^^^^^^^^^^^^^^ `#[unsafe(naked)]` is incompatible with testing attributes
88

99
error[E0736]: cannot use `#[unsafe(naked)]` with testing attributes
10-
--> $DIR/naked-functions-testattrs.rs:19:1
10+
--> $DIR/naked-functions-testattrs.rs:18:1
1111
|
1212
LL | #[test]
1313
| ------- function marked with testing attribute here
1414
LL | #[unsafe(naked)]
1515
| ^^^^^^^^^^^^^^^^ `#[unsafe(naked)]` is incompatible with testing attributes
1616

1717
error[E0736]: cannot use `#[unsafe(naked)]` with testing attributes
18-
--> $DIR/naked-functions-testattrs.rs:27:1
18+
--> $DIR/naked-functions-testattrs.rs:26:1
1919
|
2020
LL | #[test]
2121
| ------- function marked with testing attribute here
2222
LL | #[unsafe(naked)]
2323
| ^^^^^^^^^^^^^^^^ `#[unsafe(naked)]` is incompatible with testing attributes
2424

2525
error[E0736]: cannot use `#[unsafe(naked)]` with testing attributes
26-
--> $DIR/naked-functions-testattrs.rs:34:1
26+
--> $DIR/naked-functions-testattrs.rs:33:1
2727
|
2828
LL | #[bench]
2929
| -------- function marked with testing attribute here

0 commit comments

Comments
 (0)