Skip to content

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

Closed

Description

@Reconcyl

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.

Activity

  1. added
    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and tools
    on Mar 30, 2019
  2. added
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    E-help-wantedCall for participation: Help is requested to fix this issue.
    on Mar 30, 2019
  3. DevQps commented on Apr 1, 2019

    @DevQps
    Contributor

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

  4. added 3 commits that reference this issue on Apr 15, 2019
    f247393
    c4871ad
    d9422f0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-enhancementCategory: An issue proposing an enhancement or a PR with one.E-help-wantedCall for participation: Help is requested to fix this issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions