about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorNadrieril <nadrieril+git@gmail.com>2024-01-05 17:21:09 +0100
committerNadrieril <nadrieril+git@gmail.com>2024-01-18 21:15:24 +0100
commitd8b72e796e4e2bc31701e2197c4bc6f324adbf64 (patch)
tree30ba18d447055c6645fa2df7801645b8e261ee9f /tests
parenta947c4c2c34a5bc1f25d5e9fd5cc269b4ae0d330 (diff)
downloadrust-d8b72e796e4e2bc31701e2197c4bc6f324adbf64.tar.gz
rust-d8b72e796e4e2bc31701e2197c4bc6f324adbf64.zip
Typecheck never patterns
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/rfcs/rfc-0000-never_patterns/typeck.rs17
-rw-r--r--tests/ui/rfcs/rfc-0000-never_patterns/typeck.stderr66
2 files changed, 78 insertions, 5 deletions
diff --git a/tests/ui/rfcs/rfc-0000-never_patterns/typeck.rs b/tests/ui/rfcs/rfc-0000-never_patterns/typeck.rs
index 90ff34e2f02..333108e92c0 100644
--- a/tests/ui/rfcs/rfc-0000-never_patterns/typeck.rs
+++ b/tests/ui/rfcs/rfc-0000-never_patterns/typeck.rs
@@ -1,4 +1,3 @@
-// check-pass
 #![feature(never_patterns)]
 #![feature(exhaustive_patterns)]
 #![allow(incomplete_features)]
@@ -17,40 +16,48 @@ fn safe_unwrap_result<T: Copy>(res: Result<T, Void>) {
 
 // Check we only accept `!` where we want to.
 fn never_pattern_typeck(void: Void) {
-    // FIXME(never_patterns): Don't accept on a non-empty type.
+    // Don't accept on a non-empty type.
     match () {
         !,
+        //~^ ERROR: mismatched types
     }
     match (0, false) {
         !,
+        //~^ ERROR: mismatched types
     }
     match (0, false) {
         (_, !),
+        //~^ ERROR: mismatched types
     }
     match Some(0) {
         None => {}
         Some(!),
+        //~^ ERROR: mismatched types
     }
 
-    // FIXME(never_patterns): Don't accept on an arbitrary type, even if there are no more branches.
+    // Don't accept on an arbitrary type, even if there are no more branches.
     match () {
         () => {}
         !,
+        //~^ ERROR: mismatched types
     }
 
-    // FIXME(never_patterns): Don't accept even on an empty branch.
+    // Don't accept even on an empty branch.
     match None::<Void> {
         None => {}
         !,
+        //~^ ERROR: mismatched types
     }
     match (&[] as &[Void]) {
         [] => {}
         !,
+        //~^ ERROR: mismatched types
     }
-    // FIXME(never_patterns): Let alone if the emptiness is behind a reference.
+    // Let alone if the emptiness is behind a reference.
     match None::<&Void> {
         None => {}
         !,
+        //~^ ERROR: mismatched types
     }
 
     // Participate in match ergonomics.
diff --git a/tests/ui/rfcs/rfc-0000-never_patterns/typeck.stderr b/tests/ui/rfcs/rfc-0000-never_patterns/typeck.stderr
new file mode 100644
index 00000000000..8c0475894de
--- /dev/null
+++ b/tests/ui/rfcs/rfc-0000-never_patterns/typeck.stderr
@@ -0,0 +1,66 @@
+error: mismatched types
+  --> $DIR/typeck.rs:21:9
+   |
+LL |         !,
+   |         ^ a never pattern must be used on an uninhabited type
+   |
+   = note: the matched value is of type `()`
+
+error: mismatched types
+  --> $DIR/typeck.rs:25:9
+   |
+LL |         !,
+   |         ^ a never pattern must be used on an uninhabited type
+   |
+   = note: the matched value is of type `(i32, bool)`
+
+error: mismatched types
+  --> $DIR/typeck.rs:29:13
+   |
+LL |         (_, !),
+   |             ^ a never pattern must be used on an uninhabited type
+   |
+   = note: the matched value is of type `bool`
+
+error: mismatched types
+  --> $DIR/typeck.rs:34:14
+   |
+LL |         Some(!),
+   |              ^ a never pattern must be used on an uninhabited type
+   |
+   = note: the matched value is of type `i32`
+
+error: mismatched types
+  --> $DIR/typeck.rs:41:9
+   |
+LL |         !,
+   |         ^ a never pattern must be used on an uninhabited type
+   |
+   = note: the matched value is of type `()`
+
+error: mismatched types
+  --> $DIR/typeck.rs:48:9
+   |
+LL |         !,
+   |         ^ a never pattern must be used on an uninhabited type
+   |
+   = note: the matched value is of type `Option<Void>`
+
+error: mismatched types
+  --> $DIR/typeck.rs:53:9
+   |
+LL |         !,
+   |         ^ a never pattern must be used on an uninhabited type
+   |
+   = note: the matched value is of type `[Void]`
+
+error: mismatched types
+  --> $DIR/typeck.rs:59:9
+   |
+LL |         !,
+   |         ^ a never pattern must be used on an uninhabited type
+   |
+   = note: the matched value is of type `Option<&Void>`
+
+error: aborting due to 8 previous errors
+