Skip to content

Commit 1bb0c92

Browse files
authored
Rollup merge of #70300 - aleksator:66636_reword_unused_variable_warning, r=Dylan-DPC
Reword unused variable warning Fixes #66636
2 parents 8cb3daa + b35c302 commit 1bb0c92

22 files changed

+69
-69
lines changed

src/doc/rustc/src/json.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ Diagnostics have the following format:
168168
"rendered": null
169169
},
170170
{
171-
"message": "consider prefixing with an underscore",
171+
"message": "if this is intentional, prefix it with an underscore",
172172
"code": null,
173173
"level": "help",
174174
"spans": [
@@ -201,7 +201,7 @@ Diagnostics have the following format:
201201
/* Optional string of the rendered version of the diagnostic as displayed
202202
by rustc. Note that this may be influenced by the `--json` flag.
203203
*/
204-
"rendered": "warning: unused variable: `x`\n --> lib.rs:2:9\n |\n2 | let x = 123;\n | ^ help: consider prefixing with an underscore: `_x`\n |\n = note: `#[warn(unused_variables)]` on by default\n\n"
204+
"rendered": "warning: unused variable: `x`\n --> lib.rs:2:9\n |\n2 | let x = 123;\n | ^ help: if this is intentional, prefix it with an underscore: `_x`\n |\n = note: `#[warn(unused_variables)]` on by default\n\n"
205205
}
206206
```
207207

src/librustc_passes/liveness.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1565,7 +1565,7 @@ impl<'tcx> Liveness<'_, 'tcx> {
15651565
}
15661566
} else {
15671567
err.multipart_suggestion(
1568-
"consider prefixing with an underscore",
1568+
"if this is intentional, prefix it with an underscore",
15691569
spans.iter().map(|span| (*span, format!("_{}", name))).collect(),
15701570
Applicability::MachineApplicable,
15711571
);

src/test/ui/const-generics/issues/issue-62187-encountered-polymorphic-const.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ warning: unused variable: `foo`
1010
--> $DIR/issue-62187-encountered-polymorphic-const.rs:15:9
1111
|
1212
LL | let foo = <[u8; 2]>::BIT_LEN;
13-
| ^^^ help: consider prefixing with an underscore: `_foo`
13+
| ^^^ help: if this is intentional, prefix it with an underscore: `_foo`
1414
|
1515
= note: `#[warn(unused_variables)]` on by default
1616

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: unused variable: `x`
22
--> $DIR/issue-17999.rs:5:13
33
|
44
LL | let x = ();
5-
| ^ help: consider prefixing with an underscore: `_x`
5+
| ^ help: if this is intentional, prefix it with an underscore: `_x`
66
|
77
note: the lint level is defined here
88
--> $DIR/issue-17999.rs:1:9
@@ -14,7 +14,7 @@ error: unused variable: `a`
1414
--> $DIR/issue-17999.rs:7:13
1515
|
1616
LL | a => {}
17-
| ^ help: consider prefixing with an underscore: `_a`
17+
| ^ help: if this is intentional, prefix it with an underscore: `_a`
1818

1919
error: aborting due to 2 previous errors
2020

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: unused variable: `a`
22
--> $DIR/issue-22599.rs:8:19
33
|
44
LL | v = match 0 { a => 0 };
5-
| ^ help: consider prefixing with an underscore: `_a`
5+
| ^ help: if this is intentional, prefix it with an underscore: `_a`
66
|
77
note: the lint level is defined here
88
--> $DIR/issue-22599.rs:1:9

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ note: the lint level is defined here
99
|
1010
LL | #![deny(unused_variables)]
1111
| ^^^^^^^^^^^^^^^^
12-
help: consider prefixing with an underscore
12+
help: if this is intentional, prefix it with an underscore
1313
|
1414
LL | E::A(_x) | E::B(_x) => {}
1515
| ^^ ^^
@@ -20,7 +20,7 @@ error: unused variable: `x`
2020
LL | F::A(x, y) | F::B(x, y) => { y },
2121
| ^ ^
2222
|
23-
help: consider prefixing with an underscore
23+
help: if this is intentional, prefix it with an underscore
2424
|
2525
LL | F::A(_x, y) | F::B(_x, y) => { y },
2626
| ^^ ^^
@@ -29,21 +29,21 @@ error: unused variable: `a`
2929
--> $DIR/issue-56685.rs:27:14
3030
|
3131
LL | F::C(a, b) => { 3 }
32-
| ^ help: consider prefixing with an underscore: `_a`
32+
| ^ help: if this is intentional, prefix it with an underscore: `_a`
3333

3434
error: unused variable: `b`
3535
--> $DIR/issue-56685.rs:27:17
3636
|
3737
LL | F::C(a, b) => { 3 }
38-
| ^ help: consider prefixing with an underscore: `_b`
38+
| ^ help: if this is intentional, prefix it with an underscore: `_b`
3939

4040
error: unused variable: `x`
4141
--> $DIR/issue-56685.rs:32:25
4242
|
4343
LL | let _ = if let F::A(x, y) | F::B(x, y) = F::A(1, 2) {
4444
| ^ ^
4545
|
46-
help: consider prefixing with an underscore
46+
help: if this is intentional, prefix it with an underscore
4747
|
4848
LL | let _ = if let F::A(_x, y) | F::B(_x, y) = F::A(1, 2) {
4949
| ^^ ^^
@@ -54,7 +54,7 @@ error: unused variable: `x`
5454
LL | while let F::A(x, y) | F::B(x, y) = F::A(1, 2) {
5555
| ^ ^
5656
|
57-
help: consider prefixing with an underscore
57+
help: if this is intentional, prefix it with an underscore
5858
|
5959
LL | while let F::A(_x, y) | F::B(_x, y) = F::A(1, 2) {
6060
| ^^ ^^

src/test/ui/lint/issue-47390-unused-variable-in-struct-pattern.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ warning: unused variable: `i_think_continually`
22
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:26:9
33
|
44
LL | let i_think_continually = 2;
5-
| ^^^^^^^^^^^^^^^^^^^ help: consider prefixing with an underscore: `_i_think_continually`
5+
| ^^^^^^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_i_think_continually`
66
|
77
note: the lint level is defined here
88
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:5:9
@@ -15,19 +15,19 @@ warning: unused variable: `mut_unused_var`
1515
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:33:13
1616
|
1717
LL | let mut mut_unused_var = 1;
18-
| ^^^^^^^^^^^^^^ help: consider prefixing with an underscore: `_mut_unused_var`
18+
| ^^^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_mut_unused_var`
1919

2020
warning: unused variable: `var`
2121
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:37:14
2222
|
2323
LL | let (mut var, unused_var) = (1, 2);
24-
| ^^^ help: consider prefixing with an underscore: `_var`
24+
| ^^^ help: if this is intentional, prefix it with an underscore: `_var`
2525

2626
warning: unused variable: `unused_var`
2727
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:37:19
2828
|
2929
LL | let (mut var, unused_var) = (1, 2);
30-
| ^^^^^^^^^^ help: consider prefixing with an underscore: `_unused_var`
30+
| ^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused_var`
3131

3232
warning: unused variable: `corridors_of_light`
3333
--> $DIR/issue-47390-unused-variable-in-struct-pattern.rs:45:26

src/test/ui/lint/lint-match-arms.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: unused variable: `y`
22
--> $DIR/lint-match-arms.rs:5:9
33
|
44
LL | y => (),
5-
| ^ help: consider prefixing with an underscore: `_y`
5+
| ^ help: if this is intentional, prefix it with an underscore: `_y`
66
|
77
note: the lint level is defined here
88
--> $DIR/lint-match-arms.rs:3:16

src/test/ui/lint/lint-removed-allow.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: unused variable: `unused`
22
--> $DIR/lint-removed-allow.rs:8:17
33
|
44
LL | fn main() { let unused = (); }
5-
| ^^^^^^ help: consider prefixing with an underscore: `_unused`
5+
| ^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused`
66
|
77
note: the lint level is defined here
88
--> $DIR/lint-removed-allow.rs:7:8

src/test/ui/lint/lint-removed-cmdline.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ error: unused variable: `unused`
1818
--> $DIR/lint-removed-cmdline.rs:12:17
1919
|
2020
LL | fn main() { let unused = (); }
21-
| ^^^^^^ help: consider prefixing with an underscore: `_unused`
21+
| ^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused`
2222
|
2323
note: the lint level is defined here
2424
--> $DIR/lint-removed-cmdline.rs:11:8

src/test/ui/lint/lint-removed.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ error: unused variable: `unused`
1010
--> $DIR/lint-removed.rs:8:17
1111
|
1212
LL | fn main() { let unused = (); }
13-
| ^^^^^^ help: consider prefixing with an underscore: `_unused`
13+
| ^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused`
1414
|
1515
note: the lint level is defined here
1616
--> $DIR/lint-removed.rs:7:8

src/test/ui/lint/lint-renamed-allow.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: unused variable: `unused`
22
--> $DIR/lint-renamed-allow.rs:8:17
33
|
44
LL | fn main() { let unused = (); }
5-
| ^^^^^^ help: consider prefixing with an underscore: `_unused`
5+
| ^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused`
66
|
77
note: the lint level is defined here
88
--> $DIR/lint-renamed-allow.rs:7:8

src/test/ui/lint/lint-renamed-cmdline.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ error: unused variable: `unused`
1818
--> $DIR/lint-renamed-cmdline.rs:8:17
1919
|
2020
LL | fn main() { let unused = (); }
21-
| ^^^^^^ help: consider prefixing with an underscore: `_unused`
21+
| ^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused`
2222
|
2323
note: the lint level is defined here
2424
--> $DIR/lint-renamed-cmdline.rs:7:8

src/test/ui/lint/lint-renamed.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ error: unused variable: `unused`
1010
--> $DIR/lint-renamed.rs:4:17
1111
|
1212
LL | fn main() { let unused = (); }
13-
| ^^^^^^ help: consider prefixing with an underscore: `_unused`
13+
| ^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused`
1414
|
1515
note: the lint level is defined here
1616
--> $DIR/lint-renamed.rs:3:8

src/test/ui/lint/lint-unused-variables.stderr

+11-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: unused variable: `a`
22
--> $DIR/lint-unused-variables.rs:8:5
33
|
44
LL | a: i32,
5-
| ^ help: consider prefixing with an underscore: `_a`
5+
| ^ help: if this is intentional, prefix it with an underscore: `_a`
66
|
77
note: the lint level is defined here
88
--> $DIR/lint-unused-variables.rs:5:9
@@ -14,61 +14,61 @@ error: unused variable: `b`
1414
--> $DIR/lint-unused-variables.rs:14:5
1515
|
1616
LL | b: i32,
17-
| ^ help: consider prefixing with an underscore: `_b`
17+
| ^ help: if this is intentional, prefix it with an underscore: `_b`
1818

1919
error: unused variable: `a`
2020
--> $DIR/lint-unused-variables.rs:68:9
2121
|
2222
LL | a: i32,
23-
| ^ help: consider prefixing with an underscore: `_a`
23+
| ^ help: if this is intentional, prefix it with an underscore: `_a`
2424

2525
error: unused variable: `b`
2626
--> $DIR/lint-unused-variables.rs:74:9
2727
|
2828
LL | b: i32,
29-
| ^ help: consider prefixing with an underscore: `_b`
29+
| ^ help: if this is intentional, prefix it with an underscore: `_b`
3030

3131
error: unused variable: `b`
3232
--> $DIR/lint-unused-variables.rs:42:9
3333
|
3434
LL | b: i32,
35-
| ^ help: consider prefixing with an underscore: `_b`
35+
| ^ help: if this is intentional, prefix it with an underscore: `_b`
3636

3737
error: unused variable: `b`
3838
--> $DIR/lint-unused-variables.rs:47:9
3939
|
4040
LL | b: i32,
41-
| ^ help: consider prefixing with an underscore: `_b`
41+
| ^ help: if this is intentional, prefix it with an underscore: `_b`
4242

4343
error: unused variable: `a`
4444
--> $DIR/lint-unused-variables.rs:22:9
4545
|
4646
LL | a: i32,
47-
| ^ help: consider prefixing with an underscore: `_a`
47+
| ^ help: if this is intentional, prefix it with an underscore: `_a`
4848

4949
error: unused variable: `b`
5050
--> $DIR/lint-unused-variables.rs:29:9
5151
|
5252
LL | b: i32,
53-
| ^ help: consider prefixing with an underscore: `_b`
53+
| ^ help: if this is intentional, prefix it with an underscore: `_b`
5454

5555
error: unused variable: `b`
5656
--> $DIR/lint-unused-variables.rs:34:9
5757
|
5858
LL | b: i32,
59-
| ^ help: consider prefixing with an underscore: `_b`
59+
| ^ help: if this is intentional, prefix it with an underscore: `_b`
6060

6161
error: unused variable: `b`
6262
--> $DIR/lint-unused-variables.rs:55:9
6363
|
6464
LL | b: i32,
65-
| ^ help: consider prefixing with an underscore: `_b`
65+
| ^ help: if this is intentional, prefix it with an underscore: `_b`
6666

6767
error: unused variable: `b`
6868
--> $DIR/lint-unused-variables.rs:60:9
6969
|
7070
LL | b: i32,
71-
| ^ help: consider prefixing with an underscore: `_b`
71+
| ^ help: if this is intentional, prefix it with an underscore: `_b`
7272

7373
error: aborting due to 11 previous errors
7474

src/test/ui/lint/lint-uppercase-variables.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ warning: unused variable: `Foo`
2222
--> $DIR/lint-uppercase-variables.rs:22:9
2323
|
2424
LL | Foo => {}
25-
| ^^^ help: consider prefixing with an underscore: `_Foo`
25+
| ^^^ help: if this is intentional, prefix it with an underscore: `_Foo`
2626
|
2727
note: the lint level is defined here
2828
--> $DIR/lint-uppercase-variables.rs:1:9
@@ -35,13 +35,13 @@ warning: unused variable: `Foo`
3535
--> $DIR/lint-uppercase-variables.rs:28:9
3636
|
3737
LL | let Foo = foo::Foo::Foo;
38-
| ^^^ help: consider prefixing with an underscore: `_Foo`
38+
| ^^^ help: if this is intentional, prefix it with an underscore: `_Foo`
3939

4040
warning: unused variable: `Foo`
4141
--> $DIR/lint-uppercase-variables.rs:33:17
4242
|
4343
LL | fn in_param(Foo: foo::Foo) {}
44-
| ^^^ help: consider prefixing with an underscore: `_Foo`
44+
| ^^^ help: if this is intentional, prefix it with an underscore: `_Foo`
4545

4646
error: structure field `X` should have a snake case name
4747
--> $DIR/lint-uppercase-variables.rs:10:5

src/test/ui/liveness/liveness-unused.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ error: unused variable: `x`
1717
--> $DIR/liveness-unused.rs:8:7
1818
|
1919
LL | fn f1(x: isize) {
20-
| ^ help: consider prefixing with an underscore: `_x`
20+
| ^ help: if this is intentional, prefix it with an underscore: `_x`
2121
|
2222
note: the lint level is defined here
2323
--> $DIR/liveness-unused.rs:2:9
@@ -29,19 +29,19 @@ error: unused variable: `x`
2929
--> $DIR/liveness-unused.rs:12:8
3030
|
3131
LL | fn f1b(x: &mut isize) {
32-
| ^ help: consider prefixing with an underscore: `_x`
32+
| ^ help: if this is intentional, prefix it with an underscore: `_x`
3333

3434
error: unused variable: `x`
3535
--> $DIR/liveness-unused.rs:20:9
3636
|
3737
LL | let x: isize;
38-
| ^ help: consider prefixing with an underscore: `_x`
38+
| ^ help: if this is intentional, prefix it with an underscore: `_x`
3939

4040
error: unused variable: `x`
4141
--> $DIR/liveness-unused.rs:25:9
4242
|
4343
LL | let x = 3;
44-
| ^ help: consider prefixing with an underscore: `_x`
44+
| ^ help: if this is intentional, prefix it with an underscore: `_x`
4545

4646
error: variable `x` is assigned to, but never used
4747
--> $DIR/liveness-unused.rs:30:13
@@ -76,25 +76,25 @@ error: unused variable: `i`
7676
--> $DIR/liveness-unused.rs:59:12
7777
|
7878
LL | Some(i) => {
79-
| ^ help: consider prefixing with an underscore: `_i`
79+
| ^ help: if this is intentional, prefix it with an underscore: `_i`
8080

8181
error: unused variable: `x`
8282
--> $DIR/liveness-unused.rs:79:9
8383
|
8484
LL | for x in 1..10 { }
85-
| ^ help: consider prefixing with an underscore: `_x`
85+
| ^ help: if this is intentional, prefix it with an underscore: `_x`
8686

8787
error: unused variable: `x`
8888
--> $DIR/liveness-unused.rs:84:10
8989
|
9090
LL | for (x, _) in [1, 2, 3].iter().enumerate() { }
91-
| ^ help: consider prefixing with an underscore: `_x`
91+
| ^ help: if this is intentional, prefix it with an underscore: `_x`
9292

9393
error: unused variable: `x`
9494
--> $DIR/liveness-unused.rs:89:13
9595
|
9696
LL | for (_, x) in [1, 2, 3].iter().enumerate() {
97-
| ^ help: consider prefixing with an underscore: `_x`
97+
| ^ help: if this is intentional, prefix it with an underscore: `_x`
9898

9999
error: variable `x` is assigned to, but never used
100100
--> $DIR/liveness-unused.rs:112:9

src/test/ui/never_type/never-assign-dead-code.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ warning: unused variable: `x`
2525
--> $DIR/never-assign-dead-code.rs:9:9
2626
|
2727
LL | let x: ! = panic!("aah");
28-
| ^ help: consider prefixing with an underscore: `_x`
28+
| ^ help: if this is intentional, prefix it with an underscore: `_x`
2929
|
3030
note: the lint level is defined here
3131
--> $DIR/never-assign-dead-code.rs:6:9

src/test/ui/proc-macro/attributes-included.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ warning: unused variable: `a`
22
--> $DIR/attributes-included.rs:17:9
33
|
44
LL | let a: i32 = "foo";
5-
| ^ help: consider prefixing with an underscore: `_a`
5+
| ^ help: if this is intentional, prefix it with an underscore: `_a`
66
|
77
note: the lint level is defined here
88
--> $DIR/attributes-included.rs:4:9

0 commit comments

Comments
 (0)