Skip to content

Commit c858593

Browse files
committed
non-exhastive diagnostic: add note re. scrutinee type
1 parent 3b1d735 commit c858593

File tree

64 files changed

+265
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+265
-0
lines changed

src/librustc_mir_build/hair/pattern/check_match.rs

+2
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
241241
}
242242

243243
adt_defined_here(cx, &mut err, pattern_ty, &witnesses);
244+
err.note(&format!("the matched value is of type `{}`", pattern_ty));
244245
err.emit();
245246
});
246247
}
@@ -480,6 +481,7 @@ fn check_exhaustive<'p, 'tcx>(
480481
"ensure that all possible cases are being handled, \
481482
possibly by adding wildcards or more match arms",
482483
);
484+
err.note(&format!("the matched value is of type `{}`", scrut_ty));
483485
err.emit();
484486
}
485487

src/test/ui/consts/const-match-check.eval1.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ LL | A = { let 0 = 0; 0 },
66
|
77
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
88
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
9+
= note: the matched value is of type `i32`
910
help: you might want to use `if let` to ignore the variant that isn't matched
1011
|
1112
LL | A = { if let 0 = 0 { /* */ } 0 },

src/test/ui/consts/const-match-check.eval2.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ LL | let x: [i32; { let 0 = 0; 0 }] = [];
66
|
77
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
88
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
9+
= note: the matched value is of type `i32`
910
help: you might want to use `if let` to ignore the variant that isn't matched
1011
|
1112
LL | let x: [i32; { if let 0 = 0 { /* */ } 0 }] = [];

src/test/ui/consts/const-match-check.matchck.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ LL | const X: i32 = { let 0 = 0; 0 };
66
|
77
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
88
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
9+
= note: the matched value is of type `i32`
910
help: you might want to use `if let` to ignore the variant that isn't matched
1011
|
1112
LL | const X: i32 = { if let 0 = 0 { /* */ } 0 };
@@ -19,6 +20,7 @@ LL | static Y: i32 = { let 0 = 0; 0 };
1920
|
2021
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
2122
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
23+
= note: the matched value is of type `i32`
2224
help: you might want to use `if let` to ignore the variant that isn't matched
2325
|
2426
LL | static Y: i32 = { if let 0 = 0 { /* */ } 0 };
@@ -32,6 +34,7 @@ LL | const X: i32 = { let 0 = 0; 0 };
3234
|
3335
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
3436
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
37+
= note: the matched value is of type `i32`
3538
help: you might want to use `if let` to ignore the variant that isn't matched
3639
|
3740
LL | const X: i32 = { if let 0 = 0 { /* */ } 0 };
@@ -45,6 +48,7 @@ LL | const X: i32 = { let 0 = 0; 0 };
4548
|
4649
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
4750
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
51+
= note: the matched value is of type `i32`
4852
help: you might want to use `if let` to ignore the variant that isn't matched
4953
|
5054
LL | const X: i32 = { if let 0 = 0 { /* */ } 0 };

src/test/ui/consts/const-pattern-irrefutable.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ LL | let a = 4;
99
| |
1010
| interpreted as a constant pattern, not a new variable
1111
| help: introduce a variable instead: `a_var`
12+
|
13+
= note: the matched value is of type `u8`
1214

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

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

3743
error: aborting due to 3 previous errors
3844

src/test/ui/consts/const_let_refutable.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error[E0005]: refutable pattern in function argument: `&[]`, `&[_]` and `&[_, _,
33
|
44
LL | const fn slice(&[a, b]: &[i32]) -> i32 {
55
| ^^^^^^^ patterns `&[]`, `&[_]` and `&[_, _, _, ..]` not covered
6+
|
7+
= note: the matched value is of type `&[i32]`
68

79
error[E0723]: loops and conditional expressions are not stable in const fn
810
--> $DIR/const_let_refutable.rs:3:17

src/test/ui/consts/match_ice.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ LL | match K {
1414
| ^ pattern `&T` not covered
1515
|
1616
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
17+
= note: the matched value is of type `&T`
1718

1819
error: to use a constant of type `S` in a pattern, `S` must be annotated with `#[derive(PartialEq, Eq)]`
1920
--> $DIR/match_ice.rs:11:9

src/test/ui/empty/empty-never-array.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ LL | let Helper::U(u) = Helper::T(t, []);
1414
|
1515
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
1616
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
17+
= note: the matched value is of type `Helper<T, U>`
1718
help: you might want to use `if let` to ignore the variant that isn't matched
1819
|
1920
LL | if let Helper::U(u) = Helper::T(t, []) { /* */ }

src/test/ui/error-codes/E0004-2.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ LL | Some(#[stable(feature = "rust1", since = "1.0.0")] T),
1313
| ---- not covered
1414
|
1515
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
16+
= note: the matched value is of type `std::option::Option<i32>`
1617

1718
error: aborting due to previous error
1819

src/test/ui/error-codes/E0004.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ LL | match x {
1212
| ^ pattern `HastaLaVistaBaby` not covered
1313
|
1414
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
15+
= note: the matched value is of type `Terminator`
1516

1617
error: aborting due to previous error
1718

src/test/ui/error-codes/E0005.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ LL | None,
1111
|
1212
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
1313
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
14+
= note: the matched value is of type `std::option::Option<i32>`
1415
help: you might want to use `if let` to ignore the variant that isn't matched
1516
|
1617
LL | if let Some(y) = x { /* */ }

src/test/ui/error-codes/E0297.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ LL | for Some(x) in xs {}
88
|
99
LL | None,
1010
| ---- not covered
11+
|
12+
= note: the matched value is of type `std::option::Option<i32>`
1113

1214
error: aborting due to previous error
1315

src/test/ui/feature-gates/feature-gate-exhaustive-patterns.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ LL | Err(#[stable(feature = "rust1", since = "1.0.0")] E),
1111
|
1212
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
1313
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
14+
= note: the matched value is of type `std::result::Result<u32, !>`
1415
help: you might want to use `if let` to ignore the variant that isn't matched
1516
|
1617
LL | if let Ok(_x) = foo() { /* */ }

src/test/ui/feature-gates/feature-gate-precise_pointer_size_matching.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | match 0usize {
55
| ^^^^^^ pattern `_` not covered
66
|
77
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
8+
= note: the matched value is of type `usize`
89

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

1719
error: aborting due to 2 previous errors
1820

src/test/ui/for/for-loop-refutable-pattern-error-message.stderr

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

79
error: aborting due to previous error
810

0 commit comments

Comments
 (0)