Skip to content

Commit 2c0d2f9

Browse files
committed
Add test for uninhabited std::mem::uninitialized uses.
1 parent d8e8e17 commit 2c0d2f9

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

tests/ui/uninhabited/void-branch.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#![deny(unreachable_code)]
2+
#![allow(deprecated, invalid_value)]
3+
4+
enum Void {}
5+
6+
fn with_void() {
7+
if false {
8+
unsafe {
9+
//~^ ERROR unreachable expression
10+
std::mem::uninitialized::<Void>();
11+
}
12+
}
13+
14+
println!();
15+
}
16+
17+
fn infallible() -> std::convert::Infallible {
18+
loop {}
19+
}
20+
21+
fn with_infallible() {
22+
if false {
23+
//~^ ERROR unreachable expression
24+
infallible();
25+
}
26+
27+
println!()
28+
}
29+
30+
fn main() {}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
error: unreachable expression
2+
--> $DIR/void-branch.rs:8:9
3+
|
4+
LL | / unsafe {
5+
LL | |
6+
LL | | std::mem::uninitialized::<Void>();
7+
| | --------------------------------- any code following this expression is unreachable
8+
LL | | }
9+
| |_________^ unreachable expression
10+
|
11+
note: this expression has type `Void`, which is uninhabited
12+
--> $DIR/void-branch.rs:10:13
13+
|
14+
LL | std::mem::uninitialized::<Void>();
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16+
note: the lint level is defined here
17+
--> $DIR/void-branch.rs:1:9
18+
|
19+
LL | #![deny(unreachable_code)]
20+
| ^^^^^^^^^^^^^^^^
21+
22+
error: unreachable expression
23+
--> $DIR/void-branch.rs:22:14
24+
|
25+
LL | if false {
26+
| ______________^
27+
LL | |
28+
LL | | infallible();
29+
| | ------------ any code following this expression is unreachable
30+
LL | | }
31+
| |_____^ unreachable expression
32+
|
33+
note: this expression has type `Infallible`, which is uninhabited
34+
--> $DIR/void-branch.rs:24:9
35+
|
36+
LL | infallible();
37+
| ^^^^^^^^^^^^
38+
39+
error: aborting due to 2 previous errors
40+

0 commit comments

Comments
 (0)