Skip to content

Commit d87b87d

Browse files
committed
Improve clarity of diagnostic message on non-exhaustive matches
1 parent 43dd861 commit d87b87d

File tree

8 files changed

+10
-10
lines changed

8 files changed

+10
-10
lines changed

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -741,10 +741,10 @@ fn non_exhaustive_match<'p, 'tcx>(
741741
}
742742
} else if ty == cx.tcx.types.str_ {
743743
err.note(format!(
744-
"`{ty}` cannot be matched exhaustively, so a wildcard `_` is necessary",
744+
"`&str` cannot be matched exhaustively, so a wildcard `_` is necessary",
745745
));
746746
} else if cx.is_foreign_non_exhaustive_enum(ty) {
747-
err.note(format!("`{ty}` is marked as non-exhaustive"));
747+
err.note(format!("`{ty}` is marked as non-exhaustive, so a wildcard `_` is necessary to match exhaustively"));
748748
}
749749
}
750750
}

tests/ui/closures/2229_closure_analysis/match/non-exhaustive-match.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ note: `E2` defined here
4646
LL | pub enum E2 { A, B }
4747
| ^^^^^^^^^^^
4848
= note: the matched value is of type `E2`
49-
= note: `E2` is marked as non-exhaustive
49+
= note: `E2` is marked as non-exhaustive, so a wildcard `_` is necessary to match exhaustively
5050
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
5151
|
5252
LL | let _e = || { match e2 { E2::A => (), E2::B => (), _ => todo!() } };

tests/ui/match/match_non_exhaustive.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ note: `E2` defined here
4646
LL | pub enum E2 { A, B }
4747
| ^^^^^^^^^^^
4848
= note: the matched value is of type `E2`
49-
= note: `E2` is marked as non-exhaustive
49+
= note: `E2` is marked as non-exhaustive, so a wildcard `_` is necessary to match exhaustively
5050
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
5151
|
5252
LL | match e2 { E2::A => (), E2::B => (), _ => todo!() };

tests/ui/pattern/usefulness/issue-105479-str-non-exhaustiveness.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ fn main() {
55
//~^ ERROR non-exhaustive patterns: `(&_, _)` not covered [E0004]
66
//~| NOTE pattern `(&_, _)` not covered
77
//~| NOTE the matched value is of type `(&str, &str)`
8-
//~| NOTE `str` cannot be matched exhaustively, so a wildcard `_` is necessary
8+
//~| NOTE `&str` cannot be matched exhaustively, so a wildcard `_` is necessary
99
("a", "b") => {}
1010
("c", "d") => {}
1111
}

tests/ui/pattern/usefulness/issue-105479-str-non-exhaustiveness.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | match (a, b) {
55
| ^^^^^^ pattern `(&_, _)` not covered
66
|
77
= note: the matched value is of type `(&str, &str)`
8-
= note: `str` cannot be matched exhaustively, so a wildcard `_` is necessary
8+
= note: `&str` cannot be matched exhaustively, so a wildcard `_` is necessary
99
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
1010
|
1111
LL ~ ("c", "d") => {},

tests/ui/pattern/usefulness/issue-30240.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | match "world" {
55
| ^^^^^^^ pattern `&_` not covered
66
|
77
= note: the matched value is of type `&str`
8-
= note: `str` cannot be matched exhaustively, so a wildcard `_` is necessary
8+
= note: `&str` cannot be matched exhaustively, so a wildcard `_` is necessary
99
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
1010
|
1111
LL ~ "hello" => {},
@@ -19,7 +19,7 @@ LL | match "world" {
1919
| ^^^^^^^ pattern `&_` not covered
2020
|
2121
= note: the matched value is of type `&str`
22-
= note: `str` cannot be matched exhaustively, so a wildcard `_` is necessary
22+
= note: `&str` cannot be matched exhaustively, so a wildcard `_` is necessary
2323
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
2424
|
2525
LL ~ "hello" => {},

tests/ui/pattern/usefulness/nested-non-exhaustive-enums.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ note: `Option<NonExhaustiveEnum>` defined here
1010
|
1111
= note: not covered
1212
= note: the matched value is of type `Option<NonExhaustiveEnum>`
13-
= note: `NonExhaustiveEnum` is marked as non-exhaustive
13+
= note: `NonExhaustiveEnum` is marked as non-exhaustive, so a wildcard `_` is necessary to match exhaustively
1414
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
1515
|
1616
LL ~ None => {},

tests/ui/rfcs/rfc-2008-non-exhaustive/enum.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ note: `NonExhaustiveEnum` defined here
2929
LL | pub enum NonExhaustiveEnum {
3030
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
3131
= note: the matched value is of type `NonExhaustiveEnum`
32-
= note: `NonExhaustiveEnum` is marked as non-exhaustive
32+
= note: `NonExhaustiveEnum` is marked as non-exhaustive, so a wildcard `_` is necessary to match exhaustively
3333
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
3434
|
3535
LL ~ NonExhaustiveEnum::Struct { .. } => "third",

0 commit comments

Comments
 (0)