Skip to content

Commit

Permalink
non-exhastive diagnostic: add note re. scrutinee type
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Mar 27, 2020
1 parent 3b1d735 commit c858593
Show file tree
Hide file tree
Showing 64 changed files with 265 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/librustc_mir_build/hair/pattern/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
}

adt_defined_here(cx, &mut err, pattern_ty, &witnesses);
err.note(&format!("the matched value is of type `{}`", pattern_ty));
err.emit();
});
}
Expand Down Expand Up @@ -480,6 +481,7 @@ fn check_exhaustive<'p, 'tcx>(
"ensure that all possible cases are being handled, \
possibly by adding wildcards or more match arms",
);
err.note(&format!("the matched value is of type `{}`", scrut_ty));
err.emit();
}

Expand Down
1 change: 1 addition & 0 deletions src/test/ui/consts/const-match-check.eval1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ LL | A = { let 0 = 0; 0 },
|
= 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: you might want to use `if let` to ignore the variant that isn't matched
|
LL | A = { if let 0 = 0 { /* */ } 0 },
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/consts/const-match-check.eval2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ LL | let x: [i32; { let 0 = 0; 0 }] = [];
|
= 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: you might want to use `if let` to ignore the variant that isn't matched
|
LL | let x: [i32; { if let 0 = 0 { /* */ } 0 }] = [];
Expand Down
4 changes: 4 additions & 0 deletions src/test/ui/consts/const-match-check.matchck.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ LL | const X: i32 = { let 0 = 0; 0 };
|
= 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: you might want to use `if let` to ignore the variant that isn't matched
|
LL | const X: i32 = { if let 0 = 0 { /* */ } 0 };
Expand All @@ -19,6 +20,7 @@ LL | static Y: i32 = { let 0 = 0; 0 };
|
= 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: you might want to use `if let` to ignore the variant that isn't matched
|
LL | static Y: i32 = { if let 0 = 0 { /* */ } 0 };
Expand All @@ -32,6 +34,7 @@ LL | const X: i32 = { let 0 = 0; 0 };
|
= 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: you might want to use `if let` to ignore the variant that isn't matched
|
LL | const X: i32 = { if let 0 = 0 { /* */ } 0 };
Expand All @@ -45,6 +48,7 @@ LL | const X: i32 = { let 0 = 0; 0 };
|
= 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: you might want to use `if let` to ignore the variant that isn't matched
|
LL | const X: i32 = { if let 0 = 0 { /* */ } 0 };
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/consts/const-pattern-irrefutable.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ LL | let a = 4;
| |
| interpreted as a constant pattern, not a new variable
| help: introduce a variable instead: `a_var`
|
= note: the matched value is of type `u8`

error[E0005]: refutable pattern in local binding: `0u8..=1u8` and `3u8..=std::u8::MAX` not covered
--> $DIR/const-pattern-irrefutable.rs:13:9
Expand All @@ -21,6 +23,8 @@ LL | let c = 4;
| |
| interpreted as a constant pattern, not a new variable
| help: introduce a variable instead: `c_var`
|
= note: the matched value is of type `u8`

error[E0005]: refutable pattern in local binding: `0u8..=1u8` and `3u8..=std::u8::MAX` not covered
--> $DIR/const-pattern-irrefutable.rs:14:9
Expand All @@ -33,6 +37,8 @@ LL | let d = 4;
| |
| interpreted as a constant pattern, not a new variable
| help: introduce a variable instead: `d_var`
|
= note: the matched value is of type `u8`

error: aborting due to 3 previous errors

Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/consts/const_let_refutable.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ error[E0005]: refutable pattern in function argument: `&[]`, `&[_]` and `&[_, _,
|
LL | const fn slice(&[a, b]: &[i32]) -> i32 {
| ^^^^^^^ patterns `&[]`, `&[_]` and `&[_, _, _, ..]` not covered
|
= note: the matched value is of type `&[i32]`

error[E0723]: loops and conditional expressions are not stable in const fn
--> $DIR/const_let_refutable.rs:3:17
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/consts/match_ice.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ LL | match K {
| ^ pattern `&T` not covered
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
= note: the matched value is of type `&T`

error: to use a constant of type `S` in a pattern, `S` must be annotated with `#[derive(PartialEq, Eq)]`
--> $DIR/match_ice.rs:11:9
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/empty/empty-never-array.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ LL | let Helper::U(u) = Helper::T(t, []);
|
= 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 `Helper<T, U>`
help: you might want to use `if let` to ignore the variant that isn't matched
|
LL | if let Helper::U(u) = Helper::T(t, []) { /* */ }
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/error-codes/E0004-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ LL | Some(#[stable(feature = "rust1", since = "1.0.0")] T),
| ---- not covered
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
= note: the matched value is of type `std::option::Option<i32>`

error: aborting due to previous error

Expand Down
1 change: 1 addition & 0 deletions src/test/ui/error-codes/E0004.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ LL | match x {
| ^ pattern `HastaLaVistaBaby` not covered
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
= note: the matched value is of type `Terminator`

error: aborting due to previous error

Expand Down
1 change: 1 addition & 0 deletions src/test/ui/error-codes/E0005.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ LL | None,
|
= 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 `std::option::Option<i32>`
help: you might want to use `if let` to ignore the variant that isn't matched
|
LL | if let Some(y) = x { /* */ }
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/error-codes/E0297.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ LL | for Some(x) in xs {}
|
LL | None,
| ---- not covered
|
= note: the matched value is of type `std::option::Option<i32>`

error: aborting due to previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ LL | Err(#[stable(feature = "rust1", since = "1.0.0")] E),
|
= 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 `std::result::Result<u32, !>`
help: you might want to use `if let` to ignore the variant that isn't matched
|
LL | if let Ok(_x) = foo() { /* */ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LL | match 0usize {
| ^^^^^^ pattern `_` not covered
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
= note: the matched value is of type `usize`

error[E0004]: non-exhaustive patterns: `_` not covered
--> $DIR/feature-gate-precise_pointer_size_matching.rs:10:11
Expand All @@ -13,6 +14,7 @@ LL | match 0isize {
| ^^^^^^ pattern `_` not covered
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
= note: the matched value is of type `isize`

error: aborting due to 2 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ error[E0005]: refutable pattern in `for` loop binding: `&std::i32::MIN..=0i32` a
|
LL | for &1 in [1].iter() {}
| ^^ patterns `&std::i32::MIN..=0i32` and `&2i32..=std::i32::MAX` not covered
|
= note: the matched value is of type `&i32`

error: aborting due to previous error

Expand Down
Loading

0 comments on commit c858593

Please sign in to comment.