-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enum discriminants have problems with const_eval
and truncation
#9837
Comments
One possibility: if we can read out the type inferred by |
Visiting for triage, the above example no longer compiles:
I'm not familiar enough with the details to be able to come up with a newer example. |
Triage: wow, I used to be a noob :)
This now error swith:
So it seems like this is still an issue? |
marking as 'typesystem' because it would seem like a |
I thought the |
@steveklabnik That example uses a const S: i16 = 0x12345678;
enum E { V = S as isize }
fn main() { assert_eq!(S as u64, E::V as u64); } And it still panics with the error in the original post (so this is still an issue). |
cc #23897 |
This is fixed in nightly. |
Err, wait, nevermind, wrong bug; sorry about the noise. |
note that this has a warning now:
|
The warning definitely helps, but here's an interesting variation: const C1: i32 = 0x12345678;
const C2: isize = C1 as i16 as isize;
enum E { V = C2 }
fn main() { assert_eq!(C2 as u64, E::V as u64); } No warnings on stable or nightly, but still panics. |
I cannot reproduce the panic on nightly. |
Added a regression test in #36566. |
Add regression test for rust-lang#9837. Fixes rust-lang#9837
fix never_loop false positive fixes rust-lang#9831 changelog: [`never_loop`]: fixed false positive on unconditional break in internal labeled block
`never_loop`: don't emit AlwaysBreaks if it targets a block ref: rust-lang/rust-clippy#9837 (comment) The previous fix (rust-lang#9837) was too simple and ignored all break commands inside a labelled block, regardless of whether their destination was a labelled block or a loop. This fix tracks all the labelled blocks in scope to ensure that only breaks targeting loops are considered. changelog: [`never_loop`]: prevent false negatives from `breaks` nested in labelled blocks
Result:
Currently blocking #9613, because 32-bit
std::int::min_value
is0xffffffff7fffffff
(if you use all the bits of theconst_eval
result and not just the low 32) and so the discriminant is auto-sized tou64
, meaning that0x7fffffff
does not match any of its variants.I'm thinking that
check_enum_variants
needs to do whateverconst_eval
would do if the expression had anas u64
around it.The text was updated successfully, but these errors were encountered: