Skip to content

unused_braces warning emitted for braces that have semantic value #154247

@cartercanedy

Description

@cartercanedy

Summary

Since the adoption of tail expression temporary scope changes in the 2024 edition, it is safe to wrap a method call on a temporary lock guard in a block with assurance that the lock will be dropped before exiting the scope. It seems like this lint is either being emitted in error (false positive) or the other, very similar expression in the same file is not being detected (false negative).

Lint Name

unused_braces

Reproducer

Diagnostic emitted by rustc:

warning: unnecessary braces around method argument
   --> .../file.rs:459:29
    |
459 |         self.update({ self.lockable.lock().do_work()?.collect() })
    |                     ^^                                         ^^
    |
    = note: `#[warn(unused_braces)]` on by default
help: remove these braces
    |
459 -         self.update({ self.lockable.lock().do_work()?.collect() })
459 +         self.update(self.lockable.lock().do_work()?.collect())

There's a similar implementation in an impl block right below this that does not have this lint emitted

Version

rustc 1.96.0-nightly (562dee482 2026-03-21)
binary: rustc
commit-hash: 562dee4820c458d823175268e41601d4c060588a
commit-date: 2026-03-21
host: aarch64-apple-darwin
release: 1.96.0-nightly
LLVM version: 22.1.0

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.L-false-positiveLint: False positive (should not have fired).L-unused_bracesLint: unused_bracesT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions