Skip to content

assoc type impl mismatch with trait assoc type doesnt mention where clauses #99206

New issue

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

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

Already on GitHub? # to your account

Open
BoxyUwU opened this issue Jul 13, 2022 · 1 comment
Open
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-GATs Area: Generic associated types (GATs) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@BoxyUwU
Copy link
Member

BoxyUwU commented Jul 13, 2022

Given the following code:

#![feature(generic_associated_types)]

trait Trait {
    type Assoc<'a>;
}

impl<'b> Trait for &'b () {
    type Assoc<'a>
    = &'a &'b ()
    where
        Self: 'a;
}

The current output is:

error: `impl` associated type signature for `Assoc` doesn't match `trait` associated type signature
 --> src/lib.rs:8:5
  |
4 |     type Assoc<'a>;
  |     -------------- expected
...
8 |     type Assoc<'a>
  |     ^^^^^^^^^^^^^^ found

Ideally the output should look like:

error: `impl` associated type signature for `Assoc` doesn't match `trait` associated type signature
 --> src/lib.rs:8:5
  |
4 |     type Assoc<'a>;
  |     -------------- expected no where clause
...
8 |     type Assoc<'a>
  |     ...
  |     where
  |         Self: 'a;
  |         ^^^^^^^^ found where clause not present on trait definition
note: consider adding where clause to trait definition
  |
4 |    type Assoc<'a>
  |    where
  |        Self: 'a;
  |    +++++++++++++
@BoxyUwU BoxyUwU 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. F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs labels Jul 13, 2022
JohnTitor added a commit to JohnTitor/rust that referenced this issue Jul 26, 2022
…smatch, r=cjgillot

Slightly improve mismatched GAT where clause error

This makes the error reporting a bit more standardized between `where` on GATs and functions.

cc rust-lang#99206 (`@BoxyUwU),` don't want to mark this as as "fixed" because they're still not perfect, but this is still an improvement IMO so I want to land it incrementally.

regarding "consider adding where clause to trait definition", we don't actually do that for methods as far as i can tell? i could file an issue to look into that maybe.
@compiler-errors
Copy link
Member

The error message now:

error[E0276]: impl has stricter requirements than trait
  --> src/lib.rs:11:15
   |
4  |     type Assoc<'a>;
   |     -------------- definition of `Assoc` from trait
...
11 |         Self: 'a;
   |               ^^ impl has extra requirement `'b: 'a`

@fmease fmease added A-GATs Area: Generic associated types (GATs) and removed F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs labels Sep 24, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-GATs Area: Generic associated types (GATs) 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