improve error message when #[naked]
is used with #[track-caller] and
#[target-feature]``
This commit is contained in:
parent
4bd36324b6
commit
7e6c083873
7 changed files with 53 additions and 20 deletions
|
@ -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,
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue