Skip to content

Fix invalid special casing of the unreachable! macro#93179

Merged
bors merged 2 commits intorust-lang:masterfrom
Urgau:unreachable-2021
Feb 7, 2022
Merged

Fix invalid special casing of the unreachable! macro#93179
bors merged 2 commits intorust-lang:masterfrom
Urgau:unreachable-2021

Conversation

@Urgau
Copy link
Member

@Urgau Urgau commented Jan 21, 2022

This pull-request fix an invalid special casing of the unreachable! macro in the same way the panic! macro was solved, by adding two new internal only macros unreachable_2015 and unreachable_2021 edition dependent and turn unreachable! into a built-in macro that do dispatching. This logic is stolen from the panic! macro.

This pull-request also adds an internal feature format_args_capture_non_literal that allows capturing arguments from formatted string that expanded from macros. The original RFC #2795 mentioned this as a future possibility. This feature is required because of concatenation that needs to be done inside the macro:

$crate::concat!("internal error: entered unreachable code: ", $fmt)

In summary the new behavior for the unreachable! macro with this pr is:

Edition 2021:

let x = 5;
unreachable!("x is {x}");
internal error: entered unreachable code: x is 5

Edition <= 2018:

let x = 5;
unreachable!("x is {x}");
internal error: entered unreachable code: x is {x}

Also note that the change in this PR are insta-stable and breaking changes but this a considered as being a bug.
If someone could start a perf run and then a crater run this would be appreciated.

Fixes #92137

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beta-accepted Accepted for backporting to the compiler in the beta channel. merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. relnotes Marks issues that should be documented in the release notes of the next release. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unreachable!("{}") works on Rust 2021