-
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
Can't implement Copy for C style enums with negative discriminants that overflow into unspecified positive discriminants #23221
Comments
Providing an explicit discriminant for the variant after the fn main() { }
#[repr(C)]
#[derive(Copy)]
enum X {
A = -1,
B = 0,
} |
The same happens without repr(C) or with repr(i32). |
Also, |
@pnkfelix: The error message shows that it's about overflowing discriminants. There is nothing special about -1. |
@mahkoh my point is that the bug is not observed by all negative discriminants. But whatever, I'm not interested in fighting over how the title is phrased. |
In any case the previous title was wrong because this works fine: fn main() { }
//#[repr(C)]
enum _X {
A = -1,
}
impl Copy for _X { } |
cc #23897 |
…values. Moved such overflow checking into one place (in `rustc::middle::ty`, since it needs to be run on-demand during `const_eval` in some scenarios), and revised `rustc_typeck` accordingly. (Note that we only check for overflow if program did not provide a discriminant value explicitly.) Fix rust-lang#23030 Fix rust-lang#23221 Fix rust-lang#23235
…values. Moved such overflow checking into one place (in `rustc::middle::ty`, since it needs to be run on-demand during `const_eval` in some scenarios), and revised `rustc_typeck` accordingly. (Note that we only check for overflow if program did not provide a discriminant value explicitly.) Fix rust-lang#23030 Fix rust-lang#23221 Fix rust-lang#23235
const_eval : add overflow-checking for {`+`, `-`, `*`, `/`, `<<`, `>>`}. One tricky detail here: There is some duplication of labor between `rustc::middle::const_eval` and `rustc_trans::trans::consts`. It might be good to explore ways to try to factor out the common structure to the two passes (by abstracting over the particular value-representation used in the compile-time interpreter). ---- Update: Rebased atop rust-lang#23841 Fix rust-lang#22531 Fix rust-lang#23030 Fix rust-lang#23221 Fix rust-lang#23235
The text was updated successfully, but these errors were encountered: