Skip to content

Conversation

@michaelsproul
Copy link
Contributor

Closes #18842.

@michaelsproul
Copy link
Contributor Author

As brought up by @bstrie in #18842, having the option to print a message when unreachable code runs can be useful, particularly when tweaking existing code.

You can now do:

unreachable!();
unreachable!("oh no!");
unreachable!("wow, formatting: {}", 7);

Corresponding output:

internal error: entered unreachable code
internal error: entered unreachable code: oh no!
internal error: entered unreachable code: wow, formatting: 7

Calling the macro without an argument preserves the current behaviour.

bors added a commit that referenced this pull request Nov 13, 2014
@bors bors closed this Nov 13, 2014
@bors bors merged commit 837dd14 into rust-lang:master Nov 13, 2014
@michaelsproul michaelsproul deleted the unreachable-formatting branch January 16, 2015 00:39
lnicola pushed a commit to lnicola/rust that referenced this pull request Jan 7, 2025
internal: target-triple -> target-tuple + version fetching cleanup
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 this pull request may close these issues.

Add an optional string parameter to the unreachable!() macro to communicate which invariant was violated

2 participants