Skip to content

Commit

Permalink
Make suggestion verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Nov 7, 2024
1 parent d02ba09 commit cdbfcfc
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 33 deletions.
3 changes: 2 additions & 1 deletion compiler/rustc_mir_build/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,8 @@ impl<'tcx> Subdiagnostic for AdtDefinedHere<'tcx> {
#[suggestion(
mir_build_interpreted_as_const,
code = "{variable}_var",
applicability = "maybe-incorrect"
applicability = "maybe-incorrect",
style = "verbose"
)]
pub(crate) struct InterpretedAsConst {
#[primary_span]
Expand Down
9 changes: 5 additions & 4 deletions tests/ui/closures/2229_closure_analysis/bad-pattern.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
...
LL | let PAT = v1;
| ^^^
| |
| pattern `1_u32..=u32::MAX` not covered
| help: introduce a variable instead: `PAT_var`
| ^^^ pattern `1_u32..=u32::MAX` not covered
|
= 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: the matched value is of type `u32`
help: introduce a variable instead
|
LL | let PAT_var = v1;
| ~~~~~~~

error: aborting due to 7 previous errors

Expand Down
36 changes: 20 additions & 16 deletions tests/ui/consts/const-pattern-irrefutable.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
...
LL | let a = 4;
| ^
| |
| patterns `0_u8..=1_u8` and `3_u8..=u8::MAX` not covered
| help: introduce a variable instead: `a_var`
| ^ patterns `0_u8..=1_u8` and `3_u8..=u8::MAX` not covered
|
= 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: the matched value is of type `u8`
help: introduce a variable instead
|
LL | let a_var = 4;
| ~~~~~

error[E0005]: refutable pattern in local binding
--> $DIR/const-pattern-irrefutable.rs:28:9
Expand All @@ -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
...
LL | let c = 4;
| ^
| |
| patterns `0_u8..=1_u8` and `3_u8..=u8::MAX` not covered
| help: introduce a variable instead: `b_var`
| ^ patterns `0_u8..=1_u8` and `3_u8..=u8::MAX` not covered
|
= 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: the matched value is of type `u8`
help: introduce a variable instead
|
LL | let b_var = 4;
| ~~~~~

error[E0005]: refutable pattern in local binding
--> $DIR/const-pattern-irrefutable.rs:32:9
Expand All @@ -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
...
LL | let d = (4, 4);
| ^
| |
| patterns `(0_u8..=1_u8, _)` and `(3_u8..=u8::MAX, _)` not covered
| help: introduce a variable instead: `d_var`
| ^ patterns `(0_u8..=1_u8, _)` and `(3_u8..=u8::MAX, _)` not covered
|
= 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: 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
--> $DIR/const-pattern-irrefutable.rs:36:9
Expand All @@ -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
...
LL | let e = S {
| ^
| |
| pattern `S { foo: 1_u8..=u8::MAX }` not covered
| help: introduce a variable instead: `e_var`
| ^ pattern `S { foo: 1_u8..=u8::MAX }` not covered
|
= 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
Expand All @@ -66,6 +66,10 @@ note: `S` defined here
LL | struct 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

Expand Down
18 changes: 10 additions & 8 deletions tests/ui/mir/issue-112269.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,31 @@ error[E0005]: refutable pattern in local binding
LL | const x: i32 = 4;
| ------------ missing patterns are not covered because `x` is interpreted as a constant pattern, not a new variable
LL | let x: i32 = 3;
| ^
| |
| patterns `i32::MIN..=3_i32` and `5_i32..=i32::MAX` not covered
| help: introduce a variable instead: `x_var`
| ^ patterns `i32::MIN..=3_i32` and `5_i32..=i32::MAX` not covered
|
= 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: 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
--> $DIR/issue-112269.rs:7:9
|
LL | const y: i32 = 3;
| ------------ missing patterns are not covered because `y` is interpreted as a constant pattern, not a new variable
LL | let y = 4;
| ^
| |
| patterns `i32::MIN..=2_i32` and `4_i32..=i32::MAX` not covered
| help: introduce a variable instead: `y_var`
| ^ patterns `i32::MIN..=2_i32` and `4_i32..=i32::MAX` not covered
|
= 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: the matched value is of type `i32`
help: introduce a variable instead
|
LL | let y_var = 4;
| ~~~~~

error: aborting due to 2 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ error[E0005]: refutable pattern in local binding
--> $DIR/const-pat-non-exaustive-let-new-var.rs:2:9
|
LL | let A = 3;
| ^
| |
| patterns `i32::MIN..=1_i32` and `3_i32..=i32::MAX` not covered
| help: introduce a variable instead: `A_var`
| ^ patterns `i32::MIN..=1_i32` and `3_i32..=i32::MAX` not covered
...
LL | const A: i32 = 2;
| ------------ missing patterns are not covered because `A` is interpreted as a constant pattern, not a new variable
|
= 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: the matched value is of type `i32`
help: introduce a variable instead
|
LL | let A_var = 3;
| ~~~~~

error: aborting due to 1 previous error

Expand Down

0 comments on commit cdbfcfc

Please sign in to comment.