mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
improve error message when #[naked]
is used with #[track-caller] and
#[target-feature]``
This commit is contained in:
parent
4bd36324b6
commit
7e6c083873
@ -485,7 +485,7 @@ passes_naked_functions_asm_options =
|
||||
passes_naked_functions_codegen_attribute =
|
||||
cannot use additional code generation attributes with `#[naked]`
|
||||
.label = this attribute is incompatible with `#[naked]`
|
||||
.label2 = function marked with `#[naked]` here
|
||||
.naked_attribute = function marked with `#[naked]` here
|
||||
|
||||
passes_naked_functions_must_use_noreturn =
|
||||
asm in naked functions must use `noreturn` option
|
||||
|
@ -421,20 +421,22 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
||||
const FORBIDDEN: [rustc_span::Symbol; 3] =
|
||||
[sym::track_caller, sym::inline, sym::target_feature];
|
||||
|
||||
for other_attr in attrs {
|
||||
if FORBIDDEN.into_iter().any(|name| other_attr.has_name(name)) {
|
||||
self.dcx().emit_err(errors::NakedFunctionCodegenAttribute {
|
||||
span: other_attr.span,
|
||||
naked_span: attr.span,
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
match target {
|
||||
Target::Fn
|
||||
| Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) => true,
|
||||
| Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) => {
|
||||
for other_attr in attrs {
|
||||
if FORBIDDEN.into_iter().any(|name| other_attr.has_name(name)) {
|
||||
self.dcx().emit_err(errors::NakedFunctionCodegenAttribute {
|
||||
span: other_attr.span,
|
||||
naked_span: attr.span,
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
// FIXME(#80564): We permit struct fields, match arms and macro defs to have an
|
||||
// `#[naked]` attribute with just a lint, because we previously
|
||||
// erroneously allowed it and some crates used it accidentally, to be compatible
|
||||
|
@ -1188,7 +1188,7 @@ pub struct NakedFunctionCodegenAttribute {
|
||||
#[primary_span]
|
||||
#[label]
|
||||
pub span: Span,
|
||||
#[label(passes_label2)]
|
||||
#[label(passes_naked_attribute)]
|
||||
pub naked_span: Span,
|
||||
}
|
||||
|
||||
|
13
tests/ui/asm/naked-functions-target-feature.rs
Normal file
13
tests/ui/asm/naked-functions-target-feature.rs
Normal file
@ -0,0 +1,13 @@
|
||||
//@ only-x86_64
|
||||
//@ needs-asm-support
|
||||
#![feature(naked_functions)]
|
||||
#![crate_type = "lib"]
|
||||
|
||||
use std::arch::asm;
|
||||
|
||||
#[target_feature(enable = "sse2")]
|
||||
//~^ ERROR [E0736]
|
||||
#[naked]
|
||||
pub unsafe extern "C" fn naked_target_feature() {
|
||||
asm!("", options(noreturn));
|
||||
}
|
12
tests/ui/asm/naked-functions-target-feature.stderr
Normal file
12
tests/ui/asm/naked-functions-target-feature.stderr
Normal file
@ -0,0 +1,12 @@
|
||||
error[E0736]: cannot use additional code generation attributes with `#[naked]`
|
||||
--> $DIR/naked-functions-target-feature.rs:8:1
|
||||
|
|
||||
LL | #[target_feature(enable = "sse2")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this attribute is incompatible with `#[naked]`
|
||||
LL |
|
||||
LL | #[naked]
|
||||
| -------- function marked with `#[naked]` here
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0736`.
|
@ -3,7 +3,7 @@
|
||||
|
||||
use std::arch::asm;
|
||||
|
||||
#[track_caller] //~ ERROR cannot use `#[track_caller]` with `#[naked]`
|
||||
#[track_caller] //~ ERROR [E0736]
|
||||
//~^ ERROR `#[track_caller]` requires Rust ABI
|
||||
#[naked]
|
||||
extern "C" fn f() {
|
||||
@ -15,7 +15,7 @@ extern "C" fn f() {
|
||||
struct S;
|
||||
|
||||
impl S {
|
||||
#[track_caller] //~ ERROR cannot use `#[track_caller]` with `#[naked]`
|
||||
#[track_caller] //~ ERROR [E0736]
|
||||
//~^ ERROR `#[track_caller]` requires Rust ABI
|
||||
#[naked]
|
||||
extern "C" fn g() {
|
||||
|
@ -1,14 +1,20 @@
|
||||
error[E0736]: cannot use `#[track_caller]` with `#[naked]`
|
||||
error[E0736]: cannot use additional code generation attributes with `#[naked]`
|
||||
--> $DIR/error-with-naked.rs:6:1
|
||||
|
|
||||
LL | #[track_caller]
|
||||
| ^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^^^ this attribute is incompatible with `#[naked]`
|
||||
LL |
|
||||
LL | #[naked]
|
||||
| -------- function marked with `#[naked]` here
|
||||
|
||||
error[E0736]: cannot use `#[track_caller]` with `#[naked]`
|
||||
error[E0736]: cannot use additional code generation attributes with `#[naked]`
|
||||
--> $DIR/error-with-naked.rs:18:5
|
||||
|
|
||||
LL | #[track_caller]
|
||||
| ^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^^^ this attribute is incompatible with `#[naked]`
|
||||
LL |
|
||||
LL | #[naked]
|
||||
| -------- function marked with `#[naked]` here
|
||||
|
||||
error[E0737]: `#[track_caller]` requires Rust ABI
|
||||
--> $DIR/error-with-naked.rs:6:1
|
||||
|
Loading…
Reference in New Issue
Block a user