Skip to content

error messages incorrectly display where bounds with higher ranked self types #104398

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

Open
lcnr opened this issue Nov 14, 2022 · 1 comment
Open
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-higher-ranked Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs) D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@lcnr
Copy link
Contributor

lcnr commented Nov 14, 2022

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

trait Trait {}

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

fn main() {
    with_bound();
}

The current output is:

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

error[[E0277]](https://doc.rust-lang.org/stable/error-index.html#E0277): the trait bound `for<'a> fn(Inv<'a>): Trait` is not satisfied
  --> src/main.rs:12:5
   |
12 |     with_bound();
   |     ^^^^^^^^^^ the trait `Trait` is not implemented for `for<'a> fn(Inv<'a>)`
   |
note: required by a bound in `with_bound`
  --> src/main.rs:7:28
   |
5  | fn with_bound<T>()
   |    ---------- required by a bound in this
6  | where
7  |     (for<'a> fn(Inv<'a>)): Trait,
   |                            ^^^^^ required by this bound in `with_bound`

The incorrect warning is tracked in #104397. The error message is also wrong though. for<'a> fn(Inv<'a>): Trait is a different from (for<'a> fn(Inv<'a>)): Trait.

@lcnr lcnr added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 14, 2022
@fmease fmease added D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. A-higher-ranked Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs) labels Sep 24, 2024
@estebank
Copy link
Contributor

Current output:

error[E0277]: the trait bound `for<'a> fn(Inv<'a>): Trait` is not satisfied
  --> src/main.rs:12:5
   |
12 |     with_bound();
   |     ^^^^^^^^^^^^ the trait `Trait` is not implemented for `for<'a> fn(Inv<'a>)`
   |
help: this trait has no implementations, consider adding one
  --> src/main.rs:3:1
   |
3  | trait Trait {}
   | ^^^^^^^^^^^
note: required by a bound in `with_bound`
  --> src/main.rs:7:28
   |
5  | fn with_bound<T>()
   |    ---------- required by a bound in this function
6  | where
7  |     (for<'a> fn(Inv<'a>)): Trait,
   |                            ^^^^^ required by this bound in `with_bound`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-higher-ranked Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs) D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants