mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-14 04:56:49 +00:00
Improve clarity of diagnostic message on non-exhaustive matches
This commit is contained in:
parent
43dd8613a3
commit
d87b87d10e
@ -741,10 +741,10 @@ fn non_exhaustive_match<'p, 'tcx>(
|
||||
}
|
||||
} else if ty == cx.tcx.types.str_ {
|
||||
err.note(format!(
|
||||
"`{ty}` cannot be matched exhaustively, so a wildcard `_` is necessary",
|
||||
"`&str` cannot be matched exhaustively, so a wildcard `_` is necessary",
|
||||
));
|
||||
} else if cx.is_foreign_non_exhaustive_enum(ty) {
|
||||
err.note(format!("`{ty}` is marked as non-exhaustive"));
|
||||
err.note(format!("`{ty}` is marked as non-exhaustive, so a wildcard `_` is necessary to match exhaustively"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ note: `E2` defined here
|
||||
LL | pub enum E2 { A, B }
|
||||
| ^^^^^^^^^^^
|
||||
= note: the matched value is of type `E2`
|
||||
= note: `E2` is marked as non-exhaustive
|
||||
= note: `E2` is marked as non-exhaustive, so a wildcard `_` is necessary to match exhaustively
|
||||
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
||||
|
|
||||
LL | let _e = || { match e2 { E2::A => (), E2::B => (), _ => todo!() } };
|
||||
|
@ -46,7 +46,7 @@ note: `E2` defined here
|
||||
LL | pub enum E2 { A, B }
|
||||
| ^^^^^^^^^^^
|
||||
= note: the matched value is of type `E2`
|
||||
= note: `E2` is marked as non-exhaustive
|
||||
= note: `E2` is marked as non-exhaustive, so a wildcard `_` is necessary to match exhaustively
|
||||
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
||||
|
|
||||
LL | match e2 { E2::A => (), E2::B => (), _ => todo!() };
|
||||
|
@ -5,7 +5,7 @@ fn main() {
|
||||
//~^ ERROR non-exhaustive patterns: `(&_, _)` not covered [E0004]
|
||||
//~| NOTE pattern `(&_, _)` not covered
|
||||
//~| NOTE the matched value is of type `(&str, &str)`
|
||||
//~| NOTE `str` cannot be matched exhaustively, so a wildcard `_` is necessary
|
||||
//~| NOTE `&str` cannot be matched exhaustively, so a wildcard `_` is necessary
|
||||
("a", "b") => {}
|
||||
("c", "d") => {}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ LL | match (a, b) {
|
||||
| ^^^^^^ pattern `(&_, _)` not covered
|
||||
|
|
||||
= note: the matched value is of type `(&str, &str)`
|
||||
= note: `str` cannot be matched exhaustively, so a wildcard `_` is necessary
|
||||
= note: `&str` cannot be matched exhaustively, so a wildcard `_` is necessary
|
||||
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
||||
|
|
||||
LL ~ ("c", "d") => {},
|
||||
|
@ -5,7 +5,7 @@ LL | match "world" {
|
||||
| ^^^^^^^ pattern `&_` not covered
|
||||
|
|
||||
= note: the matched value is of type `&str`
|
||||
= note: `str` cannot be matched exhaustively, so a wildcard `_` is necessary
|
||||
= note: `&str` cannot be matched exhaustively, so a wildcard `_` is necessary
|
||||
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
||||
|
|
||||
LL ~ "hello" => {},
|
||||
@ -19,7 +19,7 @@ LL | match "world" {
|
||||
| ^^^^^^^ pattern `&_` not covered
|
||||
|
|
||||
= note: the matched value is of type `&str`
|
||||
= note: `str` cannot be matched exhaustively, so a wildcard `_` is necessary
|
||||
= note: `&str` cannot be matched exhaustively, so a wildcard `_` is necessary
|
||||
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
||||
|
|
||||
LL ~ "hello" => {},
|
||||
|
@ -10,7 +10,7 @@ note: `Option<NonExhaustiveEnum>` defined here
|
||||
|
|
||||
= note: not covered
|
||||
= note: the matched value is of type `Option<NonExhaustiveEnum>`
|
||||
= note: `NonExhaustiveEnum` is marked as non-exhaustive
|
||||
= note: `NonExhaustiveEnum` is marked as non-exhaustive, so a wildcard `_` is necessary to match exhaustively
|
||||
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
||||
|
|
||||
LL ~ None => {},
|
||||
|
@ -29,7 +29,7 @@ note: `NonExhaustiveEnum` defined here
|
||||
LL | pub enum NonExhaustiveEnum {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: the matched value is of type `NonExhaustiveEnum`
|
||||
= note: `NonExhaustiveEnum` is marked as non-exhaustive
|
||||
= note: `NonExhaustiveEnum` is marked as non-exhaustive, so a wildcard `_` is necessary to match exhaustively
|
||||
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
||||
|
|
||||
LL ~ NonExhaustiveEnum::Struct { .. } => "third",
|
||||
|
Loading…
Reference in New Issue
Block a user