Skip to content

unused_parens false positive in return position of Fn generics, when there is another path segment #143080

Open
@sodiboo

Description

@sodiboo

Code

type T = u8;

type A = Fn()->(T)::Y;
type B = Fn()->T::Y;

Current output

warning: unnecessary parentheses around type
 --> src/lib.rs:3:16
  |
3 | type A = Fn()->(T)::Y;
  |                ^ ^
  |
  = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
  |
3 - type A = Fn()->(T)::Y;
3 + type A = Fn()->T::Y;

Desired output

< nothing at all >

Rationale and extra context

The snippet is syntactically valid, and when generating HIR output, it contains no errors whatsoever, only this pesky warning that says to make the first line like the second.

But they are not equivalent, as the HIR output clearly shows:

#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;
type T = u8;

type A = <Fn() -> T>::Y;
type B = Fn() -> T::Y;

The errors emitted when trying to generate MIR output further demonstrate that these are very different things, and the parenthesis really do matter:

error[E0223]: ambiguous associated type
 --> src/lib.rs:3:10
  |
3 | type A = Fn()->(T)::Y;
  |          ^^^^^^^^^^^^
  |
help: if there were a trait named `Example` with associated type `Y` implemented for `(dyn Fn() -> u8 + 'static)`, you could use the fully-qualified path
  |
3 - type A = Fn()->(T)::Y;
3 + type A = <(dyn Fn() -> u8 + 'static) as Example>::Y;
  |

error[E0223]: ambiguous associated type
 --> src/lib.rs:4:16
  |
4 | type B = Fn()->T::Y;
  |                ^^^^
  |
help: if there were a trait named `Example` with associated type `Y` implemented for `u8`, you could use the fully-qualified path
  |
4 - type B = Fn()->T::Y;
4 + type B = Fn()-><u8 as Example>::Y;

Rust Version

rustc 1.90.0-nightly (b03b3a7ec 2025-06-26)
binary: rustc
commit-hash: b03b3a7ec92682be2917540b679478d41c95a30c
commit-date: 2025-06-26
host: x86_64-unknown-linux-gnu
release: 1.90.0-nightly
LLVM version: 20.1.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.L-false-positiveLint: False positive (should not have fired).L-unused_parensLint: unused_parensP-lowLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions