Skip to content

fix unused_braces suggestion for wildcard assignment#158011

Open
pbkx wants to merge 1 commit into
rust-lang:mainfrom
pbkx:issue-116536-unused-braces-wildcard-assignment
Open

fix unused_braces suggestion for wildcard assignment#158011
pbkx wants to merge 1 commit into
rust-lang:mainfrom
pbkx:issue-116536-unused-braces-wildcard-assignment

Conversation

@pbkx

@pbkx pbkx commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Fixes #116536.

The unused_braces lint could suggest removing braces from wildcard assignments like:

_ = { e };

producing:

_ = e;

These are not equivalent: _ = { e }; moves/drops e, while _ = e; does not. This PR suppresses unused_braces for assignment RHS blocks when the assignment LHS contains _.

ui regression test covers both the simple wildcard assignment case and a tuple destructuring assignment case

@rustbot rustbot added 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. labels Jun 17, 2026
@pbkx
pbkx marked this pull request as ready for review June 17, 2026 10:09
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 17, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jun 17, 2026
@rustbot

rustbot commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

r? @TaKO8Ki

rustbot has assigned @TaKO8Ki.
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 73 candidates
  • Random selection from 21 candidates

@TaKO8Ki TaKO8Ki 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.

Thank you. I left one comment.

View changes since this review


Assign(_, ref value, _) | AssignOp(.., ref value) => {
Assign(ref lhs, ref value, _) => {
let ctx = if expr_contains_underscore(lhs) {

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.

I think this lint should not be triggered in some other cases like (..) = { e } [..] = { e }. Can we address them here as well?

#![deny(unused_braces)]

struct D(&'static str);

impl Drop for D {
    fn drop(&mut self) {
        println!("drop {}", self.0);
    }
}

fn main() {
    let e = (D("a"), D("b"));
    (..) = { e };
}

@rust-bors

rust-bors Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #158720) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.

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 false positive with assignment to wildcard

3 participants