-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Unhelpful error messages for calls of methods defined in an impl with restricted bounds that aren't satisfied #20941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
(A way to paper over this would be to move to |
Comments from IRC:
|
I'd be happy to mentor this. For the record, the other bug is: #7643 |
Hi Niko, I'd like to take a stab at this. I was thinking that in the ProbeContext during method resolution we could keep track of the methods that were considered but did not fulfill the method constraints. Then when printing out the error we could notify the user that their type needs to fulfill whatever constraint it is. Does this seem like a viable strategy? |
Any progress on this? I wasted a lot of time today trying to figure out why I couldn't call |
Can this be nominated for 1.0? This still seriously bugs me. |
When a method exists in an impl but can not be used due to missing trait bounds for the type parameters, we should inform the user which trait bounds are missing. For example, this code ``` // Note this is missing a Debug impl struct Foo; fn main() { let a: Result<(), Foo> = Ok(()); a.unwrap() } ``` Now gives the following error: ``` /home/gulshan/tmp/tmp.rs:6:7: 6:15 error: no method named `unwrap` found for type `core::result::Result<(), Foo>` in the current scope /home/gulshan/tmp/tmp.rs:6 a.unwrap() ^~~~~~~~ /home/gulshan/tmp/tmp.rs:6:7: 6:15 note: The method `unwrap` exists but the following trait bounds were not satisfied: `Foo : core::fmt::Debug` error: aborting due to previous error ``` Fixes #20941.
The
_bad
one is completely unhelpful, the_good
is much better since it allows one to diagnose the problem. It would be nice for them both to be good.This comes up relatively often with
RefCell::<T, E>::unwrap
(which requiresE: Show
in theimpl
), andMutex::<T>::lock
(which requiresT: Send
in the impl).The text was updated successfully, but these errors were encountered: