Skip to content

Skip linting unused braces for FunctionArg and MethodArg context for 2024 later #154373

Open
chenyukang wants to merge 1 commit into
rust-lang:mainfrom
chenyukang:yukang-fix-154247-unused-braces-temp-scope-lite
Open

Skip linting unused braces for FunctionArg and MethodArg context for 2024 later #154373
chenyukang wants to merge 1 commit into
rust-lang:mainfrom
chenyukang:yukang-fix-154247-unused-braces-temp-scope-lite

Conversation

@chenyukang

@chenyukang chenyukang commented Mar 25, 2026

Copy link
Copy Markdown
Member

Fixes #154247

unused_braces is a AST level lint, but in Rust 2024 braces around function and method arguments can affect temporary drop scope.

I tried to find a more complete fix for it, but seems all too heavy, which involve AST visitor or need hir related stuff.

Instead of teaching this lint to reason about semantics, so it's better to stop linting those argument-position braces in 2024 later edition.

@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 Mar 25, 2026
@rustbot

rustbot commented Mar 25, 2026

Copy link
Copy Markdown
Collaborator

r? @fmease

rustbot has assigned @fmease.
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 69 candidates
  • Random selection from 11 candidates

@chenyukang chenyukang force-pushed the yukang-fix-154247-unused-braces-temp-scope-lite branch from 73c892b to e120f17 Compare March 26, 2026 14:18
@rustbot

This comment has been minimized.

@fmease fmease left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry for the delay!

I feel like some of the rules are too strict and it's also possible that there are still cases that might not be covered. I'm not an expert on temporary scopes, so I'll reassign.

r? dingxiangfei2009 or reassign

View changes since this review

Comment thread compiler/rustc_lint/src/unused.rs Outdated
is_kw: bool,
);

fn is_expr_simple_arg(expr: &ast::Expr) -> bool {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a very generic name for a very specific use case. "Simple argument" could mean vastly different things in different contexts. I think this should be renamed to something more specific.

Comment thread compiler/rustc_lint/src/unused.rs Outdated
Comment on lines +140 to +141
ast::ExprKind::Lit(_) | ast::ExprKind::Path(..) => true,
ast::ExprKind::Type(expr, _) => Self::is_expr_simple_arg(expr),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Surely more kinds of expressions qualify? Like possibly as-casting other "simple" exprs, arrays & tuples of other "simple" exprs and so on.

@rustbot rustbot assigned dingxiangfei2009 and unassigned fmease Apr 15, 2026
@chenyukang chenyukang force-pushed the yukang-fix-154247-unused-braces-temp-scope-lite branch from e120f17 to 14cc286 Compare April 19, 2026 08:20
@rustbot

This comment has been minimized.

@chenyukang

Copy link
Copy Markdown
Member Author

@rustbot ready

@Enselic

Enselic commented Jul 9, 2026

Copy link
Copy Markdown
Member

r? compiler

@rustbot rustbot assigned oli-obk and unassigned dingxiangfei2009 Jul 9, 2026
Comment thread compiler/rustc_lint/src/unused.rs Outdated
ast::ExprKind::Array(exprs) | ast::ExprKind::Tup(exprs) => {
exprs.iter().all(|expr| Self::is_arg_block_without_temp_scope_change(expr))
}
_ => false,

@oli-obk oli-obk Jul 9, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

exhaustively list them all and add almost all others to the "ok" list:

  • unary,unsafebindercast,includebytes
  • binary, index, range,
  • constblock, path,inlineasm, offsetof
  • if,while,forloop,loop,match,block
  • gen, closure, tryblock, try
  • use, await, break, ret, continue, yield, yeet
  • assign, assignop,
  • struct, repeat

View changes since the review

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 9, 2026
@chenyukang chenyukang force-pushed the yukang-fix-154247-unused-braces-temp-scope-lite branch from 14cc286 to 2e43946 Compare July 10, 2026 04:16
@rustbot

This comment has been minimized.

@chenyukang chenyukang force-pushed the yukang-fix-154247-unused-braces-temp-scope-lite branch from 2e43946 to 88aa4a9 Compare July 10, 2026 04:20
@rustbot

rustbot commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rust-log-analyzer

This comment has been minimized.

@chenyukang chenyukang force-pushed the yukang-fix-154247-unused-braces-temp-scope-lite branch from 88aa4a9 to 8e30f04 Compare July 10, 2026 04:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

unused_braces warning emitted for braces that have semantic value

7 participants