Skip to content

Commit 789186d

Browse files
committed
Trying out a new message that works a little better for values *and* items
1 parent 7faaf39 commit 789186d

29 files changed

+301
-226
lines changed

compiler/rustc_passes/src/dead.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -589,10 +589,11 @@ impl DeadVisitor<'tcx> {
589589
Applicability::MachineApplicable,
590590
)
591591
.note(&format!(
592-
"the leading underscore helps signal to the reader that the {} may still serve\n\
593-
a purpose even if it isn't used in a way that we can detect (e.g. the {}\nis \
594-
only used through FFI or used only for its effect when dropped)",
595-
descr, descr,
592+
"The leading underscore signals to the reader that while the {} may not be {}\n\
593+
by any Rust code, it still serves some other purpose that isn't detected by rustc.\n\
594+
(e.g. some values are used for their effect when dropped or used in FFI code\n\
595+
exclusively through raw pointers)",
596+
descr, participle,
596597
));
597598
// Force the note we added to the front, before any other subdiagnostics
598599
diag.children.rotate_right(1);

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ error: associated constant is never used: `BAR`
44
LL | const BAR: u32 = 1;
55
| ^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_BAR`
66
|
7-
= note: the leading underscore helps signal to the reader that the associated constant may still serve
8-
a purpose even if it isn't used in a way that we can detect (e.g. the associated constant
9-
is only used through FFI or used only for its effect when dropped)
7+
= note: The leading underscore signals to the reader that while the associated constant may not be used
8+
by any Rust code, it still serves some other purpose that isn't detected by rustc.
9+
(e.g. some values are used for their effect when dropped or used in FFI code
10+
exclusively through raw pointers)
1011
note: the lint level is defined here
1112
--> $DIR/associated-const-dead-code.rs:1:9
1213
|

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ warning: variant is never constructed: `Void`
44
LL | Void(Void),
55
| ^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_Void`
66
|
7-
= note: the leading underscore helps signal to the reader that the variant may still serve
8-
a purpose even if it isn't used in a way that we can detect (e.g. the variant
9-
is only used through FFI or used only for its effect when dropped)
7+
= note: The leading underscore signals to the reader that while the variant may not be constructed
8+
by any Rust code, it still serves some other purpose that isn't detected by rustc.
9+
(e.g. some values are used for their effect when dropped or used in FFI code
10+
exclusively through raw pointers)
1011
= note: `-W dead-code` implied by `-W unused`
1112

1213
warning: 1 warning emitted

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ warning: type alias is never used: `Z`
44
LL | type Z = dyn for<'x> Send;
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_Z`
66
|
7-
= note: the leading underscore helps signal to the reader that the type alias may still serve
8-
a purpose even if it isn't used in a way that we can detect (e.g. the type alias
9-
is only used through FFI or used only for its effect when dropped)
7+
= note: The leading underscore signals to the reader that while the type alias may not be used
8+
by any Rust code, it still serves some other purpose that isn't detected by rustc.
9+
(e.g. some values are used for their effect when dropped or used in FFI code
10+
exclusively through raw pointers)
1011
note: the lint level is defined here
1112
--> $DIR/issue-37515.rs:3:9
1213
|

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ 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 helps signal to the reader that the function may still serve
8-
a purpose even if it isn't used in a way that we can detect (e.g. the function
9-
is only used through FFI or used only for its effect when dropped)
7+
= note: The leading underscore signals to the reader that while the function may not be used
8+
by any Rust code, it still serves some other purpose that isn't detected by rustc.
9+
(e.g. some values are used for their effect when dropped or used in FFI code
10+
exclusively through raw pointers)
1011
note: the lint level is defined here
1112
--> $DIR/basic.rs:1:9
1213
|

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

+8-6
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ 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 helps signal to the reader that the variant may still serve
8-
a purpose even if it isn't used in a way that we can detect (e.g. the variant
9-
is only used through FFI or used only for its effect when dropped)
7+
= note: The leading underscore signals to the reader that while the variant may not be constructed
8+
by any Rust code, it still serves some other purpose that isn't detected by rustc.
9+
(e.g. some values are used for their effect when dropped or used in FFI code
10+
exclusively through raw pointers)
1011
note: the lint level is defined here
1112
--> $DIR/const-and-self.rs:3:9
1213
|
@@ -19,9 +20,10 @@ warning: variant is never constructed: `C`
1920
LL | C,
2021
| ^ help: if this is intentional, prefix it with an underscore: `_C`
2122
|
22-
= note: the leading underscore helps signal to the reader that the variant may still serve
23-
a purpose even if it isn't used in a way that we can detect (e.g. the variant
24-
is only used through FFI or used only for its effect when dropped)
23+
= note: The leading underscore signals to the reader that while the variant may not be constructed
24+
by any Rust code, it still serves some other purpose that isn't detected by rustc.
25+
(e.g. some values are used for their effect when dropped or used in FFI code
26+
exclusively through raw pointers)
2527

2628
warning: 2 warnings emitted
2729

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ error: field is never read: `guard`
44
LL | guard: MutexGuard<'a, T>,
55
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_guard`
66
|
7-
= note: the leading underscore helps signal to the reader that the field may still serve
8-
a purpose even if it isn't used in a way that we can detect (e.g. the field
9-
is only used through FFI or used only for its effect when dropped)
7+
= note: The leading underscore signals to the reader that while the field may not be read
8+
by any Rust code, it still serves some other purpose that isn't detected by rustc.
9+
(e.g. some values are used for their effect when dropped or used in FFI code
10+
exclusively through raw pointers)
1011
note: the lint level is defined here
1112
--> $DIR/drop-only-field-issue-81658.rs:8:9
1213
|

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ 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 helps signal to the reader that the enum may still serve
8-
a purpose even if it isn't used in a way that we can detect (e.g. the enum
9-
is only used through FFI or used only for its effect when dropped)
7+
= note: The leading underscore signals to the reader that while the enum may not be used
8+
by any Rust code, it still serves some other purpose that isn't detected by rustc.
9+
(e.g. some values are used for their effect when dropped or used in FFI code
10+
exclusively through raw pointers)
1011
note: the lint level is defined here
1112
--> $DIR/empty-unused-enum.rs:1:9
1213
|

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ error: field is never read: `items`
44
LL | items: Option<Vec<T>>,
55
| ^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_items`
66
|
7-
= note: the leading underscore helps signal to the reader that the field may still serve
8-
a purpose even if it isn't used in a way that we can detect (e.g. the field
9-
is only used through FFI or used only for its effect when dropped)
7+
= note: The leading underscore signals to the reader that while the field may not be read
8+
by any Rust code, it still serves some other purpose that isn't detected by rustc.
9+
(e.g. some values are used for their effect when dropped or used in FFI code
10+
exclusively through raw pointers)
1011
note: the lint level is defined here
1112
--> $DIR/field-used-in-ffi-issue-81658.rs:7:9
1213
|

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ error: type alias is never used: `Unused`
44
LL | type Unused = ();
55
| ^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_Unused`
66
|
7-
= note: the leading underscore helps signal to the reader that the type alias may still serve
8-
a purpose even if it isn't used in a way that we can detect (e.g. the type alias
9-
is only used through FFI or used only for its effect when dropped)
7+
= note: The leading underscore signals to the reader that while the type alias may not be used
8+
by any Rust code, it still serves some other purpose that isn't detected by rustc.
9+
(e.g. some values are used for their effect when dropped or used in FFI code
10+
exclusively through raw pointers)
1011
note: the lint level is defined here
1112
--> $DIR/impl-trait.rs:1:9
1213
|

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

+40-30
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ error: struct is never constructed: `Bar`
44
LL | pub struct Bar;
55
| ^^^ help: if this is intentional, prefix it with an underscore: `_Bar`
66
|
7-
= note: the leading underscore helps signal to the reader that the struct may still serve
8-
a purpose even if it isn't used in a way that we can detect (e.g. the struct
9-
is only used through FFI or used only for its effect when dropped)
7+
= note: The leading underscore signals to the reader that while the struct may not be constructed
8+
by any Rust code, it still serves some other purpose that isn't detected by rustc.
9+
(e.g. some values are used for their effect when dropped or used in FFI code
10+
exclusively through raw pointers)
1011
note: the lint level is defined here
1112
--> $DIR/lint-dead-code-1.rs:5:9
1213
|
@@ -19,89 +20,98 @@ error: static is never used: `priv_static`
1920
LL | static priv_static: isize = 0;
2021
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_priv_static`
2122
|
22-
= note: the leading underscore helps signal to the reader that the static may still serve
23-
a purpose even if it isn't used in a way that we can detect (e.g. the static
24-
is only used through FFI or used only for its effect when dropped)
23+
= note: The leading underscore signals to the reader that while the static may not be used
24+
by any Rust code, it still serves some other purpose that isn't detected by rustc.
25+
(e.g. some values are used for their effect when dropped or used in FFI code
26+
exclusively through raw pointers)
2527

2628
error: constant is never used: `priv_const`
2729
--> $DIR/lint-dead-code-1.rs:27:1
2830
|
2931
LL | const priv_const: isize = 0;
3032
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_priv_const`
3133
|
32-
= note: the leading underscore helps signal to the reader that the constant may still serve
33-
a purpose even if it isn't used in a way that we can detect (e.g. the constant
34-
is only used through FFI or used only for its effect when dropped)
34+
= note: The leading underscore signals to the reader that while the constant may not be used
35+
by any Rust code, it still serves some other purpose that isn't detected by rustc.
36+
(e.g. some values are used for their effect when dropped or used in FFI code
37+
exclusively through raw pointers)
3538

3639
error: struct is never constructed: `PrivStruct`
3740
--> $DIR/lint-dead-code-1.rs:35:8
3841
|
3942
LL | struct PrivStruct;
4043
| ^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_PrivStruct`
4144
|
42-
= note: the leading underscore helps signal to the reader that the struct may still serve
43-
a purpose even if it isn't used in a way that we can detect (e.g. the struct
44-
is only used through FFI or used only for its effect when dropped)
45+
= note: The leading underscore signals to the reader that while the struct may not be constructed
46+
by any Rust code, it still serves some other purpose that isn't detected by rustc.
47+
(e.g. some values are used for their effect when dropped or used in FFI code
48+
exclusively through raw pointers)
4549

4650
error: enum is never used: `priv_enum`
4751
--> $DIR/lint-dead-code-1.rs:64:6
4852
|
4953
LL | enum priv_enum { foo2, bar2 }
5054
| ^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_priv_enum`
5155
|
52-
= note: the leading underscore helps signal to the reader that the enum may still serve
53-
a purpose even if it isn't used in a way that we can detect (e.g. the enum
54-
is only used through FFI or used only for its effect when dropped)
56+
= note: The leading underscore signals to the reader that while the enum may not be used
57+
by any Rust code, it still serves some other purpose that isn't detected by rustc.
58+
(e.g. some values are used for their effect when dropped or used in FFI code
59+
exclusively through raw pointers)
5560

5661
error: variant is never constructed: `bar3`
5762
--> $DIR/lint-dead-code-1.rs:67:5
5863
|
5964
LL | bar3
6065
| ^^^^ help: if this is intentional, prefix it with an underscore: `_bar3`
6166
|
62-
= note: the leading underscore helps signal to the reader that the variant may still serve
63-
a purpose even if it isn't used in a way that we can detect (e.g. the variant
64-
is only used through FFI or used only for its effect when dropped)
67+
= note: The leading underscore signals to the reader that while the variant may not be constructed
68+
by any Rust code, it still serves some other purpose that isn't detected by rustc.
69+
(e.g. some values are used for their effect when dropped or used in FFI code
70+
exclusively through raw pointers)
6571

6672
error: function is never used: `priv_fn`
6773
--> $DIR/lint-dead-code-1.rs:88:4
6874
|
6975
LL | fn priv_fn() {
7076
| ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_priv_fn`
7177
|
72-
= note: the leading underscore helps signal to the reader that the function may still serve
73-
a purpose even if it isn't used in a way that we can detect (e.g. the function
74-
is only used through FFI or used only for its effect when dropped)
78+
= note: The leading underscore signals to the reader that while the function may not be used
79+
by any Rust code, it still serves some other purpose that isn't detected by rustc.
80+
(e.g. some values are used for their effect when dropped or used in FFI code
81+
exclusively through raw pointers)
7582

7683
error: function is never used: `foo`
7784
--> $DIR/lint-dead-code-1.rs:93:4
7885
|
7986
LL | fn foo() {
8087
| ^^^ help: if this is intentional, prefix it with an underscore: `_foo`
8188
|
82-
= note: the leading underscore helps signal to the reader that the function may still serve
83-
a purpose even if it isn't used in a way that we can detect (e.g. the function
84-
is only used through FFI or used only for its effect when dropped)
89+
= note: The leading underscore signals to the reader that while the function may not be used
90+
by any Rust code, it still serves some other purpose that isn't detected by rustc.
91+
(e.g. some values are used for their effect when dropped or used in FFI code
92+
exclusively through raw pointers)
8593

8694
error: function is never used: `bar`
8795
--> $DIR/lint-dead-code-1.rs:98:4
8896
|
8997
LL | fn bar() {
9098
| ^^^ help: if this is intentional, prefix it with an underscore: `_bar`
9199
|
92-
= note: the leading underscore helps signal to the reader that the function may still serve
93-
a purpose even if it isn't used in a way that we can detect (e.g. the function
94-
is only used through FFI or used only for its effect when dropped)
100+
= note: The leading underscore signals to the reader that while the function may not be used
101+
by any Rust code, it still serves some other purpose that isn't detected by rustc.
102+
(e.g. some values are used for their effect when dropped or used in FFI code
103+
exclusively through raw pointers)
95104

96105
error: function is never used: `baz`
97106
--> $DIR/lint-dead-code-1.rs:102:4
98107
|
99108
LL | fn baz() -> impl Copy {
100109
| ^^^ help: if this is intentional, prefix it with an underscore: `_baz`
101110
|
102-
= note: the leading underscore helps signal to the reader that the function may still serve
103-
a purpose even if it isn't used in a way that we can detect (e.g. the function
104-
is only used through FFI or used only for its effect when dropped)
111+
= note: The leading underscore signals to the reader that while the function may not be used
112+
by any Rust code, it still serves some other purpose that isn't detected by rustc.
113+
(e.g. some values are used for their effect when dropped or used in FFI code
114+
exclusively through raw pointers)
105115

106116
error: aborting due to 10 previous errors
107117

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

+12-9
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ error: function is never used: `dead_fn`
44
LL | fn dead_fn() {}
55
| ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_dead_fn`
66
|
7-
= note: the leading underscore helps signal to the reader that the function may still serve
8-
a purpose even if it isn't used in a way that we can detect (e.g. the function
9-
is only used through FFI or used only for its effect when dropped)
7+
= note: The leading underscore signals to the reader that while the function may not be used
8+
by any Rust code, it still serves some other purpose that isn't detected by rustc.
9+
(e.g. some values are used for their effect when dropped or used in FFI code
10+
exclusively through raw pointers)
1011
note: the lint level is defined here
1112
--> $DIR/lint-dead-code-2.rs:2:9
1213
|
@@ -19,19 +20,21 @@ error: function is never used: `dead_fn2`
1920
LL | fn dead_fn2() {}
2021
| ^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_dead_fn2`
2122
|
22-
= note: the leading underscore helps signal to the reader that the function may still serve
23-
a purpose even if it isn't used in a way that we can detect (e.g. the function
24-
is only used through FFI or used only for its effect when dropped)
23+
= note: The leading underscore signals to the reader that while the function may not be used
24+
by any Rust code, it still serves some other purpose that isn't detected by rustc.
25+
(e.g. some values are used for their effect when dropped or used in FFI code
26+
exclusively through raw pointers)
2527

2628
error: function is never used: `main`
2729
--> $DIR/lint-dead-code-2.rs:38:4
2830
|
2931
LL | fn main() {
3032
| ^^^^ help: if this is intentional, prefix it with an underscore: `_main`
3133
|
32-
= note: the leading underscore helps signal to the reader that the function may still serve
33-
a purpose even if it isn't used in a way that we can detect (e.g. the function
34-
is only used through FFI or used only for its effect when dropped)
34+
= note: The leading underscore signals to the reader that while the function may not be used
35+
by any Rust code, it still serves some other purpose that isn't detected by rustc.
36+
(e.g. some values are used for their effect when dropped or used in FFI code
37+
exclusively through raw pointers)
3538

3639
error: aborting due to 3 previous errors
3740

0 commit comments

Comments
 (0)