Unhelpful diagnostic when casting a tuple-like enum to an int #120756
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
D-confusing
Diagnostics: Confusing error or lint that should be reworked.
D-newcomer-roadblock
Diagnostics: Confusing error or lint; hard to understand for new users.
D-terse
Diagnostics: An error or lint that doesn't give enough information about the problem at hand.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Code
Current output
Desired output
Possibly link to the Rust Reference where this is explained in detail. https://doc.rust-lang.org/reference/items/enumerations.html#casting
Rationale and extra context
Casting an enum to an int is common for C developers. When I searched the internet for guides on how to do this in Rust, they all essentially said it just works like
foo as i32
. E.g. stackoverflow, rust by example.These guides don't explicitly say that this only works if all of the enum variants are unit-like. The compiler message in this situation did not help me to understand what had gone wrong, and googling for it and "enum" returned the same sort of results as mentioned above.
Other cases
No response
Rust Version
Anything else?
No response
The text was updated successfully, but these errors were encountered: