Skip to content

Commit 3e34eb8

Browse files
committed
Putting help message only under the identifier that needs to be prefixed
1 parent 2acd8eb commit 3e34eb8

29 files changed

+183
-216
lines changed

compiler/rustc_passes/src/dead.rs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_middle::middle::privacy;
1616
use rustc_middle::ty::{self, DefIdTree, TyCtxt};
1717
use rustc_session::lint;
1818

19-
use rustc_span::symbol::{sym, Symbol};
19+
use rustc_span::symbol::{sym, Ident, Symbol};
2020

2121
// Any local node that may call something in its body block should be
2222
// explored. For example, if it's a live Node::Item that is a
@@ -578,7 +578,7 @@ impl DeadVisitor<'tcx> {
578578
&mut self,
579579
id: hir::HirId,
580580
span: rustc_span::Span,
581-
name: Symbol,
581+
name: Ident,
582582
participle: &str,
583583
extra_note: Option<ExtraNote>,
584584
) {
@@ -587,7 +587,7 @@ impl DeadVisitor<'tcx> {
587587
let def_id = self.tcx.hir().local_def_id(id);
588588
let descr = self.tcx.def_kind(def_id).descr(def_id.to_def_id());
589589

590-
let prefixed = vec![(span, format!("_{}", name))];
590+
let prefixed = vec![(name.span, format!("_{}", name))];
591591

592592
let mut diag =
593593
lint.build(&format!("{} is never {}: `{}`", descr, participle, name));
@@ -600,11 +600,11 @@ impl DeadVisitor<'tcx> {
600600

601601
let mut note = format!(
602602
"the leading underscore signals that this {} serves some other \
603-
purpose\neven if it isn't used in a way that we can detect.",
603+
purpose even if it isn't used in a way that we can detect.",
604604
descr,
605605
);
606606
if matches!(extra_note, Some(ExtraNote::OtherPurposeExamples)) {
607-
note += " (e.g. for its effect\nwhen dropped or in foreign code)";
607+
note += " (e.g. for its effect when dropped or in foreign code)";
608608
}
609609

610610
diag.note(&note);
@@ -659,7 +659,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
659659
hir::ItemKind::Struct(..) => "constructed", // Issue #52325
660660
_ => "used",
661661
};
662-
self.warn_dead_code(item.hir_id(), span, item.ident.name, participle, None);
662+
self.warn_dead_code(item.hir_id(), span, item.ident, participle, None);
663663
} else {
664664
// Only continue if we didn't warn
665665
intravisit::walk_item(self, item);
@@ -673,15 +673,15 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
673673
id: hir::HirId,
674674
) {
675675
if self.should_warn_about_variant(&variant) {
676-
self.warn_dead_code(variant.id, variant.span, variant.ident.name, "constructed", None);
676+
self.warn_dead_code(variant.id, variant.span, variant.ident, "constructed", None);
677677
} else {
678678
intravisit::walk_variant(self, variant, g, id);
679679
}
680680
}
681681

682682
fn visit_foreign_item(&mut self, fi: &'tcx hir::ForeignItem<'tcx>) {
683683
if self.should_warn_about_foreign_item(fi) {
684-
self.warn_dead_code(fi.hir_id(), fi.span, fi.ident.name, "used", None);
684+
self.warn_dead_code(fi.hir_id(), fi.span, fi.ident, "used", None);
685685
}
686686
intravisit::walk_foreign_item(self, fi);
687687
}
@@ -691,7 +691,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
691691
self.warn_dead_code(
692692
field.hir_id,
693693
field.span,
694-
field.ident.name,
694+
field.ident,
695695
"read",
696696
Some(ExtraNote::OtherPurposeExamples),
697697
);
@@ -706,7 +706,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
706706
self.warn_dead_code(
707707
impl_item.hir_id(),
708708
impl_item.span,
709-
impl_item.ident.name,
709+
impl_item.ident,
710710
"used",
711711
None,
712712
);
@@ -726,13 +726,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
726726
} else {
727727
impl_item.ident.span
728728
};
729-
self.warn_dead_code(
730-
impl_item.hir_id(),
731-
span,
732-
impl_item.ident.name,
733-
"used",
734-
None,
735-
);
729+
self.warn_dead_code(impl_item.hir_id(), span, impl_item.ident, "used", None);
736730
}
737731
self.visit_nested_body(body_id)
738732
}

src/test/ui/associated-consts/associated-const-dead-code.stderr

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ error: associated constant is never used: `BAR`
22
--> $DIR/associated-const-dead-code.rs:6:5
33
|
44
LL | const BAR: u32 = 1;
5-
| ^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_BAR`
5+
| ^^^^^^---^^^^^^^^^^
6+
| |
7+
| help: if this is intentional, prefix it with an underscore: `_BAR`
68
|
7-
= note: the leading underscore signals that this associated constant serves some other purpose
8-
even if it isn't used in a way that we can detect.
9+
= note: the leading underscore signals that this associated constant serves some other purpose even if it isn't used in a way that we can detect.
910
note: the lint level is defined here
1011
--> $DIR/associated-const-dead-code.rs:1:9
1112
|

src/test/ui/derive-uninhabited-enum-38885.stderr

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ warning: variant is never constructed: `Void`
22
--> $DIR/derive-uninhabited-enum-38885.rs:13:5
33
|
44
LL | Void(Void),
5-
| ^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_Void`
5+
| ----^^^^^^
6+
| |
7+
| help: if this is intentional, prefix it with an underscore: `_Void`
68
|
7-
= note: the leading underscore signals that this variant serves some other purpose
8-
even if it isn't used in a way that we can detect.
9+
= note: the leading underscore signals that this variant serves some other purpose even if it isn't used in a way that we can detect.
910
= note: `-W dead-code` implied by `-W unused`
1011

1112
warning: 1 warning emitted

src/test/ui/issues/issue-37515.stderr

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ warning: type alias is never used: `Z`
22
--> $DIR/issue-37515.rs:5:1
33
|
44
LL | type Z = dyn for<'x> Send;
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_Z`
5+
| ^^^^^-^^^^^^^^^^^^^^^^^^^^
6+
| |
7+
| help: if this is intentional, prefix it with an underscore: `_Z`
68
|
7-
= note: the leading underscore signals that this type alias serves some other purpose
8-
even if it isn't used in a way that we can detect.
9+
= note: the leading underscore signals that this type alias serves some other purpose even if it isn't used in a way that we can detect.
910
note: the lint level is defined here
1011
--> $DIR/issue-37515.rs:3:9
1112
|

src/test/ui/lint/dead-code/basic.stderr

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ error: function is never used: `foo`
44
LL | fn foo() {
55
| ^^^ help: if this is intentional, prefix it with an underscore: `_foo`
66
|
7-
= note: the leading underscore signals that this function serves some other purpose
8-
even if it isn't used in a way that we can detect.
7+
= note: the leading underscore signals that this function serves some other purpose even if it isn't used in a way that we can detect.
98
note: the lint level is defined here
109
--> $DIR/basic.rs:1:9
1110
|

src/test/ui/lint/dead-code/const-and-self.stderr

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ warning: variant is never constructed: `B`
44
LL | B,
55
| ^ help: if this is intentional, prefix it with an underscore: `_B`
66
|
7-
= note: the leading underscore signals that this variant serves some other purpose
8-
even if it isn't used in a way that we can detect.
7+
= note: the leading underscore signals that this variant serves some other purpose even if it isn't used in a way that we can detect.
98
note: the lint level is defined here
109
--> $DIR/const-and-self.rs:3:9
1110
|
@@ -18,8 +17,7 @@ warning: variant is never constructed: `C`
1817
LL | C,
1918
| ^ help: if this is intentional, prefix it with an underscore: `_C`
2019
|
21-
= note: the leading underscore signals that this variant serves some other purpose
22-
even if it isn't used in a way that we can detect.
20+
= note: the leading underscore signals that this variant serves some other purpose even if it isn't used in a way that we can detect.
2321

2422
warning: 2 warnings emitted
2523

src/test/ui/lint/dead-code/drop-only-field-issue-81658.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ error: field is never read: `guard`
22
--> $DIR/drop-only-field-issue-81658.rs:15:5
33
|
44
LL | guard: MutexGuard<'a, T>,
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_guard`
5+
| -----^^^^^^^^^^^^^^^^^^^
6+
| |
7+
| help: if this is intentional, prefix it with an underscore: `_guard`
68
|
7-
= note: the leading underscore signals that this field serves some other purpose
8-
even if it isn't used in a way that we can detect. (e.g. for its effect
9-
when dropped or in foreign code)
9+
= note: the leading underscore signals that this field serves some other purpose even if it isn't used in a way that we can detect. (e.g. for its effect when dropped or in foreign code)
1010
note: the lint level is defined here
1111
--> $DIR/drop-only-field-issue-81658.rs:8:9
1212
|

src/test/ui/lint/dead-code/empty-unused-enum.stderr

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ error: enum is never used: `E`
44
LL | enum E {}
55
| ^ help: if this is intentional, prefix it with an underscore: `_E`
66
|
7-
= note: the leading underscore signals that this enum serves some other purpose
8-
even if it isn't used in a way that we can detect.
7+
= note: the leading underscore signals that this enum serves some other purpose even if it isn't used in a way that we can detect.
98
note: the lint level is defined here
109
--> $DIR/empty-unused-enum.rs:1:9
1110
|

src/test/ui/lint/dead-code/field-used-in-ffi-issue-81658.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ error: field is never read: `items`
22
--> $DIR/field-used-in-ffi-issue-81658.rs:13:5
33
|
44
LL | items: Option<Vec<T>>,
5-
| ^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_items`
5+
| -----^^^^^^^^^^^^^^^^
6+
| |
7+
| help: if this is intentional, prefix it with an underscore: `_items`
68
|
7-
= note: the leading underscore signals that this field serves some other purpose
8-
even if it isn't used in a way that we can detect. (e.g. for its effect
9-
when dropped or in foreign code)
9+
= note: the leading underscore signals that this field serves some other purpose even if it isn't used in a way that we can detect. (e.g. for its effect when dropped or in foreign code)
1010
note: the lint level is defined here
1111
--> $DIR/field-used-in-ffi-issue-81658.rs:7:9
1212
|

src/test/ui/lint/dead-code/impl-trait.stderr

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ error: type alias is never used: `Unused`
22
--> $DIR/impl-trait.rs:12:1
33
|
44
LL | type Unused = ();
5-
| ^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_Unused`
5+
| ^^^^^------^^^^^^
6+
| |
7+
| help: if this is intentional, prefix it with an underscore: `_Unused`
68
|
7-
= note: the leading underscore signals that this type alias serves some other purpose
8-
even if it isn't used in a way that we can detect.
9+
= note: the leading underscore signals that this type alias serves some other purpose even if it isn't used in a way that we can detect.
910
note: the lint level is defined here
1011
--> $DIR/impl-trait.rs:1:9
1112
|

0 commit comments

Comments
 (0)