-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Generate safe stable code for derives on empty enums #113770
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
Conversation
Generate `match *self {}` instead of `unsafe { core::intrinsics::unreachable() }`. This is: 1. safe 2. stable for the benefit of everyone looking at these derived impls through `cargo expand`. Both expansions compile to the same code at all optimization levels (including `0`).
r? @b-naber (rustbot has picked a reviewer for you, use r? to override) |
Changes to the code generated for builtin derived traits. cc @nnethercote |
very nice r? @compiler-errors @bors r+ |
I was just about to request a tiny change. @bors r- |
// There is no sensible code to be generated for *any* deriving on a | ||
// zero-variant enum. So we just generate a failing expression. | ||
// For zero-variant enum, this function body is unreachable. | ||
// Generate `match *self {}`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add something like this: "This results in the same generated code as unsafe { core::intrinsics::unreachable() }
while also being safe and stable."
Thanks.
@bors delegate=dtolnay
✌️ @dtolnay, you can now approve this pull request! If @nnethercote told you to " |
@bors r=compiler-errors,nnethercote |
@bors rollup |
…ors,nnethercote Generate safe stable code for derives on empty enums Generate `match *self {}` instead of `unsafe { core::intrinsics::unreachable() }`. This is: 1. safe 2. stable for the benefit of everyone looking at these derived impls through `cargo expand`. [Both expansions compile to the same code at all optimization levels (including `0`).](https://rust.godbolt.org/z/P79joGMh3)
…iaskrgr Rollup of 4 pull requests Successful merges: - rust-lang#112741 (fix typo in `rustdoc/src/what-is-rustdoc.md`) - rust-lang#113535 (Add a sparc-unknown-none-elf target.) - rust-lang#113651 (self type param infer, avoid ICE) - rust-lang#113770 (Generate safe stable code for derives on empty enums) r? `@ghost` `@rustbot` modify labels: rollup
Generate
match *self {}
instead ofunsafe { core::intrinsics::unreachable() }
.This is:
for the benefit of everyone looking at these derived impls through
cargo expand
.Both expansions compile to the same code at all optimization levels (including
0
).