Skip to content

Tweak error for stmt macro expansion in expression context - #161035

Open
estebank wants to merge 1 commit into
rust-lang:mainfrom
estebank:issue-30597
Open

Tweak error for stmt macro expansion in expression context#161035
estebank wants to merge 1 commit into
rust-lang:mainfrom
estebank:issue-30597

Conversation

@estebank

@estebank estebank commented Aug 13, 2026

Copy link
Copy Markdown
Contributor
  • Use a multipart suggestion
  • When encountering a stmt metavariable where an expression is expected in another macro expansion, do not suggest a stray ;

Fix #30597.

- Use a multipart suggestion
- When encountering a `stmt` metavariable where an expression is expected in another macro expansion, do not suggest a stray `;`
@rustbot rustbot added 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 Aug 13, 2026
@rustbot

rustbot commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

r? @dingxiangfei2009

rustbot has assigned @dingxiangfei2009.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

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

@estebank estebank changed the title Tweak stmt macro expansion in expression context Tweak error for stmt macro expansion in expression context Aug 13, 2026
Comment on lines +12 to +15
help: surround the macro invocation with `{}` to interpret the expansion as a statement
|
LL | println!("{}", { foo!(42); });
| + +++

@estebank estebank Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not 100% sure that we want to provide this suggestion. It is valid in that it produces syntactically correct code, but then the resulting () will likely be completely useless for the println.

View changes since the review

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

Labels

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.

bad diagnostic when macro tries to use stmt as expr

3 participants