Skip to content

Commit 400e8e5

Browse files
committed
Fix attribute printing in an error.
The current code assumes that the attribute is just an identifier, and so misprints paths.
1 parent 4be670f commit 400e8e5

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

Diff for: compiler/rustc_passes/src/check_attr.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -561,12 +561,15 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
561561
allowed_target: Target,
562562
) {
563563
if target != allowed_target {
564+
let path = attr.path();
565+
let path: Vec<_> = path.iter().map(|s| s.as_str()).collect();
566+
let attr_name = path.join("::");
564567
self.tcx.emit_node_span_lint(
565568
UNUSED_ATTRIBUTES,
566569
hir_id,
567570
attr.span(),
568571
errors::OnlyHasEffectOn {
569-
attr_name: attr.name_or_empty(),
572+
attr_name,
570573
target_name: allowed_target.name().replace(' ', "_"),
571574
},
572575
);

Diff for: compiler/rustc_passes/src/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1433,7 +1433,7 @@ pub(crate) struct UselessAssignment<'a> {
14331433
#[derive(LintDiagnostic)]
14341434
#[diag(passes_only_has_effect_on)]
14351435
pub(crate) struct OnlyHasEffectOn {
1436-
pub attr_name: Symbol,
1436+
pub attr_name: String,
14371437
pub target_name: String,
14381438
}
14391439

Diff for: tests/ui/attributes/check-builtin-attr-ice.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@
4444
struct Foo {
4545
#[should_panic::skip]
4646
//~^ ERROR failed to resolve
47-
//~| ERROR `#[]` only has an effect on functions
47+
//~| ERROR `#[should_panic::skip]` only has an effect on functions
4848
pub field: u8,
4949

5050
#[should_panic::a::b::c]
5151
//~^ ERROR failed to resolve
52-
//~| ERROR `#[]` only has an effect on functions
52+
//~| ERROR `#[should_panic::a::b::c]` only has an effect on functions
5353
pub field2: u8,
5454
}
5555

Diff for: tests/ui/attributes/check-builtin-attr-ice.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ error[E0433]: failed to resolve: use of unresolved module or unlinked crate `den
1616
LL | #[deny::skip]
1717
| ^^^^ use of unresolved module or unlinked crate `deny`
1818

19-
error: `#[]` only has an effect on functions
19+
error: `#[should_panic::skip]` only has an effect on functions
2020
--> $DIR/check-builtin-attr-ice.rs:45:5
2121
|
2222
LL | #[should_panic::skip]
@@ -28,7 +28,7 @@ note: the lint level is defined here
2828
LL | #![deny(unused_attributes)]
2929
| ^^^^^^^^^^^^^^^^^
3030

31-
error: `#[]` only has an effect on functions
31+
error: `#[should_panic::a::b::c]` only has an effect on functions
3232
--> $DIR/check-builtin-attr-ice.rs:50:5
3333
|
3434
LL | #[should_panic::a::b::c]

0 commit comments

Comments
 (0)