refactor unreachable/expr_cast.rs test

This commit is contained in:
Waffle Lapkin 2025-06-01 12:51:17 +02:00
parent 4b55fe199c
commit a067c6a3c6
No known key found for this signature in database
2 changed files with 21 additions and 20 deletions

View File

@ -1,13 +1,12 @@
#![allow(unused_variables)]
#![allow(unused_assignments)]
#![allow(dead_code)]
//@ edition: 2024
#![deny(unreachable_code)]
#![feature(never_type, type_ascription)]
fn a() {
// the cast is unreachable:
let x = {return} as !; //~ ERROR unreachable
//~| ERROR non-primitive cast
_ = {return} as u32; //~ error: unreachable
}
fn main() { }
fn b() {
(return) as u32; //~ error: unreachable
}
fn main() {}

View File

@ -1,24 +1,26 @@
error: unreachable expression
--> $DIR/expr_cast.rs:9:13
--> $DIR/expr_cast.rs:5:9
|
LL | let x = {return} as !;
| ^------^^^^^^
| ||
| |any code following this expression is unreachable
| unreachable expression
LL | _ = {return} as u32;
| ^------^^^^^^^^
| ||
| |any code following this expression is unreachable
| unreachable expression
|
note: the lint level is defined here
--> $DIR/expr_cast.rs:4:9
--> $DIR/expr_cast.rs:2:9
|
LL | #![deny(unreachable_code)]
| ^^^^^^^^^^^^^^^^
error[E0605]: non-primitive cast: `()` as `!`
--> $DIR/expr_cast.rs:9:13
error: unreachable expression
--> $DIR/expr_cast.rs:9:5
|
LL | let x = {return} as !;
| ^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
LL | (return) as u32;
| --------^^^^^^^
| |
| unreachable expression
| any code following this expression is unreachable
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0605`.