-
Notifications
You must be signed in to change notification settings - Fork 13.4k
"note: method exists but trait bounds not satisfied" could be better #36513
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
Comments
I want to add the case to don't duplicate an issue. Message is unsophisticated if I use different versions of crates. I stumbled it many times ( Example: error[E0277]: the trait bound `mould_auth::AuthService<checker::Checker<r2d2::Pool<r2d2_postgres::PostgresConnectionManager>>, session::UserRole, dba::Error>: mould::service::Service<session::UserSession>` is not satisfied
--> src\main.rs:63:11
|
63 | suite.register("auth-service", auth_service);
| ^^^^^^^^ trait `mould_auth::AuthService<checker::Checker<r2d2::Pool<r2d2_postgres::PostgresConnectionManager>>, session::UserRole, dba::Error>: mould::service::Service<session::UserSession>` not satisfied
error[E0277]: the trait bound `mould_auth::TokenService<checker::Checker<r2d2::Pool<r2d2_postgres::PostgresConnectionManager>>, session::UserRole, dba::Error>: mould::service::Service<session::UserSession>` is not satisfied
--> src\main.rs:68:11
|
68 | suite.register("token-service", token_service);
| ^^^^^^^^ trait `mould_auth::TokenService<checker::Checker<r2d2::Pool<r2d2_postgres::PostgresConnectionManager>>, session::UserRole, dba::Error>: mould::service::Service<session::UserSession>` not satisfied
error: aborting due to 2 previous errors There is an error, because main crate use one dependency from |
|
I'm getting a similar problem here too. I'm trying to convert a Json object to a string. Rocket and serde is involved in this issue:
The error is:
It mentions that something isn't satisfied, which is helpful. Maybe this is an issue with the underlying Json object and not Rust? |
Another variant of the “same trait from different versions” is when you have the exact same version but from different sources, e.g. crates.io and a git dependency. |
another example is where trait bounds are nested, in which case the error suggests that the bounds are not met, but not which bounds or why. a simple example (playground link): pub struct Example;
trait A {
fn do_a(&self);
}
trait B {
fn do_b(&self);
}
trait Empty {}
impl <T> B for T where T: A + Empty
{
fn do_b(&self) {
self.do_a()
}
}
impl A for Example {
fn do_a(&self) {
println!("A!");
}
}
fn main() {
let e = Example;
e.do_b();
} Error:
it would be extremely useful in this instance to have a note to indicate why the bound is not met, in this instance as |
For the original case, would the following output be acceptable?
That's the current output in #69255. I think I can change it slightly to be less verbose, but worry about it being more confusing in the general case:
The case in the last comment would now be:
|
looks great to me! the question then is how it generalises to work with more complex nested bounds, but, i don't have a good example handy at the moment (the snippet i posted was a minimum reproduction of something, but, i can't remember what). |
Current output in #69255:
which would look like this in end user's envs:
|
Add more context to E0599 errors Point at the intermediary unfulfilled trait bounds. Fix rust-lang#52523, fix rust-lang#61661, cc rust-lang#36513, fix rust-lang#68131, fix rust-lang#64417, fix rust-lang#61768, cc rust-lang#57457, cc rust-lang#9082, fix rust-lang#57994, cc rust-lang#64934, cc rust-lang#65149.
Add more context to E0599 errors Point at the intermediary unfulfilled trait bounds. Fix rust-lang#52523, fix rust-lang#61661, cc rust-lang#36513, fix rust-lang#68131, fix rust-lang#64417, fix rust-lang#61768, cc rust-lang#57457, cc rust-lang#9082, fix rust-lang#57994, cc rust-lang#64934, cc rust-lang#65149.
Current output:
|
Current output:
For the second case, we should point at the |
Current output:
|
The only part left to do in this ticket is covered by #40375, so I'll close this one. |
Uh oh!
There was an error while loading. Please reload this page.
I saw this broken code on IRC:
I know why it's broken, but I don't like the error message:
note
just told me that the problem is the trait bounds, so it is superfluous to suggest importing a trait (even without thenote
, it doesn't need to be imported so thehelp
is useless).note
saysIterator
is not satisfied, which is not helpful. The problem is thatIterator<Item=String>
is not satisfied.The text was updated successfully, but these errors were encountered: