Skip to content

unused_parens: False positive on parenthesized type-relative paths that would otherwise be interpreted as the start of a generic param list (impl<T>, for<T>, where<T>) #107235

@kadiwa4

Description

@kadiwa4

Code

struct Something;
impl (<Something>::Item) {}

Current output

warning: unnecessary parentheses around type
 --> src/lib.rs:2:6
  |
2 | impl (<Something>::Item) {}
  |      ^                 ^
  |
  = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
  |
2 - impl (<Something>::Item) {}
2 + impl <Something>::Item {}
  |

error[E0223]: ambiguous associated type
 --> src/lib.rs:2:7
  |
2 | impl (<Something>::Item) {}
  |       ^^^^^^^^^^^^^^^^^ help: use the fully-qualified path: `<Something as IntoIterator>::Item`

For more information about this error, try `rustc --explain E0223`.
warning: `playground` (lib) generated 1 warning
error: could not compile `playground` (lib) due to previous error; 1 warning emitted

on rustc nightly 2023-07-29

Desired output

Same thing without the unused_parens warning.

Rationale and extra context

Without the parentheses, it would be equivalent to

impl<Something> ::Item {}

Note that Something is now a generic type and ::Item is a standalone item path.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions