add naked_functions_target_feature
unstable feature
This commit is contained in:
parent
8b87fefd76
commit
c26142697c
7 changed files with 67 additions and 8 deletions
|
@ -568,6 +568,8 @@ declare_features! (
|
||||||
(incomplete, mut_ref, "1.79.0", Some(123076)),
|
(incomplete, mut_ref, "1.79.0", Some(123076)),
|
||||||
/// Allows using `#[naked]` on functions.
|
/// Allows using `#[naked]` on functions.
|
||||||
(unstable, naked_functions, "1.9.0", Some(90957)),
|
(unstable, naked_functions, "1.9.0", Some(90957)),
|
||||||
|
/// Allows using `#[target_feature(enable = "...")]` on `#[naked]` on functions.
|
||||||
|
(unstable, naked_functions_target_feature, "1.86.0", Some(138568)),
|
||||||
/// Allows specifying the as-needed link modifier
|
/// Allows specifying the as-needed link modifier
|
||||||
(unstable, native_link_modifiers_as_needed, "1.53.0", Some(81490)),
|
(unstable, native_link_modifiers_as_needed, "1.53.0", Some(81490)),
|
||||||
/// Allow negative trait implementations.
|
/// Allow negative trait implementations.
|
||||||
|
|
|
@ -598,7 +598,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
||||||
sym::repr,
|
sym::repr,
|
||||||
// code generation
|
// code generation
|
||||||
sym::cold,
|
sym::cold,
|
||||||
sym::target_feature,
|
|
||||||
// documentation
|
// documentation
|
||||||
sym::doc,
|
sym::doc,
|
||||||
];
|
];
|
||||||
|
@ -624,6 +623,21 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if other_attr.has_name(sym::target_feature) {
|
||||||
|
if !self.tcx.features().naked_functions_target_feature() {
|
||||||
|
feature_err(
|
||||||
|
&self.tcx.sess,
|
||||||
|
sym::naked_functions_target_feature,
|
||||||
|
other_attr.span(),
|
||||||
|
"`#[target_feature(/* ... */)]` is currently unstable on `#[naked]` functions",
|
||||||
|
).emit();
|
||||||
|
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if !ALLOW_LIST.iter().any(|name| other_attr.has_name(*name)) {
|
if !ALLOW_LIST.iter().any(|name| other_attr.has_name(*name)) {
|
||||||
self.dcx().emit_err(errors::NakedFunctionIncompatibleAttribute {
|
self.dcx().emit_err(errors::NakedFunctionIncompatibleAttribute {
|
||||||
span: other_attr.span(),
|
span: other_attr.span(),
|
||||||
|
|
|
@ -1375,6 +1375,7 @@ symbols! {
|
||||||
naked,
|
naked,
|
||||||
naked_asm,
|
naked_asm,
|
||||||
naked_functions,
|
naked_functions,
|
||||||
|
naked_functions_target_feature,
|
||||||
name,
|
name,
|
||||||
names,
|
names,
|
||||||
native_link_modifiers,
|
native_link_modifiers,
|
||||||
|
|
21
tests/ui/asm/naked-functions-target-feature.rs
Normal file
21
tests/ui/asm/naked-functions-target-feature.rs
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
//@ build-pass
|
||||||
|
//@ needs-asm-support
|
||||||
|
|
||||||
|
#![feature(naked_functions, naked_functions_target_feature)]
|
||||||
|
#![crate_type = "lib"]
|
||||||
|
|
||||||
|
use std::arch::{asm, naked_asm};
|
||||||
|
|
||||||
|
#[cfg(target_arch = "x86_64")]
|
||||||
|
#[target_feature(enable = "sse2")]
|
||||||
|
#[naked]
|
||||||
|
pub unsafe extern "C" fn compatible_target_feature() {
|
||||||
|
naked_asm!("");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_arch = "aarch64")]
|
||||||
|
#[target_feature(enable = "neon")]
|
||||||
|
#[naked]
|
||||||
|
pub unsafe extern "C" fn compatible_target_feature() {
|
||||||
|
naked_asm!("");
|
||||||
|
}
|
|
@ -230,13 +230,6 @@ pub unsafe extern "C" fn compatible_codegen_attributes() {
|
||||||
naked_asm!("", options(raw));
|
naked_asm!("", options(raw));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
#[target_feature(enable = "sse2")]
|
|
||||||
#[naked]
|
|
||||||
pub unsafe extern "C" fn compatible_target_feature() {
|
|
||||||
naked_asm!("");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[doc = "foo bar baz"]
|
#[doc = "foo bar baz"]
|
||||||
/// a doc comment
|
/// a doc comment
|
||||||
// a normal comment
|
// a normal comment
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
//@ needs-asm-support
|
||||||
|
//@ only-x86_64
|
||||||
|
|
||||||
|
#![feature(naked_functions)]
|
||||||
|
|
||||||
|
use std::arch::naked_asm;
|
||||||
|
|
||||||
|
#[naked]
|
||||||
|
#[target_feature(enable = "avx2")]
|
||||||
|
//~^ ERROR: `#[target_feature(/* ... */)]` is currently unstable on `#[naked]` functions
|
||||||
|
extern "C" fn naked() {
|
||||||
|
unsafe { naked_asm!("") }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
|
@ -0,0 +1,13 @@
|
||||||
|
error[E0658]: `#[target_feature(/* ... */)]` is currently unstable on `#[naked]` functions
|
||||||
|
--> $DIR/feature-gate-naked_functions_target_feature.rs:9:1
|
||||||
|
|
|
||||||
|
LL | #[target_feature(enable = "avx2")]
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: see issue #138568 <https://github.com/rust-lang/rust/issues/138568> for more information
|
||||||
|
= help: add `#![feature(naked_functions_target_feature)]` to the crate attributes to enable
|
||||||
|
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0658`.
|
Loading…
Add table
Add a link
Reference in a new issue