1
Fork 0

Fix attribute printing in an error.

The current code assumes that the attribute is just an identifier, and
so misprints paths.
This commit is contained in:
Nicholas Nethercote 2025-04-09 21:15:45 +10:00
parent 4be670f89b
commit 400e8e5dc8
4 changed files with 9 additions and 6 deletions

View file

@ -561,12 +561,15 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
allowed_target: Target, allowed_target: Target,
) { ) {
if target != allowed_target { if target != allowed_target {
let path = attr.path();
let path: Vec<_> = path.iter().map(|s| s.as_str()).collect();
let attr_name = path.join("::");
self.tcx.emit_node_span_lint( self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES, UNUSED_ATTRIBUTES,
hir_id, hir_id,
attr.span(), attr.span(),
errors::OnlyHasEffectOn { errors::OnlyHasEffectOn {
attr_name: attr.name_or_empty(), attr_name,
target_name: allowed_target.name().replace(' ', "_"), target_name: allowed_target.name().replace(' ', "_"),
}, },
); );

View file

@ -1433,7 +1433,7 @@ pub(crate) struct UselessAssignment<'a> {
#[derive(LintDiagnostic)] #[derive(LintDiagnostic)]
#[diag(passes_only_has_effect_on)] #[diag(passes_only_has_effect_on)]
pub(crate) struct OnlyHasEffectOn { pub(crate) struct OnlyHasEffectOn {
pub attr_name: Symbol, pub attr_name: String,
pub target_name: String, pub target_name: String,
} }

View file

@ -44,12 +44,12 @@
struct Foo { struct Foo {
#[should_panic::skip] #[should_panic::skip]
//~^ ERROR failed to resolve //~^ ERROR failed to resolve
//~| ERROR `#[]` only has an effect on functions //~| ERROR `#[should_panic::skip]` only has an effect on functions
pub field: u8, pub field: u8,
#[should_panic::a::b::c] #[should_panic::a::b::c]
//~^ ERROR failed to resolve //~^ ERROR failed to resolve
//~| ERROR `#[]` only has an effect on functions //~| ERROR `#[should_panic::a::b::c]` only has an effect on functions
pub field2: u8, pub field2: u8,
} }

View file

@ -16,7 +16,7 @@ error[E0433]: failed to resolve: use of unresolved module or unlinked crate `den
LL | #[deny::skip] LL | #[deny::skip]
| ^^^^ use of unresolved module or unlinked crate `deny` | ^^^^ use of unresolved module or unlinked crate `deny`
error: `#[]` only has an effect on functions error: `#[should_panic::skip]` only has an effect on functions
--> $DIR/check-builtin-attr-ice.rs:45:5 --> $DIR/check-builtin-attr-ice.rs:45:5
| |
LL | #[should_panic::skip] LL | #[should_panic::skip]
@ -28,7 +28,7 @@ note: the lint level is defined here
LL | #![deny(unused_attributes)] LL | #![deny(unused_attributes)]
| ^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^
error: `#[]` only has an effect on functions error: `#[should_panic::a::b::c]` only has an effect on functions
--> $DIR/check-builtin-attr-ice.rs:50:5 --> $DIR/check-builtin-attr-ice.rs:50:5
| |
LL | #[should_panic::a::b::c] LL | #[should_panic::a::b::c]