about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNadrieril <nadrieril+git@gmail.com>2024-02-08 00:09:31 +0100
committerNadrieril <nadrieril+git@gmail.com>2024-05-04 16:20:47 +0200
commit92d65a92e210ebc209e7c8ed0536ad1fbb1661a6 (patch)
treeffda86d6b80e4447fbeddc4896bfe756e188aa77
parent7dd170fccb3be6b1737af5df14dd736b366236c1 (diff)
downloadrust-92d65a92e210ebc209e7c8ed0536ad1fbb1661a6.tar.gz
rust-92d65a92e210ebc209e7c8ed0536ad1fbb1661a6.zip
Add tests
-rw-r--r--tests/mir-opt/building/match/never_patterns.opt1.SimplifyCfg-initial.after.mir54
-rw-r--r--tests/mir-opt/building/match/never_patterns.rs17
-rw-r--r--tests/ui/rfcs/rfc-0000-never_patterns/check.rs1
-rw-r--r--tests/ui/rfcs/rfc-0000-never_patterns/check.stderr12
-rw-r--r--tests/ui/rfcs/rfc-0000-never_patterns/check_place_is_initialized.rs12
-rw-r--r--tests/ui/rfcs/rfc-0000-never_patterns/typeck.rs12
-rw-r--r--tests/ui/rfcs/rfc-0000-never_patterns/use-bindings.rs34
-rw-r--r--tests/ui/rfcs/rfc-0000-never_patterns/use-bindings.stderr75
8 files changed, 211 insertions, 6 deletions
diff --git a/tests/mir-opt/building/match/never_patterns.opt1.SimplifyCfg-initial.after.mir b/tests/mir-opt/building/match/never_patterns.opt1.SimplifyCfg-initial.after.mir
new file mode 100644
index 00000000000..47598a3f48a
--- /dev/null
+++ b/tests/mir-opt/building/match/never_patterns.opt1.SimplifyCfg-initial.after.mir
@@ -0,0 +1,54 @@
+// MIR for `opt1` after SimplifyCfg-initial
+
+fn opt1(_1: &Result<u32, Void>) -> &u32 {
+    debug res => _1;
+    let mut _0: &u32;
+    let mut _2: isize;
+    let _3: &u32;
+    let mut _4: !;
+    let mut _5: ();
+    scope 1 {
+        debug x => _3;
+    }
+
+    bb0: {
+        PlaceMention(_1);
+        _2 = discriminant((*_1));
+        switchInt(move _2) -> [0: bb2, 1: bb3, otherwise: bb1];
+    }
+
+    bb1: {
+        FakeRead(ForMatchedPlace(None), _1);
+        unreachable;
+    }
+
+    bb2: {
+        falseEdge -> [real: bb4, imaginary: bb3];
+    }
+
+    bb3: {
+        StorageLive(_4);
+        goto -> bb5;
+    }
+
+    bb4: {
+        StorageLive(_3);
+        _3 = &(((*_1) as Ok).0: u32);
+        _0 = &(*_3);
+        StorageDead(_3);
+        return;
+    }
+
+    bb5: {
+        falseUnwind -> [real: bb6, unwind: bb7];
+    }
+
+    bb6: {
+        _5 = const ();
+        goto -> bb5;
+    }
+
+    bb7 (cleanup): {
+        resume;
+    }
+}
diff --git a/tests/mir-opt/building/match/never_patterns.rs b/tests/mir-opt/building/match/never_patterns.rs
new file mode 100644
index 00000000000..b6047aabe01
--- /dev/null
+++ b/tests/mir-opt/building/match/never_patterns.rs
@@ -0,0 +1,17 @@
+// skip-filecheck
+#![feature(never_patterns)]
+#![allow(incomplete_features)]
+
+enum Void {}
+
+// EMIT_MIR never_patterns.opt1.SimplifyCfg-initial.after.mir
+fn opt1(res: &Result<u32, Void>) -> &u32 {
+    match res {
+        Ok(x) => x,
+        Err(!),
+    }
+}
+
+fn main() {
+    opt1(&Ok(0));
+}
diff --git a/tests/ui/rfcs/rfc-0000-never_patterns/check.rs b/tests/ui/rfcs/rfc-0000-never_patterns/check.rs
index 0831477e749..dc13dd05fa6 100644
--- a/tests/ui/rfcs/rfc-0000-never_patterns/check.rs
+++ b/tests/ui/rfcs/rfc-0000-never_patterns/check.rs
@@ -1,3 +1,4 @@
+// Check that never patterns can't have bodies or guards.
 #![feature(never_patterns)]
 #![allow(incomplete_features)]
 
diff --git a/tests/ui/rfcs/rfc-0000-never_patterns/check.stderr b/tests/ui/rfcs/rfc-0000-never_patterns/check.stderr
index 25f7343a8a8..fbf7aa02ac2 100644
--- a/tests/ui/rfcs/rfc-0000-never_patterns/check.stderr
+++ b/tests/ui/rfcs/rfc-0000-never_patterns/check.stderr
@@ -1,5 +1,5 @@
 error: a never pattern is always unreachable
-  --> $DIR/check.rs:14:20
+  --> $DIR/check.rs:15:20
    |
 LL |         Some(!) => {}
    |                    ^^
@@ -8,13 +8,13 @@ LL |         Some(!) => {}
    |                    help: remove this expression
 
 error: a guard on a never pattern will never be run
-  --> $DIR/check.rs:19:20
+  --> $DIR/check.rs:20:20
    |
 LL |         Some(!) if true,
    |                    ^^^^ help: remove this guard
 
 error: a never pattern is always unreachable
-  --> $DIR/check.rs:24:28
+  --> $DIR/check.rs:25:28
    |
 LL |         Some(!) if true => {}
    |                            ^^
@@ -23,7 +23,7 @@ LL |         Some(!) if true => {}
    |                            help: remove this expression
 
 error: a never pattern is always unreachable
-  --> $DIR/check.rs:29:27
+  --> $DIR/check.rs:30:27
    |
 LL |         Some(never!()) => {}
    |                           ^^
@@ -32,7 +32,7 @@ LL |         Some(never!()) => {}
    |                           help: remove this expression
 
 error[E0004]: non-exhaustive patterns: `Some(!)` not covered
-  --> $DIR/check.rs:18:11
+  --> $DIR/check.rs:19:11
    |
 LL |     match None::<Void> {
    |           ^^^^^^^^^^^^ pattern `Some(!)` not covered
@@ -50,7 +50,7 @@ LL +         Some(!)
    |
 
 error[E0004]: non-exhaustive patterns: `Some(!)` not covered
-  --> $DIR/check.rs:23:11
+  --> $DIR/check.rs:24:11
    |
 LL |     match None::<Void> {
    |           ^^^^^^^^^^^^ pattern `Some(!)` not covered
diff --git a/tests/ui/rfcs/rfc-0000-never_patterns/check_place_is_initialized.rs b/tests/ui/rfcs/rfc-0000-never_patterns/check_place_is_initialized.rs
new file mode 100644
index 00000000000..c3d21a4b363
--- /dev/null
+++ b/tests/ui/rfcs/rfc-0000-never_patterns/check_place_is_initialized.rs
@@ -0,0 +1,12 @@
+//@ check-pass
+#![feature(never_patterns)]
+#![allow(incomplete_features)]
+
+enum Void {}
+
+fn main() {}
+
+fn anything<T>() -> T {
+    let x: Void;
+    match x { ! }
+}
diff --git a/tests/ui/rfcs/rfc-0000-never_patterns/typeck.rs b/tests/ui/rfcs/rfc-0000-never_patterns/typeck.rs
index e8bfa9245f5..8300f953dc1 100644
--- a/tests/ui/rfcs/rfc-0000-never_patterns/typeck.rs
+++ b/tests/ui/rfcs/rfc-0000-never_patterns/typeck.rs
@@ -123,3 +123,15 @@ fn never_pattern_typeck_pass(void: Void) {
         Some(!),
     }
 }
+
+struct Unsized {
+    void: Void,
+    slice: [u8],
+}
+
+#[cfg(pass)]
+fn not_sized(x: &Unsized) {
+    match *x {
+        !,
+    }
+}
diff --git a/tests/ui/rfcs/rfc-0000-never_patterns/use-bindings.rs b/tests/ui/rfcs/rfc-0000-never_patterns/use-bindings.rs
new file mode 100644
index 00000000000..7e38d45d595
--- /dev/null
+++ b/tests/ui/rfcs/rfc-0000-never_patterns/use-bindings.rs
@@ -0,0 +1,34 @@
+#![feature(never_patterns)]
+#![allow(incomplete_features)]
+
+#[derive(Copy, Clone)]
+enum Void {}
+
+fn main() {
+    let res_void: Result<bool, Void> = Ok(true);
+
+    let (Ok(x) | Err(!)) = res_void;
+    println!("{x}");
+    //~^ ERROR: used binding `x` is possibly-uninitialized
+    let (Ok(x) | Err(!)) = &res_void;
+    println!("{x}");
+    //~^ ERROR: used binding `x` is possibly-uninitialized
+    let (Err(!) | Ok(x)) = res_void;
+    println!("{x}");
+    //~^ ERROR: used binding `x` is possibly-uninitialized
+
+    match res_void {
+        Ok(x) | Err(!) => println!("{x}"),
+        //~^ ERROR: used binding `x` is possibly-uninitialized
+    }
+    match res_void {
+        Err(!) | Ok(x) => println!("{x}"),
+        //~^ ERROR: used binding `x` is possibly-uninitialized
+    }
+
+    let res_res_void: Result<Result<bool, Void>, Void> = Ok(Ok(true));
+    match res_res_void {
+        Ok(Ok(x) | Err(!)) | Err(!) => println!("{x}"),
+        //~^ ERROR: used binding `x` is possibly-uninitialized
+    }
+}
diff --git a/tests/ui/rfcs/rfc-0000-never_patterns/use-bindings.stderr b/tests/ui/rfcs/rfc-0000-never_patterns/use-bindings.stderr
new file mode 100644
index 00000000000..ca8277c7663
--- /dev/null
+++ b/tests/ui/rfcs/rfc-0000-never_patterns/use-bindings.stderr
@@ -0,0 +1,75 @@
+error[E0381]: used binding `x` is possibly-uninitialized
+  --> $DIR/use-bindings.rs:11:15
+   |
+LL |     let (Ok(x) | Err(!)) = res_void;
+   |             -
+   |             |
+   |             binding initialized here in some conditions
+   |             binding declared here but left uninitialized
+LL |     println!("{x}");
+   |               ^^^ `x` used here but it is possibly-uninitialized
+   |
+   = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0381]: used binding `x` is possibly-uninitialized
+  --> $DIR/use-bindings.rs:14:15
+   |
+LL |     let (Ok(x) | Err(!)) = &res_void;
+   |             -
+   |             |
+   |             binding initialized here in some conditions
+   |             binding declared here but left uninitialized
+LL |     println!("{x}");
+   |               ^^^ `x` used here but it is possibly-uninitialized
+   |
+   = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0381]: used binding `x` is possibly-uninitialized
+  --> $DIR/use-bindings.rs:17:15
+   |
+LL |     let (Err(!) | Ok(x)) = res_void;
+   |                      -
+   |                      |
+   |                      binding initialized here in some conditions
+   |                      binding declared here but left uninitialized
+LL |     println!("{x}");
+   |               ^^^ `x` used here but it is possibly-uninitialized
+   |
+   = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0381]: used binding `x` is possibly-uninitialized
+  --> $DIR/use-bindings.rs:21:37
+   |
+LL |         Ok(x) | Err(!) => println!("{x}"),
+   |            -                        ^^^ `x` used here but it is possibly-uninitialized
+   |            |
+   |            binding initialized here in some conditions
+   |            binding declared here but left uninitialized
+   |
+   = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0381]: used binding `x` is possibly-uninitialized
+  --> $DIR/use-bindings.rs:25:37
+   |
+LL |         Err(!) | Ok(x) => println!("{x}"),
+   |                     -               ^^^ `x` used here but it is possibly-uninitialized
+   |                     |
+   |                     binding initialized here in some conditions
+   |                     binding declared here but left uninitialized
+   |
+   = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0381]: used binding `x` is possibly-uninitialized
+  --> $DIR/use-bindings.rs:31:50
+   |
+LL |         Ok(Ok(x) | Err(!)) | Err(!) => println!("{x}"),
+   |               -                                  ^^^ `x` used here but it is possibly-uninitialized
+   |               |
+   |               binding initialized here in some conditions
+   |               binding declared here but left uninitialized
+   |
+   = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to 6 previous errors
+
+For more information about this error, try `rustc --explain E0381`.