Skip to content

Commit 7a260b8

Browse files
committed
Make suggestion verbose
1 parent ab3243f commit 7a260b8

File tree

5 files changed

+42
-33
lines changed

5 files changed

+42
-33
lines changed

compiler/rustc_mir_build/src/errors.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,8 @@ impl<'tcx> Subdiagnostic for AdtDefinedHere<'tcx> {
913913
#[suggestion(
914914
mir_build_interpreted_as_const,
915915
code = "{variable}_var",
916-
applicability = "maybe-incorrect"
916+
applicability = "maybe-incorrect",
917+
style = "verbose"
917918
)]
918919
pub(crate) struct InterpretedAsConst {
919920
#[primary_span]

tests/ui/closures/2229_closure_analysis/bad-pattern.stderr

+5-4
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,15 @@ LL | const PAT: u32 = 0;
101101
| -------------- missing patterns are not covered because `PAT` is interpreted as a constant pattern, not a new variable
102102
...
103103
LL | let PAT = v1;
104-
| ^^^
105-
| |
106-
| pattern `1_u32..=u32::MAX` not covered
107-
| help: introduce a variable instead: `PAT_var`
104+
| ^^^ pattern `1_u32..=u32::MAX` not covered
108105
|
109106
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
110107
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
111108
= note: the matched value is of type `u32`
109+
help: introduce a variable instead
110+
|
111+
LL | let PAT_var = v1;
112+
| ~~~~~~~
112113

113114
error: aborting due to 7 previous errors
114115

tests/ui/consts/const-pattern-irrefutable.stderr

+20-16
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ LL | const a: u8 = 2;
55
| ----------- missing patterns are not covered because `a` is interpreted as a constant pattern, not a new variable
66
...
77
LL | let a = 4;
8-
| ^
9-
| |
10-
| patterns `0_u8..=1_u8` and `3_u8..=u8::MAX` not covered
11-
| help: introduce a variable instead: `a_var`
8+
| ^ patterns `0_u8..=1_u8` and `3_u8..=u8::MAX` not covered
129
|
1310
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
1411
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
1512
= note: the matched value is of type `u8`
13+
help: introduce a variable instead
14+
|
15+
LL | let a_var = 4;
16+
| ~~~~~
1617

1718
error[E0005]: refutable pattern in local binding
1819
--> $DIR/const-pattern-irrefutable.rs:28:9
@@ -21,14 +22,15 @@ LL | pub const b: u8 = 2;
2122
| --------------- missing patterns are not covered because `b` is interpreted as a constant pattern, not a new variable
2223
...
2324
LL | let c = 4;
24-
| ^
25-
| |
26-
| patterns `0_u8..=1_u8` and `3_u8..=u8::MAX` not covered
27-
| help: introduce a variable instead: `b_var`
25+
| ^ patterns `0_u8..=1_u8` and `3_u8..=u8::MAX` not covered
2826
|
2927
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
3028
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
3129
= note: the matched value is of type `u8`
30+
help: introduce a variable instead
31+
|
32+
LL | let b_var = 4;
33+
| ~~~~~
3234

3335
error[E0005]: refutable pattern in local binding
3436
--> $DIR/const-pattern-irrefutable.rs:32:9
@@ -37,14 +39,15 @@ LL | pub const d: (u8, u8) = (2, 1);
3739
| --------------------- missing patterns are not covered because `d` is interpreted as a constant pattern, not a new variable
3840
...
3941
LL | let d = (4, 4);
40-
| ^
41-
| |
42-
| patterns `(0_u8..=1_u8, _)` and `(3_u8..=u8::MAX, _)` not covered
43-
| help: introduce a variable instead: `d_var`
42+
| ^ patterns `(0_u8..=1_u8, _)` and `(3_u8..=u8::MAX, _)` not covered
4443
|
4544
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
4645
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
4746
= note: the matched value is of type `(u8, u8)`
47+
help: introduce a variable instead
48+
|
49+
LL | let d_var = (4, 4);
50+
| ~~~~~
4851

4952
error[E0005]: refutable pattern in local binding
5053
--> $DIR/const-pattern-irrefutable.rs:36:9
@@ -53,10 +56,7 @@ LL | const e: S = S {
5356
| ---------- missing patterns are not covered because `e` is interpreted as a constant pattern, not a new variable
5457
...
5558
LL | let e = S {
56-
| ^
57-
| |
58-
| pattern `S { foo: 1_u8..=u8::MAX }` not covered
59-
| help: introduce a variable instead: `e_var`
59+
| ^ pattern `S { foo: 1_u8..=u8::MAX }` not covered
6060
|
6161
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
6262
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
@@ -66,6 +66,10 @@ note: `S` defined here
6666
LL | struct S {
6767
| ^
6868
= note: the matched value is of type `S`
69+
help: introduce a variable instead
70+
|
71+
LL | let e_var = S {
72+
| ~~~~~
6973

7074
error: aborting due to 4 previous errors
7175

tests/ui/mir/issue-112269.stderr

+10-8
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,31 @@ error[E0005]: refutable pattern in local binding
44
LL | const x: i32 = 4;
55
| ------------ missing patterns are not covered because `x` is interpreted as a constant pattern, not a new variable
66
LL | let x: i32 = 3;
7-
| ^
8-
| |
9-
| patterns `i32::MIN..=3_i32` and `5_i32..=i32::MAX` not covered
10-
| help: introduce a variable instead: `x_var`
7+
| ^ patterns `i32::MIN..=3_i32` and `5_i32..=i32::MAX` not covered
118
|
129
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
1310
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
1411
= note: the matched value is of type `i32`
12+
help: introduce a variable instead
13+
|
14+
LL | let x_var: i32 = 3;
15+
| ~~~~~
1516

1617
error[E0005]: refutable pattern in local binding
1718
--> $DIR/issue-112269.rs:7:9
1819
|
1920
LL | const y: i32 = 3;
2021
| ------------ missing patterns are not covered because `y` is interpreted as a constant pattern, not a new variable
2122
LL | let y = 4;
22-
| ^
23-
| |
24-
| patterns `i32::MIN..=2_i32` and `4_i32..=i32::MAX` not covered
25-
| help: introduce a variable instead: `y_var`
23+
| ^ patterns `i32::MIN..=2_i32` and `4_i32..=i32::MAX` not covered
2624
|
2725
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
2826
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
2927
= note: the matched value is of type `i32`
28+
help: introduce a variable instead
29+
|
30+
LL | let y_var = 4;
31+
| ~~~~~
3032

3133
error: aborting due to 2 previous errors
3234

tests/ui/suggestions/const-pat-non-exaustive-let-new-var.stderr

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ error[E0005]: refutable pattern in local binding
22
--> $DIR/const-pat-non-exaustive-let-new-var.rs:2:9
33
|
44
LL | let A = 3;
5-
| ^
6-
| |
7-
| patterns `i32::MIN..=1_i32` and `3_i32..=i32::MAX` not covered
8-
| help: introduce a variable instead: `A_var`
5+
| ^ patterns `i32::MIN..=1_i32` and `3_i32..=i32::MAX` not covered
96
...
107
LL | const A: i32 = 2;
118
| ------------ missing patterns are not covered because `A` is interpreted as a constant pattern, not a new variable
129
|
1310
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
1411
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
1512
= note: the matched value is of type `i32`
13+
help: introduce a variable instead
14+
|
15+
LL | let A_var = 3;
16+
| ~~~~~
1617

1718
error: aborting due to 1 previous error
1819

0 commit comments

Comments
 (0)