Skip to content

Avoid unused braces lint for macro generated arguments#158791

Open
chenyukang wants to merge 1 commit into
rust-lang:mainfrom
chenyukang:yukang-fix-158747-unused-braces-macro
Open

Avoid unused braces lint for macro generated arguments#158791
chenyukang wants to merge 1 commit into
rust-lang:mainfrom
chenyukang:yukang-fix-158747-unused-braces-macro

Conversation

@chenyukang

@chenyukang chenyukang commented Jul 5, 2026

Copy link
Copy Markdown
Member

Fixes #158747

This changes the unused_braces lint to avoid suggesting brace removal for macro arguments when those braces may affect macro_rules!.

But the fragment kind matters:

  • $e:expr matches an expression. Both 1 and { 1 } are expressions, so removing braces can still leave the macro matching the same kind of input.
  • $b:block only matches a block expression written with braces. { 1 } matches, but 1 does not.

So call_expr!({ 1 }) can usually be simplified to call_expr!(1), while call_block!({ 1 }) cannot.

It seems a more concrect report need a full macro_rules! matcher analysis, that seems too heavy for unused lint.

@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 Jul 5, 2026
@rustbot

rustbot commented Jul 5, 2026

Copy link
Copy Markdown
Collaborator

r? @folkertdev

rustbot has assigned @folkertdev.
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 21 candidates

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.

#[warn(unused_braces)] false positive for macro that accepts types and expressions and forwards them to a function

3 participants