Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e92560c

Browse files
committedMar 16, 2025
add naked_functions_target_feature unstable feature
1 parent 8b87fef commit e92560c

File tree

7 files changed

+67
-8
lines changed

7 files changed

+67
-8
lines changed
 

‎compiler/rustc_feature/src/unstable.rs

+2
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,8 @@ declare_features! (
568568
(incomplete, mut_ref, "1.79.0", Some(123076)),
569569
/// Allows using `#[naked]` on functions.
570570
(unstable, naked_functions, "1.9.0", Some(90957)),
571+
/// Allows using `#[target_feature(enable = "...")]` on `#[naked]` on functions.
572+
(unstable, naked_functions_target_feature, "1.86.0", Some(138568)),
571573
/// Allows specifying the as-needed link modifier
572574
(unstable, native_link_modifiers_as_needed, "1.53.0", Some(81490)),
573575
/// Allow negative trait implementations.

‎compiler/rustc_passes/src/check_attr.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
598598
sym::repr,
599599
// code generation
600600
sym::cold,
601-
sym::target_feature,
602601
// documentation
603602
sym::doc,
604603
];
@@ -624,6 +623,21 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
624623
_ => {}
625624
}
626625

626+
if other_attr.has_name(sym::target_feature) {
627+
if !self.tcx.features().naked_functions_target_feature() {
628+
feature_err(
629+
&self.tcx.sess,
630+
sym::naked_functions_target_feature,
631+
other_attr.span(),
632+
"`#[target_feature(/* ... */)]` is currently unstable on `#[naked]` functions",
633+
).emit();
634+
635+
return;
636+
} else {
637+
continue;
638+
}
639+
}
640+
627641
if !ALLOW_LIST.iter().any(|name| other_attr.has_name(*name)) {
628642
self.dcx().emit_err(errors::NakedFunctionIncompatibleAttribute {
629643
span: other_attr.span(),

‎compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1375,6 +1375,7 @@ symbols! {
13751375
naked,
13761376
naked_asm,
13771377
naked_functions,
1378+
naked_functions_target_feature,
13781379
name,
13791380
names,
13801381
native_link_modifiers,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//@ build-pass
2+
//@ needs-asm-support
3+
4+
#![feature(naked_functions, naked_functions_target_feature)]
5+
#![crate_type = "lib"]
6+
7+
use std::arch::{asm, naked_asm};
8+
9+
#[cfg(target_arch = "x86_64")]
10+
#[target_feature(enable = "sse2")]
11+
#[naked]
12+
pub unsafe extern "C" fn compatible_target_feature() {
13+
naked_asm!("");
14+
}
15+
16+
#[cfg(target_arch = "aarch64")]
17+
#[target_feature(enable = "neon")]
18+
#[naked]
19+
pub unsafe extern "C" fn compatible_target_feature() {
20+
naked_asm!("");
21+
}

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

-7
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,6 @@ pub unsafe extern "C" fn compatible_codegen_attributes() {
230230
naked_asm!("", options(raw));
231231
}
232232

233-
#[cfg(target_arch = "x86_64")]
234-
#[target_feature(enable = "sse2")]
235-
#[naked]
236-
pub unsafe extern "C" fn compatible_target_feature() {
237-
naked_asm!("");
238-
}
239-
240233
#[doc = "foo bar baz"]
241234
/// a doc comment
242235
// a normal comment
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//@ needs-asm-support
2+
//@ only-x86_64
3+
4+
#![feature(naked_functions)]
5+
6+
use std::arch::naked_asm;
7+
8+
#[naked]
9+
#[target_feature(enable = "avx2")]
10+
//~^ ERROR: `#[target_feature(/* ... */)]` is currently unstable on `#[naked]` functions
11+
extern "C" fn naked() {
12+
unsafe { naked_asm!("") }
13+
}
14+
15+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0658]: `#[target_feature(/* ... */)]` is currently unstable on `#[naked]` functions
2+
--> $DIR/feature-gate-naked_functions_target_feature.rs:8:1
3+
|
4+
LL | #[target_feature(enable = "avx2")]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #138568 <https://github.com/rust-lang/rust/issues/138568> for more information
8+
= help: add `#![feature(naked_functions_target_feature)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
11+
error: aborting due to 1 previous error
12+
13+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)
Failed to load comments.