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

Add optional messages to the unreachable macro. #18867

Merged
merged 1 commit into from
Nov 13, 2014
Merged

Add optional messages to the unreachable macro. #18867

merged 1 commit into from
Nov 13, 2014

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