Skip to content

Commit a067c6a

Browse files
committed
refactor unreachable/expr_cast.rs test
1 parent 4b55fe1 commit a067c6a

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

tests/ui/reachable/expr_cast.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
#![allow(unused_variables)]
2-
#![allow(unused_assignments)]
3-
#![allow(dead_code)]
1+
//@ edition: 2024
42
#![deny(unreachable_code)]
5-
#![feature(never_type, type_ascription)]
63

74
fn a() {
8-
// the cast is unreachable:
9-
let x = {return} as !; //~ ERROR unreachable
10-
//~| ERROR non-primitive cast
5+
_ = {return} as u32; //~ error: unreachable
116
}
127

13-
fn main() { }
8+
fn b() {
9+
(return) as u32; //~ error: unreachable
10+
}
11+
12+
fn main() {}

tests/ui/reachable/expr_cast.stderr

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
error: unreachable expression
2-
--> $DIR/expr_cast.rs:9:13
2+
--> $DIR/expr_cast.rs:5:9
33
|
4-
LL | let x = {return} as !;
5-
| ^------^^^^^^
6-
| ||
7-
| |any code following this expression is unreachable
8-
| unreachable expression
4+
LL | _ = {return} as u32;
5+
| ^------^^^^^^^^
6+
| ||
7+
| |any code following this expression is unreachable
8+
| unreachable expression
99
|
1010
note: the lint level is defined here
11-
--> $DIR/expr_cast.rs:4:9
11+
--> $DIR/expr_cast.rs:2:9
1212
|
1313
LL | #![deny(unreachable_code)]
1414
| ^^^^^^^^^^^^^^^^
1515

16-
error[E0605]: non-primitive cast: `()` as `!`
17-
--> $DIR/expr_cast.rs:9:13
16+
error: unreachable expression
17+
--> $DIR/expr_cast.rs:9:5
1818
|
19-
LL | let x = {return} as !;
20-
| ^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
19+
LL | (return) as u32;
20+
| --------^^^^^^^
21+
| |
22+
| unreachable expression
23+
| any code following this expression is unreachable
2124

2225
error: aborting due to 2 previous errors
2326

24-
For more information about this error, try `rustc --explain E0605`.

0 commit comments

Comments
 (0)