Print all labels, even if they have no span. Fall back to main item's span.
This commit is contained in:
parent
21ce58732b
commit
df2adc4760
11 changed files with 110 additions and 51 deletions
|
@ -119,13 +119,13 @@ impl CheckAttrVisitor<'_> {
|
|||
}
|
||||
sym::naked => self.check_naked(hir_id, attr, span, target),
|
||||
sym::rustc_legacy_const_generics => {
|
||||
self.check_rustc_legacy_const_generics(&attr, span, target, item)
|
||||
self.check_rustc_legacy_const_generics(hir_id, &attr, span, target, item)
|
||||
}
|
||||
sym::rustc_lint_query_instability => {
|
||||
self.check_rustc_lint_query_instability(&attr, span, target)
|
||||
self.check_rustc_lint_query_instability(hir_id, &attr, span, target)
|
||||
}
|
||||
sym::rustc_lint_diagnostics => {
|
||||
self.check_rustc_lint_diagnostics(&attr, span, target)
|
||||
self.check_rustc_lint_diagnostics(hir_id, &attr, span, target)
|
||||
}
|
||||
sym::rustc_lint_opt_ty => self.check_rustc_lint_opt_ty(&attr, span, target),
|
||||
sym::rustc_lint_opt_deny_field_access => {
|
||||
|
@ -135,7 +135,9 @@ impl CheckAttrVisitor<'_> {
|
|||
| sym::rustc_dirty
|
||||
| sym::rustc_if_this_changed
|
||||
| sym::rustc_then_this_would_need => self.check_rustc_dirty_clean(&attr),
|
||||
sym::cmse_nonsecure_entry => self.check_cmse_nonsecure_entry(attr, span, target),
|
||||
sym::cmse_nonsecure_entry => {
|
||||
self.check_cmse_nonsecure_entry(hir_id, attr, span, target)
|
||||
}
|
||||
sym::collapse_debuginfo => self.check_collapse_debuginfo(attr, span, target),
|
||||
sym::const_trait => self.check_const_trait(attr, span, target),
|
||||
sym::must_not_suspend => self.check_must_not_suspend(&attr, span, target),
|
||||
|
@ -386,6 +388,7 @@ impl CheckAttrVisitor<'_> {
|
|||
self.tcx.sess.emit_err(errors::AttrShouldBeAppliedToFn {
|
||||
attr_span: attr.span,
|
||||
defn_span: span,
|
||||
on_crate: hir_id == CRATE_HIR_ID,
|
||||
});
|
||||
false
|
||||
}
|
||||
|
@ -393,7 +396,13 @@ impl CheckAttrVisitor<'_> {
|
|||
}
|
||||
|
||||
/// Checks if `#[cmse_nonsecure_entry]` is applied to a function definition.
|
||||
fn check_cmse_nonsecure_entry(&self, attr: &Attribute, span: Span, target: Target) -> bool {
|
||||
fn check_cmse_nonsecure_entry(
|
||||
&self,
|
||||
hir_id: HirId,
|
||||
attr: &Attribute,
|
||||
span: Span,
|
||||
target: Target,
|
||||
) -> bool {
|
||||
match target {
|
||||
Target::Fn
|
||||
| Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) => true,
|
||||
|
@ -401,6 +410,7 @@ impl CheckAttrVisitor<'_> {
|
|||
self.tcx.sess.emit_err(errors::AttrShouldBeAppliedToFn {
|
||||
attr_span: attr.span,
|
||||
defn_span: span,
|
||||
on_crate: hir_id == CRATE_HIR_ID,
|
||||
});
|
||||
false
|
||||
}
|
||||
|
@ -465,9 +475,11 @@ impl CheckAttrVisitor<'_> {
|
|||
true
|
||||
}
|
||||
_ => {
|
||||
self.tcx
|
||||
.sess
|
||||
.emit_err(errors::TrackedCallerWrongLocation { attr_span, defn_span: span });
|
||||
self.tcx.sess.emit_err(errors::TrackedCallerWrongLocation {
|
||||
attr_span,
|
||||
defn_span: span,
|
||||
on_crate: hir_id == CRATE_HIR_ID,
|
||||
});
|
||||
false
|
||||
}
|
||||
}
|
||||
|
@ -576,6 +588,7 @@ impl CheckAttrVisitor<'_> {
|
|||
self.tcx.sess.emit_err(errors::AttrShouldBeAppliedToFn {
|
||||
attr_span: attr.span,
|
||||
defn_span: span,
|
||||
on_crate: hir_id == CRATE_HIR_ID,
|
||||
});
|
||||
false
|
||||
}
|
||||
|
@ -1240,7 +1253,7 @@ impl CheckAttrVisitor<'_> {
|
|||
UNUSED_ATTRIBUTES,
|
||||
hir_id,
|
||||
attr.span,
|
||||
errors::Cold { span },
|
||||
errors::Cold { span, on_crate: hir_id == CRATE_HIR_ID },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1376,6 +1389,7 @@ impl CheckAttrVisitor<'_> {
|
|||
/// Checks if `#[rustc_legacy_const_generics]` is applied to a function and has a valid argument.
|
||||
fn check_rustc_legacy_const_generics(
|
||||
&self,
|
||||
hir_id: HirId,
|
||||
attr: &Attribute,
|
||||
span: Span,
|
||||
target: Target,
|
||||
|
@ -1386,6 +1400,7 @@ impl CheckAttrVisitor<'_> {
|
|||
self.tcx.sess.emit_err(errors::AttrShouldBeAppliedToFn {
|
||||
attr_span: attr.span,
|
||||
defn_span: span,
|
||||
on_crate: hir_id == CRATE_HIR_ID,
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
@ -1450,12 +1465,19 @@ impl CheckAttrVisitor<'_> {
|
|||
|
||||
/// Helper function for checking that the provided attribute is only applied to a function or
|
||||
/// method.
|
||||
fn check_applied_to_fn_or_method(&self, attr: &Attribute, span: Span, target: Target) -> bool {
|
||||
fn check_applied_to_fn_or_method(
|
||||
&self,
|
||||
hir_id: HirId,
|
||||
attr: &Attribute,
|
||||
span: Span,
|
||||
target: Target,
|
||||
) -> bool {
|
||||
let is_function = matches!(target, Target::Fn | Target::Method(..));
|
||||
if !is_function {
|
||||
self.tcx.sess.emit_err(errors::AttrShouldBeAppliedToFn {
|
||||
attr_span: attr.span,
|
||||
defn_span: span,
|
||||
on_crate: hir_id == CRATE_HIR_ID,
|
||||
});
|
||||
false
|
||||
} else {
|
||||
|
@ -1467,17 +1489,24 @@ impl CheckAttrVisitor<'_> {
|
|||
/// or method.
|
||||
fn check_rustc_lint_query_instability(
|
||||
&self,
|
||||
hir_id: HirId,
|
||||
attr: &Attribute,
|
||||
span: Span,
|
||||
target: Target,
|
||||
) -> bool {
|
||||
self.check_applied_to_fn_or_method(attr, span, target)
|
||||
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
|
||||
}
|
||||
|
||||
/// Checks that the `#[rustc_lint_diagnostics]` attribute is only applied to a function or
|
||||
/// method.
|
||||
fn check_rustc_lint_diagnostics(&self, attr: &Attribute, span: Span, target: Target) -> bool {
|
||||
self.check_applied_to_fn_or_method(attr, span, target)
|
||||
fn check_rustc_lint_diagnostics(
|
||||
&self,
|
||||
hir_id: HirId,
|
||||
attr: &Attribute,
|
||||
span: Span,
|
||||
target: Target,
|
||||
) -> bool {
|
||||
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
|
||||
}
|
||||
|
||||
/// Checks that the `#[rustc_lint_opt_ty]` attribute is only applied to a struct.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue