Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lcnr opened this issue Nov 14, 2022 · 0 comments · Fixed by #104796
Closed

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

lcnr opened this issue Nov 14, 2022 · 0 comments · Fixed by #104796
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information.

Comments

@lcnr
Copy link
Contributor

lcnr commented Nov 14, 2022

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

@lcnr lcnr added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. labels Nov 14, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 24, 2022
…04397, r=oli-obk

lint: do not warn unused parens around higher-ranked function pointers

Fixes rust-lang#104397
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 24, 2022
…04397, r=oli-obk

lint: do not warn unused parens around higher-ranked function pointers

Fixes rust-lang#104397
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 24, 2022
…04397, r=oli-obk

lint: do not warn unused parens around higher-ranked function pointers

Fixes rust-lang#104397
@bors bors closed this as completed in 97d95d4 Nov 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant