-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.Diagnostics: Too much output caused by a single piece of incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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.
Metadata
Metadata
Assignees
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.Diagnostics: Too much output caused by a single piece of incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.