Open
Description
The following code:
struct AssertCopy<T: Copy>(T);
trait Foo {
type Assoc;
fn my_method() -> Self::Assoc;
}
impl Foo for bool {
type Assoc = AssertCopy<String>;
fn my_method() -> Self::Assoc {
panic!();
}
}
produces the following two errors:
error[E0277]: the trait bound `String: Copy` is not satisfied
--> src/lib.rs:9:5
|
1 | struct AssertCopy<T: Copy>(T);
| ---- required by this bound in `AssertCopy`
...
9 | type Assoc = AssertCopy<String>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
error[E0277]: the trait bound `String: Copy` is not satisfied
--> src/lib.rs:10:23
|
1 | struct AssertCopy<T: Copy>(T);
| ---- required by this bound in `AssertCopy`
...
10 | fn my_method() -> Self::Assoc {
| ^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
Only the first error is useful - the second error occurs because we're trying to use the 'malformed' associated type. This can be especially bad when proc-macros are involved, since the span of the return type might not be meaningful. See #83383
We should suppress the second error.