diff --git a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs index 38c24e0ab5e..95dced644e1 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs @@ -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")); } } } diff --git a/tests/ui/closures/2229_closure_analysis/match/non-exhaustive-match.stderr b/tests/ui/closures/2229_closure_analysis/match/non-exhaustive-match.stderr index fddd769c3df..0807f459029 100644 --- a/tests/ui/closures/2229_closure_analysis/match/non-exhaustive-match.stderr +++ b/tests/ui/closures/2229_closure_analysis/match/non-exhaustive-match.stderr @@ -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!() } }; diff --git a/tests/ui/match/match_non_exhaustive.stderr b/tests/ui/match/match_non_exhaustive.stderr index d07e284e299..7b8bdfe0053 100644 --- a/tests/ui/match/match_non_exhaustive.stderr +++ b/tests/ui/match/match_non_exhaustive.stderr @@ -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!() }; diff --git a/tests/ui/pattern/usefulness/issue-105479-str-non-exhaustiveness.rs b/tests/ui/pattern/usefulness/issue-105479-str-non-exhaustiveness.rs index faf37b07513..0ee7856c680 100644 --- a/tests/ui/pattern/usefulness/issue-105479-str-non-exhaustiveness.rs +++ b/tests/ui/pattern/usefulness/issue-105479-str-non-exhaustiveness.rs @@ -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") => {} } diff --git a/tests/ui/pattern/usefulness/issue-105479-str-non-exhaustiveness.stderr b/tests/ui/pattern/usefulness/issue-105479-str-non-exhaustiveness.stderr index 5c09b3bada6..771fc320a13 100644 --- a/tests/ui/pattern/usefulness/issue-105479-str-non-exhaustiveness.stderr +++ b/tests/ui/pattern/usefulness/issue-105479-str-non-exhaustiveness.stderr @@ -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") => {}, diff --git a/tests/ui/pattern/usefulness/issue-30240.stderr b/tests/ui/pattern/usefulness/issue-30240.stderr index 736ab34e164..da8bbdffbf6 100644 --- a/tests/ui/pattern/usefulness/issue-30240.stderr +++ b/tests/ui/pattern/usefulness/issue-30240.stderr @@ -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" => {}, diff --git a/tests/ui/pattern/usefulness/nested-non-exhaustive-enums.stderr b/tests/ui/pattern/usefulness/nested-non-exhaustive-enums.stderr index ae81f307fde..9fbd871db7c 100644 --- a/tests/ui/pattern/usefulness/nested-non-exhaustive-enums.stderr +++ b/tests/ui/pattern/usefulness/nested-non-exhaustive-enums.stderr @@ -10,7 +10,7 @@ note: `Option` defined here | = note: not covered = note: the matched value is of type `Option` - = 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 => {}, diff --git a/tests/ui/rfcs/rfc-2008-non-exhaustive/enum.stderr b/tests/ui/rfcs/rfc-2008-non-exhaustive/enum.stderr index 50209e18bd1..4e7f3098ab4 100644 --- a/tests/ui/rfcs/rfc-2008-non-exhaustive/enum.stderr +++ b/tests/ui/rfcs/rfc-2008-non-exhaustive/enum.stderr @@ -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",