Skip to content

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

Closed
@chris-morgan

Description

@chris-morgan

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions