Skip to content
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

Generate safe stable code for derives on empty enums #113770

Merged
merged 2 commits into from
Jul 17, 2023

Conversation

dtolnay
Copy link
Member

@dtolnay dtolnay commented Jul 16, 2023

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).

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`).
@rustbot
Copy link
Collaborator

rustbot commented Jul 16, 2023

r? @b-naber

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 16, 2023
@rustbot
Copy link
Collaborator

rustbot commented Jul 16, 2023

Changes to the code generated for builtin derived traits.

cc @nnethercote

@compiler-errors
Copy link
Member

very nice

r? @compiler-errors @bors r+

@bors
Copy link
Contributor

bors commented Jul 16, 2023

📌 Commit f441adc has been approved by compiler-errors

It is now in the queue for this repository.

@rustbot rustbot assigned compiler-errors and unassigned b-naber Jul 16, 2023
@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 16, 2023
@nnethercote
Copy link
Contributor

I was just about to request a tiny change.

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jul 16, 2023
// 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 {}`.
Copy link
Contributor

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

@bors
Copy link
Contributor

bors commented Jul 16, 2023

✌️ @dtolnay, you can now approve this pull request!

If @nnethercote told you to "r=me" after making some further change, please make that change, then do @bors r=@nnethercote

@dtolnay
Copy link
Member Author

dtolnay commented Jul 16, 2023

@bors r=compiler-errors,nnethercote

@bors
Copy link
Contributor

bors commented Jul 16, 2023

📌 Commit 56633b3 has been approved by compiler-errors,nnethercote

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 16, 2023
@nnethercote
Copy link
Contributor

@bors rollup

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 17, 2023
…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)
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 17, 2023
…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
@bors bors merged commit 93b9812 into rust-lang:master Jul 17, 2023
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants