1
Fork 0

Show used attribute's kind for user when find it isn't applied to a static variable.

fixes #126789
This commit is contained in:
surechen 2024-06-29 18:45:07 +08:00
parent 4e63822fc4
commit 9c0ce05d24
6 changed files with 35 additions and 3 deletions

View file

@ -278,7 +278,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
}
self.check_repr(attrs, span, target, item, hir_id);
self.check_used(attrs, target);
self.check_used(attrs, target, span);
}
fn inline_attr_str_error_with_macro_def(&self, hir_id: HirId, attr: &Attribute, sym: &str) {
@ -1978,12 +1978,16 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
}
}
fn check_used(&self, attrs: &[Attribute], target: Target) {
fn check_used(&self, attrs: &[Attribute], target: Target, target_span: Span) {
let mut used_linker_span = None;
let mut used_compiler_span = None;
for attr in attrs.iter().filter(|attr| attr.has_name(sym::used)) {
if target != Target::Static {
self.dcx().emit_err(errors::UsedStatic { span: attr.span });
self.dcx().emit_err(errors::UsedStatic {
attr_span: attr.span,
span: target_span,
target: target.name(),
});
}
let inner = attr.meta_item_list();
match inner.as_deref() {

View file

@ -563,7 +563,10 @@ pub struct ReprConflictingLint;
#[diag(passes_used_static)]
pub struct UsedStatic {
#[primary_span]
pub attr_span: Span,
#[label]
pub span: Span,
pub target: &'static str,
}
#[derive(Diagnostic)]