about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSebastian Toh <sebas.tsj.98@gmail.com>2023-09-03 19:55:11 +0800
committerSebastian Toh <sebas.tsj.98@gmail.com>2023-09-03 19:55:11 +0800
commitd87b87d10e630eb0fb9cd0bf11c70ee869f077b7 (patch)
treeb0700d2294c143db74caf50f5eb27ccbaf7ee2f5
parent43dd8613a308745a9f75690bb5365f8b8ca05926 (diff)
downloadrust-d87b87d10e630eb0fb9cd0bf11c70ee869f077b7.tar.gz
rust-d87b87d10e630eb0fb9cd0bf11c70ee869f077b7.zip
Improve clarity of diagnostic message on non-exhaustive matches
-rw-r--r--compiler/rustc_mir_build/src/thir/pattern/check_match.rs4
-rw-r--r--tests/ui/closures/2229_closure_analysis/match/non-exhaustive-match.stderr2
-rw-r--r--tests/ui/match/match_non_exhaustive.stderr2
-rw-r--r--tests/ui/pattern/usefulness/issue-105479-str-non-exhaustiveness.rs2
-rw-r--r--tests/ui/pattern/usefulness/issue-105479-str-non-exhaustiveness.stderr2
-rw-r--r--tests/ui/pattern/usefulness/issue-30240.stderr4
-rw-r--r--tests/ui/pattern/usefulness/nested-non-exhaustive-enums.stderr2
-rw-r--r--tests/ui/rfcs/rfc-2008-non-exhaustive/enum.stderr2
8 files changed, 10 insertions, 10 deletions
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<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 => {},
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",