rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.28k stars 12.71k forks source link

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

Open BoxyUwU opened 2 years ago

BoxyUwU commented 2 years ago

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;
  |    +++++++++++++
compiler-errors commented 2 years ago

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`