Skip to content

Commit 33f31eb

Browse files
committed
Putting help message only under the identifier that needs to be prefixed
1 parent 0fb9c23 commit 33f31eb

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
@@ -589,7 +589,7 @@ impl DeadVisitor<'tcx> {
589589
&mut self,
590590
id: hir::HirId,
591591
span: rustc_span::Span,
592-
name: Symbol,
592+
name: Ident,
593593
participle: &str,
594594
extra_note: Option<ExtraNote>,
595595
) {
@@ -598,7 +598,7 @@ impl DeadVisitor<'tcx> {
598598
let def_id = self.tcx.hir().local_def_id(id);
599599
let descr = self.tcx.def_kind(def_id).descr(def_id.to_def_id());
600600

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

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

612612
let mut note = format!(
613613
"the leading underscore signals that this {} serves some other \
614-
purpose\neven if it isn't used in a way that we can detect.",
614+
purpose even if it isn't used in a way that we can detect.",
615615
descr,
616616
);
617617
if matches!(extra_note, Some(ExtraNote::OtherPurposeExamples)) {
618-
note += " (e.g. for its effect\nwhen dropped or in foreign code)";
618+
note += " (e.g. for its effect when dropped or in foreign code)";
619619
}
620620

621621
diag.note(&note);
@@ -670,7 +670,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
670670
hir::ItemKind::Struct(..) => "constructed", // Issue #52325
671671
_ => "used",
672672
};
673-
self.warn_dead_code(item.hir_id(), span, item.ident.name, participle, None);
673+
self.warn_dead_code(item.hir_id(), span, item.ident, participle, None);
674674
} else {
675675
// Only continue if we didn't warn
676676
intravisit::walk_item(self, item);
@@ -684,15 +684,15 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
684684
id: hir::HirId,
685685
) {
686686
if self.should_warn_about_variant(&variant) {
687-
self.warn_dead_code(variant.id, variant.span, variant.ident.name, "constructed", None);
687+
self.warn_dead_code(variant.id, variant.span, variant.ident, "constructed", None);
688688
} else {
689689
intravisit::walk_variant(self, variant, g, id);
690690
}
691691
}
692692

693693
fn visit_foreign_item(&mut self, fi: &'tcx hir::ForeignItem<'tcx>) {
694694
if self.should_warn_about_foreign_item(fi) {
695-
self.warn_dead_code(fi.hir_id(), fi.span, fi.ident.name, "used", None);
695+
self.warn_dead_code(fi.hir_id(), fi.span, fi.ident, "used", None);
696696
}
697697
intravisit::walk_foreign_item(self, fi);
698698
}
@@ -702,7 +702,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
702702
self.warn_dead_code(
703703
field.hir_id,
704704
field.span,
705-
field.ident.name,
705+
field.ident,
706706
"read",
707707
Some(ExtraNote::OtherPurposeExamples),
708708
);
@@ -717,7 +717,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
717717
self.warn_dead_code(
718718
impl_item.hir_id(),
719719
impl_item.span,
720-
impl_item.ident.name,
720+
impl_item.ident,
721721
"used",
722722
None,
723723
);
@@ -737,13 +737,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> {
737737
} else {
738738
impl_item.ident.span
739739
};
740-
self.warn_dead_code(
741-
impl_item.hir_id(),
742-
span,
743-
impl_item.ident.name,
744-
"used",
745-
None,
746-
);
740+
self.warn_dead_code(impl_item.hir_id(), span, impl_item.ident, "used", None);
747741
}
748742
self.visit_nested_body(body_id)
749743
}

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)