Skip to content

Commit 34386b3

Browse files
committed
Stabilize naked_functions
This stabilizes the feature described in RFC 2972, which supersedes the earlier RFC 1201. Closes #32408 Closes #90957
1 parent 250384e commit 34386b3

20 files changed

+47
-94
lines changed

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
#[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
@@ -203,6 +203,8 @@ declare_features! (
203203
/// Allows patterns with concurrent by-move and by-ref bindings.
204204
/// For example, you can write `Foo(a, ref b)` where `a` is by-move and `b` is by-ref.
205205
(accepted, move_ref_pattern, "1.49.0", Some(68354), None),
206+
/// Allows using `#[naked]` on functions.
207+
(accepted, naked_functions, "1.60.0", Some(90957), None),
206208
/// Allows using `#![no_std]`.
207209
(accepted, no_std, "1.6.0", None, None),
208210
/// Allows defining identifiers beyond ASCII.

compiler/rustc_feature/src/active.rs

-2
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,6 @@ declare_features! (
435435
(active, more_qualified_paths, "1.54.0", Some(86935), None),
436436
/// Allows the `#[must_not_suspend]` attribute.
437437
(active, must_not_suspend, "1.57.0", Some(83310), None),
438-
/// Allows using `#[naked]` on functions.
439-
(active, naked_functions, "1.9.0", Some(32408), None),
440438
/// Allows specifying modifiers in the link attribute: `#[link(modifiers = "...")]`
441439
(active, native_link_modifiers, "1.53.0", Some(81490), None),
442440
/// Allows specifying the as-needed link modifier

compiler/rustc_feature/src/builtin_attrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
360360
// Code generation:
361361
ungated!(inline, Normal, template!(Word, List: "always|never"), FutureWarnFollowing),
362362
ungated!(cold, Normal, template!(Word), WarnFollowing),
363+
ungated!(naked, Normal, template!(Word), WarnFollowing),
363364
ungated!(no_builtins, CrateLevel, template!(Word), WarnFollowing),
364365
ungated!(target_feature, Normal, template!(List: r#"enable = "name""#), DuplicatesOk),
365366
ungated!(track_caller, Normal, template!(Word), WarnFollowing),
@@ -379,7 +380,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
379380
// ==========================================================================
380381

381382
// Linking:
382-
gated!(naked, Normal, template!(Word), WarnFollowing, naked_functions, experimental!(naked)),
383383
gated!(
384384
link_ordinal, Normal, template!(List: "ordinal"), ErrorPreceding, raw_dylib,
385385
experimental!(link_ordinal)

compiler/rustc_lint_defs/src/builtin.rs

-2
Original file line numberDiff line numberDiff line change
@@ -2745,8 +2745,6 @@ declare_lint! {
27452745
/// ### Example
27462746
///
27472747
/// ```rust
2748-
/// #![feature(naked_functions)]
2749-
///
27502748
/// use std::arch::asm;
27512749
///
27522750
/// #[naked]

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

-2
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,6 @@ LLVM CFI can be enabled with -Zsanitizer=cfi and requires LTO (i.e., -Clto).
199199
## Example
200200
201201
```text
202-
#![feature(naked_functions)]
203-
204202
use std::arch::asm;
205203
use std::mem;
206204

src/test/codegen/naked-functions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// only-x86_64
44

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

99
// CHECK: Function Attrs: naked

src/test/codegen/naked-noinline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// compile-flags: -O -Zmir-opt-level=3
33
// needs-asm-support
44
// ignore-wasm32
5+
56
#![crate_type = "lib"]
6-
#![feature(naked_functions)]
77

88
use std::arch::asm;
99

src/test/ui/asm/naked-functions-ffi.rs

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

66
use std::arch::asm;

src/test/ui/asm/naked-functions-unused.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// revisions: x86_64 aarch64
22
//[x86_64] only-x86_64
33
//[aarch64] only-aarch64
4+
45
#![deny(unused)]
5-
#![feature(naked_functions)]
66
#![crate_type = "lib"]
77

88
pub trait Trait {

src/test/ui/asm/naked-functions-unused.x86_64.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | pub extern "C" fn function(a: usize, b: usize) -> usize {
55
| ^ help: if this is intentional, prefix it with an underscore: `_a`
66
|
77
note: the lint level is defined here
8-
--> $DIR/naked-functions-unused.rs:4:9
8+
--> $DIR/naked-functions-unused.rs:5:9
99
|
1010
LL | #![deny(unused)]
1111
| ^^^^^^

src/test/ui/asm/naked-functions.rs

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

6-
#![feature(naked_functions)]
76
#![feature(or_patterns)]
87
#![feature(asm_const, asm_sym, asm_unwind)]
98
#![crate_type = "lib"]
@@ -127,7 +126,7 @@ pub unsafe fn default_abi() {
127126
}
128127

129128
#[naked]
130-
pub unsafe fn rust_abi() {
129+
pub unsafe extern "Rust" fn rust_abi() {
131130
//~^ WARN Rust ABI is unsupported in naked functions
132131
asm!("", options(noreturn));
133132
}

src/test/ui/asm/naked-functions.stderr

+34-34
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11
error: asm with the `pure` option must have at least one output
2-
--> $DIR/naked-functions.rs:111:14
2+
--> $DIR/naked-functions.rs:110:14
33
|
44
LL | asm!("", options(readonly, nostack), options(pure));
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^
66

77
error: patterns not allowed in naked function parameters
8-
--> $DIR/naked-functions.rs:21:5
8+
--> $DIR/naked-functions.rs:20:5
99
|
1010
LL | mut a: u32,
1111
| ^^^^^
1212

1313
error: patterns not allowed in naked function parameters
14-
--> $DIR/naked-functions.rs:23:5
14+
--> $DIR/naked-functions.rs:22:5
1515
|
1616
LL | &b: &i32,
1717
| ^^
1818

1919
error: patterns not allowed in naked function parameters
20-
--> $DIR/naked-functions.rs:25:6
20+
--> $DIR/naked-functions.rs:24:6
2121
|
2222
LL | (None | Some(_)): Option<std::ptr::NonNull<u8>>,
2323
| ^^^^^^^^^^^^^^
2424

2525
error: patterns not allowed in naked function parameters
26-
--> $DIR/naked-functions.rs:27:5
26+
--> $DIR/naked-functions.rs:26:5
2727
|
2828
LL | P { x, y }: P,
2929
| ^^^^^^^^^^
3030

3131
error: referencing function parameters is not allowed in naked functions
32-
--> $DIR/naked-functions.rs:36:5
32+
--> $DIR/naked-functions.rs:35:5
3333
|
3434
LL | a + 1
3535
| ^
3636
|
3737
= help: follow the calling convention in asm block to use parameters
3838

3939
error[E0787]: naked functions must contain a single asm block
40-
--> $DIR/naked-functions.rs:34:1
40+
--> $DIR/naked-functions.rs:33:1
4141
|
4242
LL | / pub unsafe extern "C" fn inc(a: u32) -> u32 {
4343
LL | |
@@ -48,21 +48,21 @@ LL | | }
4848
| |_^
4949

5050
error: referencing function parameters is not allowed in naked functions
51-
--> $DIR/naked-functions.rs:42:31
51+
--> $DIR/naked-functions.rs:41:31
5252
|
5353
LL | asm!("/* {0} */", in(reg) a, options(noreturn));
5454
| ^
5555
|
5656
= help: follow the calling convention in asm block to use parameters
5757

5858
error[E0787]: only `const` and `sym` operands are supported in naked functions
59-
--> $DIR/naked-functions.rs:42:23
59+
--> $DIR/naked-functions.rs:41:23
6060
|
6161
LL | asm!("/* {0} */", in(reg) a, options(noreturn));
6262
| ^^^^^^^^^
6363

6464
error[E0787]: naked functions must contain a single asm block
65-
--> $DIR/naked-functions.rs:48:1
65+
--> $DIR/naked-functions.rs:47:1
6666
|
6767
LL | / pub unsafe extern "C" fn inc_closure(a: u32) -> u32 {
6868
LL | |
@@ -72,7 +72,7 @@ LL | | }
7272
| |_^
7373

7474
error[E0787]: only `const` and `sym` operands are supported in naked functions
75-
--> $DIR/naked-functions.rs:65:10
75+
--> $DIR/naked-functions.rs:64:10
7676
|
7777
LL | in(reg) a,
7878
| ^^^^^^^^^
@@ -87,7 +87,7 @@ LL | out(reg) e,
8787
| ^^^^^^^^^^
8888

8989
error[E0787]: asm in naked functions must use `noreturn` option
90-
--> $DIR/naked-functions.rs:63:5
90+
--> $DIR/naked-functions.rs:62:5
9191
|
9292
LL | / asm!("/* {0} {1} {2} {3} {4} {5} {6} */",
9393
LL | |
@@ -99,7 +99,7 @@ LL | | );
9999
| |_____^
100100

101101
error[E0787]: naked functions must contain a single asm block
102-
--> $DIR/naked-functions.rs:54:1
102+
--> $DIR/naked-functions.rs:53:1
103103
|
104104
LL | / pub unsafe extern "C" fn unsupported_operands() {
105105
LL | |
@@ -119,33 +119,33 @@ LL | | }
119119
| |_^
120120

121121
error[E0787]: naked functions must contain a single asm block
122-
--> $DIR/naked-functions.rs:77:1
122+
--> $DIR/naked-functions.rs:76:1
123123
|
124124
LL | / pub extern "C" fn missing_assembly() {
125125
LL | |
126126
LL | | }
127127
| |_^
128128

129129
error[E0787]: asm in naked functions must use `noreturn` option
130-
--> $DIR/naked-functions.rs:84:5
130+
--> $DIR/naked-functions.rs:83:5
131131
|
132132
LL | asm!("");
133133
| ^^^^^^^^
134134

135135
error[E0787]: asm in naked functions must use `noreturn` option
136-
--> $DIR/naked-functions.rs:86:5
136+
--> $DIR/naked-functions.rs:85:5
137137
|
138138
LL | asm!("");
139139
| ^^^^^^^^
140140

141141
error[E0787]: asm in naked functions must use `noreturn` option
142-
--> $DIR/naked-functions.rs:88:5
142+
--> $DIR/naked-functions.rs:87:5
143143
|
144144
LL | asm!("");
145145
| ^^^^^^^^
146146

147147
error[E0787]: naked functions must contain a single asm block
148-
--> $DIR/naked-functions.rs:82:1
148+
--> $DIR/naked-functions.rs:81:1
149149
|
150150
LL | / pub extern "C" fn too_many_asm_blocks() {
151151
LL | |
@@ -163,15 +163,15 @@ LL | | }
163163
| |_^
164164

165165
error: referencing function parameters is not allowed in naked functions
166-
--> $DIR/naked-functions.rs:97:11
166+
--> $DIR/naked-functions.rs:96:11
167167
|
168168
LL | *&y
169169
| ^
170170
|
171171
= help: follow the calling convention in asm block to use parameters
172172

173173
error[E0787]: naked functions must contain a single asm block
174-
--> $DIR/naked-functions.rs:95:5
174+
--> $DIR/naked-functions.rs:94:5
175175
|
176176
LL | / pub extern "C" fn inner(y: usize) -> usize {
177177
LL | |
@@ -182,75 +182,75 @@ LL | | }
182182
| |_____^
183183

184184
error[E0787]: asm options unsupported in naked functions: `nomem`, `preserves_flags`
185-
--> $DIR/naked-functions.rs:105:5
185+
--> $DIR/naked-functions.rs:104:5
186186
|
187187
LL | asm!("", options(nomem, preserves_flags, noreturn));
188188
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
189189

190190
error[E0787]: asm options unsupported in naked functions: `nostack`, `pure`, `readonly`
191-
--> $DIR/naked-functions.rs:111:5
191+
--> $DIR/naked-functions.rs:110:5
192192
|
193193
LL | asm!("", options(readonly, nostack), options(pure));
194194
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
195195

196196
error[E0787]: asm in naked functions must use `noreturn` option
197-
--> $DIR/naked-functions.rs:111:5
197+
--> $DIR/naked-functions.rs:110:5
198198
|
199199
LL | asm!("", options(readonly, nostack), options(pure));
200200
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
201201

202202
error[E0787]: asm options unsupported in naked functions: `may_unwind`
203-
--> $DIR/naked-functions.rs:119:5
203+
--> $DIR/naked-functions.rs:118:5
204204
|
205205
LL | asm!("", options(noreturn, may_unwind));
206206
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
207207

208208
warning: Rust ABI is unsupported in naked functions
209-
--> $DIR/naked-functions.rs:124:15
209+
--> $DIR/naked-functions.rs:123:15
210210
|
211211
LL | pub unsafe fn default_abi() {
212212
| ^^^^^^^^^^^
213213
|
214214
= note: `#[warn(undefined_naked_function_abi)]` on by default
215215

216216
warning: Rust ABI is unsupported in naked functions
217-
--> $DIR/naked-functions.rs:130:15
217+
--> $DIR/naked-functions.rs:129:29
218218
|
219-
LL | pub unsafe fn rust_abi() {
220-
| ^^^^^^^^
219+
LL | pub unsafe extern "Rust" fn rust_abi() {
220+
| ^^^^^^^^
221221

222222
error: naked functions cannot be inlined
223-
--> $DIR/naked-functions.rs:170:1
223+
--> $DIR/naked-functions.rs:169:1
224224
|
225225
LL | #[inline]
226226
| ^^^^^^^^^
227227

228228
error: naked functions cannot be inlined
229-
--> $DIR/naked-functions.rs:177:1
229+
--> $DIR/naked-functions.rs:176:1
230230
|
231231
LL | #[inline(always)]
232232
| ^^^^^^^^^^^^^^^^^
233233

234234
error: naked functions cannot be inlined
235-
--> $DIR/naked-functions.rs:184:1
235+
--> $DIR/naked-functions.rs:183:1
236236
|
237237
LL | #[inline(never)]
238238
| ^^^^^^^^^^^^^^^^
239239

240240
error: naked functions cannot be inlined
241-
--> $DIR/naked-functions.rs:191:1
241+
--> $DIR/naked-functions.rs:190:1
242242
|
243243
LL | #[inline]
244244
| ^^^^^^^^^
245245

246246
error: naked functions cannot be inlined
247-
--> $DIR/naked-functions.rs:193:1
247+
--> $DIR/naked-functions.rs:192:1
248248
|
249249
LL | #[inline(always)]
250250
| ^^^^^^^^^^^^^^^^^
251251

252252
error: naked functions cannot be inlined
253-
--> $DIR/naked-functions.rs:195:1
253+
--> $DIR/naked-functions.rs:194:1
254254
|
255255
LL | #[inline(never)]
256256
| ^^^^^^^^^^^^^^^^

src/test/ui/asm/naked-invalid-attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Checks that #[naked] attribute can be placed on function definitions only.
22
//
33
// needs-asm-support
4-
#![feature(naked_functions)]
4+
55
#![naked] //~ ERROR should be applied to a function definition
66

77
use std::arch::asm;

src/test/ui/asm/named-asm-labels.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// which causes less readable LLVM errors and in the worst cases causes ICEs
1212
// or segfaults based on system dependent behavior and codegen flags.
1313

14-
#![feature(naked_functions, asm_const)]
14+
#![feature(asm_const)]
1515

1616
use std::arch::{asm, global_asm};
1717

0 commit comments

Comments
 (0)