Make suggestion verbose

This commit is contained in:
Esteban Küber 2024-11-07 19:40:27 +00:00
parent f563efec15
commit f1772d5739
5 changed files with 42 additions and 33 deletions

View File

@ -913,7 +913,8 @@ impl<'tcx> Subdiagnostic for AdtDefinedHere<'tcx> {
#[suggestion( #[suggestion(
mir_build_interpreted_as_const, mir_build_interpreted_as_const,
code = "{variable}_var", code = "{variable}_var",
applicability = "maybe-incorrect" applicability = "maybe-incorrect",
style = "verbose"
)] )]
pub(crate) struct InterpretedAsConst { pub(crate) struct InterpretedAsConst {
#[primary_span] #[primary_span]

View File

@ -101,14 +101,15 @@ LL | const PAT: u32 = 0;
| -------------- missing patterns are not covered because `PAT` is interpreted as a constant pattern, not a new variable | -------------- missing patterns are not covered because `PAT` is interpreted as a constant pattern, not a new variable
... ...
LL | let PAT = v1; LL | let PAT = v1;
| ^^^ | ^^^ pattern `1_u32..=u32::MAX` not covered
| |
| pattern `1_u32..=u32::MAX` not covered
| help: introduce a variable instead: `PAT_var`
| |
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
= note: the matched value is of type `u32` = note: the matched value is of type `u32`
help: introduce a variable instead
|
LL | let PAT_var = v1;
| ~~~~~~~
error: aborting due to 7 previous errors error: aborting due to 7 previous errors

View File

@ -5,14 +5,15 @@ LL | const a: u8 = 2;
| ----------- missing patterns are not covered because `a` is interpreted as a constant pattern, not a new variable | ----------- missing patterns are not covered because `a` is interpreted as a constant pattern, not a new variable
... ...
LL | let a = 4; LL | let a = 4;
| ^ | ^ patterns `0_u8..=1_u8` and `3_u8..=u8::MAX` not covered
| |
| patterns `0_u8..=1_u8` and `3_u8..=u8::MAX` not covered
| help: introduce a variable instead: `a_var`
| |
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
= note: the matched value is of type `u8` = note: the matched value is of type `u8`
help: introduce a variable instead
|
LL | let a_var = 4;
| ~~~~~
error[E0005]: refutable pattern in local binding error[E0005]: refutable pattern in local binding
--> $DIR/const-pattern-irrefutable.rs:28:9 --> $DIR/const-pattern-irrefutable.rs:28:9
@ -21,14 +22,15 @@ LL | pub const b: u8 = 2;
| --------------- missing patterns are not covered because `b` is interpreted as a constant pattern, not a new variable | --------------- missing patterns are not covered because `b` is interpreted as a constant pattern, not a new variable
... ...
LL | let c = 4; LL | let c = 4;
| ^ | ^ patterns `0_u8..=1_u8` and `3_u8..=u8::MAX` not covered
| |
| patterns `0_u8..=1_u8` and `3_u8..=u8::MAX` not covered
| help: introduce a variable instead: `b_var`
| |
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
= note: the matched value is of type `u8` = note: the matched value is of type `u8`
help: introduce a variable instead
|
LL | let b_var = 4;
| ~~~~~
error[E0005]: refutable pattern in local binding error[E0005]: refutable pattern in local binding
--> $DIR/const-pattern-irrefutable.rs:32:9 --> $DIR/const-pattern-irrefutable.rs:32:9
@ -37,14 +39,15 @@ LL | pub const d: (u8, u8) = (2, 1);
| --------------------- missing patterns are not covered because `d` is interpreted as a constant pattern, not a new variable | --------------------- missing patterns are not covered because `d` is interpreted as a constant pattern, not a new variable
... ...
LL | let d = (4, 4); LL | let d = (4, 4);
| ^ | ^ patterns `(0_u8..=1_u8, _)` and `(3_u8..=u8::MAX, _)` not covered
| |
| patterns `(0_u8..=1_u8, _)` and `(3_u8..=u8::MAX, _)` not covered
| help: introduce a variable instead: `d_var`
| |
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
= note: the matched value is of type `(u8, u8)` = note: the matched value is of type `(u8, u8)`
help: introduce a variable instead
|
LL | let d_var = (4, 4);
| ~~~~~
error[E0005]: refutable pattern in local binding error[E0005]: refutable pattern in local binding
--> $DIR/const-pattern-irrefutable.rs:36:9 --> $DIR/const-pattern-irrefutable.rs:36:9
@ -53,10 +56,7 @@ LL | const e: S = S {
| ---------- missing patterns are not covered because `e` is interpreted as a constant pattern, not a new variable | ---------- missing patterns are not covered because `e` is interpreted as a constant pattern, not a new variable
... ...
LL | let e = S { LL | let e = S {
| ^ | ^ pattern `S { foo: 1_u8..=u8::MAX }` not covered
| |
| pattern `S { foo: 1_u8..=u8::MAX }` not covered
| help: introduce a variable instead: `e_var`
| |
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
@ -66,6 +66,10 @@ note: `S` defined here
LL | struct S { LL | struct S {
| ^ | ^
= note: the matched value is of type `S` = note: the matched value is of type `S`
help: introduce a variable instead
|
LL | let e_var = S {
| ~~~~~
error: aborting due to 4 previous errors error: aborting due to 4 previous errors

View File

@ -4,14 +4,15 @@ error[E0005]: refutable pattern in local binding
LL | const x: i32 = 4; LL | const x: i32 = 4;
| ------------ missing patterns are not covered because `x` is interpreted as a constant pattern, not a new variable | ------------ missing patterns are not covered because `x` is interpreted as a constant pattern, not a new variable
LL | let x: i32 = 3; LL | let x: i32 = 3;
| ^ | ^ patterns `i32::MIN..=3_i32` and `5_i32..=i32::MAX` not covered
| |
| patterns `i32::MIN..=3_i32` and `5_i32..=i32::MAX` not covered
| help: introduce a variable instead: `x_var`
| |
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
= note: the matched value is of type `i32` = note: the matched value is of type `i32`
help: introduce a variable instead
|
LL | let x_var: i32 = 3;
| ~~~~~
error[E0005]: refutable pattern in local binding error[E0005]: refutable pattern in local binding
--> $DIR/issue-112269.rs:7:9 --> $DIR/issue-112269.rs:7:9
@ -19,14 +20,15 @@ error[E0005]: refutable pattern in local binding
LL | const y: i32 = 3; LL | const y: i32 = 3;
| ------------ missing patterns are not covered because `y` is interpreted as a constant pattern, not a new variable | ------------ missing patterns are not covered because `y` is interpreted as a constant pattern, not a new variable
LL | let y = 4; LL | let y = 4;
| ^ | ^ patterns `i32::MIN..=2_i32` and `4_i32..=i32::MAX` not covered
| |
| patterns `i32::MIN..=2_i32` and `4_i32..=i32::MAX` not covered
| help: introduce a variable instead: `y_var`
| |
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
= note: the matched value is of type `i32` = note: the matched value is of type `i32`
help: introduce a variable instead
|
LL | let y_var = 4;
| ~~~~~
error: aborting due to 2 previous errors error: aborting due to 2 previous errors

View File

@ -2,10 +2,7 @@ error[E0005]: refutable pattern in local binding
--> $DIR/const-pat-non-exaustive-let-new-var.rs:2:9 --> $DIR/const-pat-non-exaustive-let-new-var.rs:2:9
| |
LL | let A = 3; LL | let A = 3;
| ^ | ^ patterns `i32::MIN..=1_i32` and `3_i32..=i32::MAX` not covered
| |
| patterns `i32::MIN..=1_i32` and `3_i32..=i32::MAX` not covered
| help: introduce a variable instead: `A_var`
... ...
LL | const A: i32 = 2; LL | const A: i32 = 2;
| ------------ missing patterns are not covered because `A` is interpreted as a constant pattern, not a new variable | ------------ missing patterns are not covered because `A` is interpreted as a constant pattern, not a new variable
@ -13,6 +10,10 @@ LL | const A: i32 = 2;
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
= note: the matched value is of type `i32` = note: the matched value is of type `i32`
help: introduce a variable instead
|
LL | let A_var = 3;
| ~~~~~
error: aborting due to 1 previous error error: aborting due to 1 previous error