Skip to content

Commit 17c1a57

Browse files
committed
Add tests
1 parent a8773d5 commit 17c1a57

File tree

8 files changed

+211
-6
lines changed

8 files changed

+211
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// MIR for `opt1` after SimplifyCfg-initial
2+
3+
fn opt1(_1: &Result<u32, Void>) -> &u32 {
4+
debug res => _1;
5+
let mut _0: &u32;
6+
let mut _2: isize;
7+
let _3: &u32;
8+
let mut _4: !;
9+
let mut _5: ();
10+
scope 1 {
11+
debug x => _3;
12+
}
13+
14+
bb0: {
15+
PlaceMention(_1);
16+
_2 = discriminant((*_1));
17+
switchInt(move _2) -> [0: bb2, 1: bb3, otherwise: bb1];
18+
}
19+
20+
bb1: {
21+
FakeRead(ForMatchedPlace(None), _1);
22+
unreachable;
23+
}
24+
25+
bb2: {
26+
falseEdge -> [real: bb4, imaginary: bb3];
27+
}
28+
29+
bb3: {
30+
StorageLive(_4);
31+
goto -> bb5;
32+
}
33+
34+
bb4: {
35+
StorageLive(_3);
36+
_3 = &(((*_1) as Ok).0: u32);
37+
_0 = &(*_3);
38+
StorageDead(_3);
39+
return;
40+
}
41+
42+
bb5: {
43+
falseUnwind -> [real: bb6, unwind: bb7];
44+
}
45+
46+
bb6: {
47+
_5 = const ();
48+
goto -> bb5;
49+
}
50+
51+
bb7 (cleanup): {
52+
resume;
53+
}
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// skip-filecheck
2+
#![feature(never_patterns)]
3+
#![allow(incomplete_features)]
4+
5+
enum Void {}
6+
7+
// EMIT_MIR never_patterns.opt1.SimplifyCfg-initial.after.mir
8+
fn opt1(res: &Result<u32, Void>) -> &u32 {
9+
match res {
10+
Ok(x) => x,
11+
Err(!),
12+
}
13+
}
14+
15+
fn main() {
16+
opt1(&Ok(0));
17+
}

tests/ui/rfcs/rfc-0000-never_patterns/check.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Check that never patterns can't have bodies or guards.
12
#![feature(never_patterns)]
23
#![allow(incomplete_features)]
34

tests/ui/rfcs/rfc-0000-never_patterns/check.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: a never pattern is always unreachable
2-
--> $DIR/check.rs:14:20
2+
--> $DIR/check.rs:15:20
33
|
44
LL | Some(!) => {}
55
| ^^
@@ -8,13 +8,13 @@ LL | Some(!) => {}
88
| help: remove this expression
99

1010
error: a guard on a never pattern will never be run
11-
--> $DIR/check.rs:19:20
11+
--> $DIR/check.rs:20:20
1212
|
1313
LL | Some(!) if true,
1414
| ^^^^ help: remove this guard
1515

1616
error: a never pattern is always unreachable
17-
--> $DIR/check.rs:24:28
17+
--> $DIR/check.rs:25:28
1818
|
1919
LL | Some(!) if true => {}
2020
| ^^
@@ -23,7 +23,7 @@ LL | Some(!) if true => {}
2323
| help: remove this expression
2424

2525
error: a never pattern is always unreachable
26-
--> $DIR/check.rs:29:27
26+
--> $DIR/check.rs:30:27
2727
|
2828
LL | Some(never!()) => {}
2929
| ^^
@@ -32,7 +32,7 @@ LL | Some(never!()) => {}
3232
| help: remove this expression
3333

3434
error[E0004]: non-exhaustive patterns: `Some(!)` not covered
35-
--> $DIR/check.rs:18:11
35+
--> $DIR/check.rs:19:11
3636
|
3737
LL | match None::<Void> {
3838
| ^^^^^^^^^^^^ pattern `Some(!)` not covered
@@ -50,7 +50,7 @@ LL + Some(!)
5050
|
5151

5252
error[E0004]: non-exhaustive patterns: `Some(!)` not covered
53-
--> $DIR/check.rs:23:11
53+
--> $DIR/check.rs:24:11
5454
|
5555
LL | match None::<Void> {
5656
| ^^^^^^^^^^^^ pattern `Some(!)` not covered
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@ check-pass
2+
#![feature(never_patterns)]
3+
#![allow(incomplete_features)]
4+
5+
enum Void {}
6+
7+
fn main() {}
8+
9+
fn anything<T>() -> T {
10+
let x: Void;
11+
match x { ! }
12+
}

tests/ui/rfcs/rfc-0000-never_patterns/typeck.rs

+12
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,15 @@ fn never_pattern_typeck_pass(void: Void) {
123123
Some(!),
124124
}
125125
}
126+
127+
struct Unsized {
128+
void: Void,
129+
slice: [u8],
130+
}
131+
132+
#[cfg(pass)]
133+
fn not_sized(x: &Unsized) {
134+
match *x {
135+
!,
136+
}
137+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#![feature(never_patterns)]
2+
#![allow(incomplete_features)]
3+
4+
#[derive(Copy, Clone)]
5+
enum Void {}
6+
7+
fn main() {
8+
let res_void: Result<bool, Void> = Ok(true);
9+
10+
let (Ok(x) | Err(!)) = res_void;
11+
println!("{x}");
12+
//~^ ERROR: used binding `x` is possibly-uninitialized
13+
let (Ok(x) | Err(!)) = &res_void;
14+
println!("{x}");
15+
//~^ ERROR: used binding `x` is possibly-uninitialized
16+
let (Err(!) | Ok(x)) = res_void;
17+
println!("{x}");
18+
//~^ ERROR: used binding `x` is possibly-uninitialized
19+
20+
match res_void {
21+
Ok(x) | Err(!) => println!("{x}"),
22+
//~^ ERROR: used binding `x` is possibly-uninitialized
23+
}
24+
match res_void {
25+
Err(!) | Ok(x) => println!("{x}"),
26+
//~^ ERROR: used binding `x` is possibly-uninitialized
27+
}
28+
29+
let res_res_void: Result<Result<bool, Void>, Void> = Ok(Ok(true));
30+
match res_res_void {
31+
Ok(Ok(x) | Err(!)) | Err(!) => println!("{x}"),
32+
//~^ ERROR: used binding `x` is possibly-uninitialized
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
error[E0381]: used binding `x` is possibly-uninitialized
2+
--> $DIR/use-bindings.rs:11:15
3+
|
4+
LL | let (Ok(x) | Err(!)) = res_void;
5+
| -
6+
| |
7+
| binding initialized here in some conditions
8+
| binding declared here but left uninitialized
9+
LL | println!("{x}");
10+
| ^^^ `x` used here but it is possibly-uninitialized
11+
|
12+
= 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)
13+
14+
error[E0381]: used binding `x` is possibly-uninitialized
15+
--> $DIR/use-bindings.rs:14:15
16+
|
17+
LL | let (Ok(x) | Err(!)) = &res_void;
18+
| -
19+
| |
20+
| binding initialized here in some conditions
21+
| binding declared here but left uninitialized
22+
LL | println!("{x}");
23+
| ^^^ `x` used here but it is possibly-uninitialized
24+
|
25+
= 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)
26+
27+
error[E0381]: used binding `x` is possibly-uninitialized
28+
--> $DIR/use-bindings.rs:17:15
29+
|
30+
LL | let (Err(!) | Ok(x)) = res_void;
31+
| -
32+
| |
33+
| binding initialized here in some conditions
34+
| binding declared here but left uninitialized
35+
LL | println!("{x}");
36+
| ^^^ `x` used here but it is possibly-uninitialized
37+
|
38+
= 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)
39+
40+
error[E0381]: used binding `x` is possibly-uninitialized
41+
--> $DIR/use-bindings.rs:21:37
42+
|
43+
LL | Ok(x) | Err(!) => println!("{x}"),
44+
| - ^^^ `x` used here but it is possibly-uninitialized
45+
| |
46+
| binding initialized here in some conditions
47+
| binding declared here but left uninitialized
48+
|
49+
= 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)
50+
51+
error[E0381]: used binding `x` is possibly-uninitialized
52+
--> $DIR/use-bindings.rs:25:37
53+
|
54+
LL | Err(!) | Ok(x) => println!("{x}"),
55+
| - ^^^ `x` used here but it is possibly-uninitialized
56+
| |
57+
| binding initialized here in some conditions
58+
| binding declared here but left uninitialized
59+
|
60+
= 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)
61+
62+
error[E0381]: used binding `x` is possibly-uninitialized
63+
--> $DIR/use-bindings.rs:31:50
64+
|
65+
LL | Ok(Ok(x) | Err(!)) | Err(!) => println!("{x}"),
66+
| - ^^^ `x` used here but it is possibly-uninitialized
67+
| |
68+
| binding initialized here in some conditions
69+
| binding declared here but left uninitialized
70+
|
71+
= 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)
72+
73+
error: aborting due to 6 previous errors
74+
75+
For more information about this error, try `rustc --explain E0381`.

0 commit comments

Comments
 (0)