Skip to content

Replace std::util::unreachable with a macro #8991

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

Closed
chris-morgan opened this issue Sep 5, 2013 · 0 comments · Fixed by #9320
Closed

Replace std::util::unreachable with a macro #8991

chris-morgan opened this issue Sep 5, 2013 · 0 comments · Fixed by #9320

Comments

@chris-morgan
Copy link
Member

Rationale

  • You get better errors on account of the fail!() expansion evaluating file!() and line!() in the caller rather than inside the unreachable function.
  • You don't need to import something to get it, which means people are more likely to use unreachable!() when that is semantically what is intended, which makes the intent of code (and the errors in case of incorrectness of the unreachable assertion) much more obvious (at present it's distinctly easier to simply write fail!()).

Demonstration

With a function

fn main() {
    ::std::util::unreachable();
}
task <unnamed> failed at 'internal error: entered unreachable code', /home/chris/vc/rust/src/libstd/util.rs:132

With a macro

fn main() {
    unreachable!();
}
task <unnamed> failed at 'internal error: entered unreachable code', myfile.rs:2
chris-morgan added a commit to chris-morgan/rust that referenced this issue Sep 5, 2013
Rationale: having a function which fails means that the location of
failure which is output is that of the unreachable() function, rather
than the caller.

This is part of rust-lang#8991 but is not all of it; current usage of
``std::util::unreachable()`` must remain so for the moment, until a new
snapshot is made; then I will remove that function entirely in favour of
using this macro.
bors added a commit that referenced this issue Sep 5, 2013
Rationale: having a function which fails means that the location of
failure which is output is that of the unreachable() function, rather
than the caller.

This is part of #8991 but is not all of it; current usage of
``std::util::unreachable()`` must remain so for the moment, until a new
snapshot is made; then I will remove that function entirely in favour of
using this macro.
bors added a commit that referenced this issue Sep 20, 2013
…-two-containing-the-destruction-of-the-unreachable-function, r=alexcrichton

This is the second of two parts of #8991, now possible as a new snapshot
has been made. (The first part implemented the unreachable!() macro; it
was #8992, 6b7b8f2.)

``std::util::unreachable()`` is removed summarily; any code which used
it should now use the ``unreachable!()`` macro.

Closes #9312.

Closes #8991.
@bors bors closed this as completed in e2807a4 Sep 20, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant