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

Chore: prefer unreachable_unchecked in Cow::to_mut method #88608

Closed
wants to merge 1 commit into from
Closed

Chore: prefer unreachable_unchecked in Cow::to_mut method #88608

wants to merge 1 commit into from

Conversation

BastiDood
Copy link

As a small first step in #88606, this PR uses the core::hint::unreachable_unchecked function in place of the unreachable macro in the Cow::to_mut implementation. It should be fairly apparent that this is a safe assertion to make since self has just been assigned to the Owned variant. Thanks!

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @dtolnay (or someone else) soon.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 3, 2021
@hellow554
Copy link
Contributor

hellow554 commented Sep 3, 2021

As already said in the other thread, this actually doesn't change anything, because the compiler is smart enough to detect, that the branch won't be taken. See https://rust.godbolt.org/z/c75xv4df4 for a comparision

@BastiDood
Copy link
Author

...this actually doesn't change anything...

Thanks for taking the time to set up the Godbolt example! It's incredible how the compiler even removed the entire panic branch regardless. For the meantime, I'll be looking forward to the discussion in the original thread before resolving this PR. 👍

Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compilers are way better at this than humans are. Making the human do it, when the compiler is doing the same already, is not an improvement. That puts the maintainers now perpetually on the hook for absence of UB going forward, in the presence of changes to the surrounding code.

@dtolnay dtolnay closed this Sep 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants