Skip to content

Commit 921c1da

Browse files
committed
tag-variant-cast-non-nullary
1 parent aaabaac commit 921c1da

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

tests/ui/cast/cast-enum-to-primitive-error.fixed

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
//! This test verifies that a direct non-primitive cast from an enum to an integer type
2+
//! is correctly disallowed, even when a `From` implementation exists for that enum.
3+
//! It specifically checks for the `E0605` error ("non-primitive cast: `Enum` as `Primitive`")
4+
//! and confirms that `rustfix` can suggest an appropriate correction (e.g., using `into()`).
5+
16
//@ run-rustfix
7+
28
#![allow(dead_code, unused_variables)]
9+
310
enum NonNullary {
411
Nullary,
512
Other(isize),

tests/ui/cast/cast-enum-to-primitive-error.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
//! This test verifies that a direct non-primitive cast from an enum to an integer type
2+
//! is correctly disallowed, even when a `From` implementation exists for that enum.
3+
//! It specifically checks for the `E0605` error ("non-primitive cast: `Enum` as `Primitive`")
4+
//! and confirms that `rustfix` can suggest an appropriate correction (e.g., using `into()`).
5+
16
//@ run-rustfix
7+
28
#![allow(dead_code, unused_variables)]
9+
310
enum NonNullary {
411
Nullary,
512
Other(isize),

tests/ui/cast/cast-enum-to-primitive-error.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0605]: non-primitive cast: `NonNullary` as `isize`
2-
--> $DIR/tag-variant-cast-non-nullary.rs:19:15
2+
--> $DIR/cast-enum-to-primitive-error.rs:26:15
33
|
44
LL | let val = v as isize;
55
| ^^^^^^^^^^ an `as` expression can be used to convert enum types to numeric types only if the enum type is unit-only or field-less

0 commit comments

Comments
 (0)