Skip to content

Eliminate some buggy unreachable!()s in expand_[option_]env()#159940

Open
bal-e wants to merge 2 commits into
rust-lang:mainfrom
bal-e:env-macro-unreachables
Open

Eliminate some buggy unreachable!()s in expand_[option_]env()#159940
bal-e wants to merge 2 commits into
rust-lang:mainfrom
bal-e:env-macro-unreachables

Conversation

@bal-e

@bal-e bal-e commented Jul 26, 2026

Copy link
Copy Markdown

These unreachable!()s had misleading messages (the value they were extracting was not produced by expr_to_string()) and one of them could be triggered, see #159939. It turns out the value being extracted wasn't necessary at all, it was already computed elsewhere, so (aside from the added test case) it's a reduction in code.

Closes #159939. Adds a test case for it too.

Commits can be reviewed individually.

I've added the expected stderr (computed using the fixed version of
the code). As of *this* commit, the last line causes an ICE.
@rustbot rustbot added A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 26, 2026
@rustbot

rustbot commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @dingxiangfei2009 (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue
Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 74 candidates
  • Random selection from 16 candidates

@rust-log-analyzer

This comment has been minimized.

@bal-e
bal-e force-pushed the env-macro-unreachables branch from 17024a1 to 613074a Compare July 26, 2026 05:36
@rust-log-analyzer

This comment has been minimized.

@bal-e
bal-e force-pushed the env-macro-unreachables branch from 613074a to 1a53575 Compare July 26, 2026 07:47
@bal-e

bal-e commented Jul 26, 2026

Copy link
Copy Markdown
Author

Sorry about the spam, I should have checked the remaining tests. tests/ui passes locally now.

The right symbol is already available as `var`, extracted post macro
expansion; just use that directly.

I have also restructured the `expand_env()` control flow now that there
is less shared code, reducing indentation. The primary change there is
to use `var` instead of `*symbol`.

`var` contains the unescaped name (whereas `symbol` used to store the
contents of the original string literal), so `.escape_debug()` is used
to re-escape it. The escaping no longer depends on the exact string
literal used in the user input, which is quite nice IMO. This required
storing `String`s in the diagnostics instead of `Symbol`s.

I have added a FIXME to note the accidental double macro expansion
occurring in `expand_env()`. It is not a problem, per se, just something
that could be cleaned up in the future.
@bal-e
bal-e force-pushed the env-macro-unreachables branch from 1a53575 to 4f5f05f Compare July 26, 2026 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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.

[ICE]: option_env! + nested macro + non-unicode value hits unreachable!()

4 participants