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

Confusing wording in documentation for std::hint::unreachable_unchecked() #59549

Closed
Reconcyl opened this issue Mar 30, 2019 · 1 comment · Fixed by #59717
Closed

Confusing wording in documentation for std::hint::unreachable_unchecked() #59549

Reconcyl opened this issue Mar 30, 2019 · 1 comment · Fixed by #59717
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools C-enhancement Category: An issue proposing an enhancement or a PR with one. E-help-wanted Call for participation: Help is requested to fix this issue.

Comments

@Reconcyl
Copy link

The documentation for std::hint::unreachable_unchecked() mentions two ways that it can affect a program:

  1. It can enable the compiler to make optimizations based on the assumption that the function will never be executed.
  2. If the function actually is executed, its behavior is undefined.

It then goes on to mention the unreachable!() macro, saying

The unreachable!() macro is the safe counterpart of this function, which will panic instead when executed.

This statement could be read as addressing the 2nd effect, but not the 1st. In other words, it could be interpreted as saying "the compiler will assume that unreachable!() will never be executed, but in the event that it is it will cause a panic." It might be worth rewording this statement to make it clear that neither (1) nor (2) applies to the safe version.

@Centril Centril added the A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools label Mar 30, 2019
@frewsxcv frewsxcv assigned frewsxcv and unassigned frewsxcv Mar 30, 2019
@jonas-schievink jonas-schievink added C-enhancement Category: An issue proposing an enhancement or a PR with one. E-help-wanted Call for participation: Help is requested to fix this issue. labels Mar 30, 2019
@DevQps
Copy link
Contributor

DevQps commented Apr 1, 2019

@Reconcyl Would you like to rephrase this yourself, or would you like me to take an attempt?

Centril added a commit to Centril/rust that referenced this issue Apr 15, 2019
improve docs for std::hint::unreachable_unchecked()

Fixes rust-lang#59549
Centril added a commit to Centril/rust that referenced this issue Apr 16, 2019
improve docs for std::hint::unreachable_unchecked()

Fixes rust-lang#59549
Centril added a commit to Centril/rust that referenced this issue Apr 16, 2019
improve docs for std::hint::unreachable_unchecked()

Fixes rust-lang#59549
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools C-enhancement Category: An issue proposing an enhancement or a PR with one. E-help-wanted Call for participation: Help is requested to fix this issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants