Add tests
This commit is contained in:
parent
7dd170fccb
commit
92d65a92e2
@ -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;
|
||||
}
|
||||
}
|
17
tests/mir-opt/building/match/never_patterns.rs
Normal file
17
tests/mir-opt/building/match/never_patterns.rs
Normal file
@ -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));
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
// Check that never patterns can't have bodies or guards.
|
||||
#![feature(never_patterns)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
|
@ -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
|
||||
|
@ -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 { ! }
|
||||
}
|
@ -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 {
|
||||
!,
|
||||
}
|
||||
}
|
||||
|
34
tests/ui/rfcs/rfc-0000-never_patterns/use-bindings.rs
Normal file
34
tests/ui/rfcs/rfc-0000-never_patterns/use-bindings.rs
Normal file
@ -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
|
||||
}
|
||||
}
|
75
tests/ui/rfcs/rfc-0000-never_patterns/use-bindings.stderr
Normal file
75
tests/ui/rfcs/rfc-0000-never_patterns/use-bindings.stderr
Normal file
@ -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`.
|
Loading…
Reference in New Issue
Block a user