1
Fork 0

improve error message when #[naked] is used with #[track-caller] and #[target-feature]``

This commit is contained in:
Folkert 2024-07-16 23:35:02 +02:00
parent 4bd36324b6
commit 7e6c083873
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
7 changed files with 53 additions and 20 deletions

View file

@ -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

View file

@ -1188,7 +1188,7 @@ pub struct NakedFunctionCodegenAttribute {
#[primary_span]
#[label]
pub span: Span,
#[label(passes_label2)]
#[label(passes_naked_attribute)]
pub naked_span: Span,
}