Skip to content

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

Open
chenyukang wants to merge 1 commit intorust-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 intorust-lang:mainfrom
chenyukang:yukang-fix-154247-unused-braces-temp-scope-lite

Conversation

@chenyukang
Copy link
Copy Markdown
Member

@chenyukang chenyukang commented Mar 25, 2026

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
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 25, 2026

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.

Copy link
Copy Markdown
Member

@fmease fmease left a comment

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
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 19, 2026

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.

@chenyukang
Copy link
Copy Markdown
Member Author

@rustbot ready

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.

unused_braces warning emitted for braces that have semantic value

4 participants