-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Open
Copy link
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemArea: Trait systemE-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.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
Code
trait Trait {}
mod m {
pub trait Trait {}
pub struct St;
impl Trait for St {}
}
fn func<T: Trait>(_: T) {}
fn main() {
func(m::St);
}
Current output
Compiling playground v0.0.1 (/playground)
error[E0277]: the trait bound `St: Trait` is not satisfied
--> src/main.rs:12:10
|
12 | func(m::St);
| ---- ^^^^^ the trait `Trait` is not implemented for `St`
| |
| required by a bound introduced by this call
|
help: this trait has no implementations, consider adding one
--> src/main.rs:1:1
|
1 | trait Trait {}
| ^^^^^^^^^^^
note: required by a bound in `func`
--> src/main.rs:9:12
|
9 | fn func<T: Trait>(_: T) {}
| ^^^^^ required by this bound in `func`
Desired output
Compiling playground v0.0.1 (/playground)
error[E0277]: the trait bound `St: Trait` is not satisfied
--> src/main.rs:12:10
|
12 | func(m::St);
| ---- ^^^^^ the trait `Trait` is not implemented for `St`
| |
| required by a bound introduced by this call
|
note: `St` implements similarly named `crate::m::Trait`, but not `crate::Trait`
help: this trait has no implementations, consider adding one
--> src/main.rs:1:1
|
1 | trait Trait {}
| ^^^^^^^^^^^
note: required by a bound in `func`
--> src/main.rs:9:12
|
9 | fn func<T: Trait>(_: T) {}
| ^^^^^ required by this bound in `func`
Rationale and extra context
This can easily happen if you accidentally have two different versions of the same crate in your dependency tree (see this URLO thread), or have two dependencies that use different trait for the same thing (eg. tokio::io::AsyncRead
and futures_io::AsyncRead
)
Other cases
Should also probably trigger if the implemented trait has a small enough edit distance between it and the desired trait, similar to the help messages for misspelled methods and types.
Rust Version
1.82.0
Anything else?
No response
tmccombs, gr1mpatr0n, hasezoey, itsjunetime, lhao03 and 3 more
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemArea: Trait systemE-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.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.