Skip to content

False positive warning in unused_parens lint with dyn Trait returned from a closure #143653

@alexcrichton

Description

@alexcrichton

Code

I tried this code:

#![deny(unused_parens)]
#![allow(warnings)]
trait MyTrait {}

fn foo(_: Box<dyn FnMut(&mut u32) -> &mut (dyn MyTrait) + Send + Sync>) {}

fn main() {}

I expected compile with no warnings, but instead, the current nightly yields:

error: unnecessary parentheses around type
 --> src/main.rs:5:43
  |
5 | fn foo(_: Box<dyn FnMut(&mut u32) -> &mut (dyn MyTrait) + Send + Sync>) {}
  |                                           ^           ^
  |
note: the lint level is defined here
 --> src/main.rs:1:9
  |
1 | #![deny(unused_parens)]
  |         ^^^^^^^^^^^^^
help: remove these parentheses
  |
5 - fn foo(_: Box<dyn FnMut(&mut u32) -> &mut (dyn MyTrait) + Send + Sync>) {}
5 + fn foo(_: Box<dyn FnMut(&mut u32) -> &mut dyn MyTrait + Send + Sync>) {}
  |

error: aborting due to 1 previous error

Version with regression

Bisecting via cargo-bisect-rustc yields:

searched nightlies: from nightly-2025-07-02 to nightly-2025-07-08
regressed nightly: nightly-2025-07-04
searched commit range: 6677875...da58c05
regressed commit: 25face9

bisected with cargo-bisect-rustc v0.6.10

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc

where my guess is that #142237 is the cause (cc @benschulz as the author)

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.I-prioritizeIssue: Indicates that prioritization has been requested for this issue.L-false-positiveLint: False positive (should not have fired).L-unused_parensLint: unused_parensT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-untriagedUntriaged performance or correctness regression.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions