Skip to content

unused_parens: higher ranked self type in where bounds is incorrectly handled #104397

Closed
@lcnr

Description

@lcnr
struct Inv<'a>(&'a mut &'a ());

trait Trait {}
impl Trait for for<'a> fn(Inv<'a>) {}


fn with_bound()
where
    (for<'a> fn(Inv<'a>)): Trait,
{}

fn main() {
    with_bound();
}

results in the following lint:

warning: unnecessary parentheses around type
 --> src/main.rs:9:5
  |
9 |     (for<'a> fn(Inv<'a>)): Trait,
  |     ^                   ^
  |
  = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
  |
9 -     (for<'a> fn(Inv<'a>)): Trait,
9 +     for<'a> fn(Inv<'a>): Trait,
  |

following the lint results in a compiler error however:

error: implementation of `Trait` is not general enough
  --> src/main.rs:13:5
   |
13 |     with_bound();
   |     ^^^^^^^^^^^^ implementation of `Trait` is not general enough
   |
   = note: `for<'a> fn(Inv<'a>)` must implement `Trait`, for any lifetime `'0`...
   = note: ...but `Trait` is actually implemented for the type `for<'a> fn(Inv<'a>)`

By removing the parens this gets parsed as for<'a> (fn(Inv<'a>): Trait) instead of the original (for<'a> fn(Inv(<'a>))): Trait

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.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions