`unused_parens` false positive in return position of `Fn` generics, when there is another path segment
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the example in src/lib.rs and compare the HIR output for types A and B, then inspect the unused_parens warning and the MIR errors shown in the report. Done means the valid code no longer emits the incorrect warning while the distinction between the parenthesized and unparenthesized forms remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100