-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Spurious error about Sized bound when trait needs to be imported #35976
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
This is seriously confusing. I just spend 30 minutes trying to figure it out before googling and finding this. |
I believe what is happening is this:
Given the popularity of this pattern (e.g., iterators work the same way), it's probably worth trying to tailor an error message for this case if we can. |
I imagine something like this:
The trick is...what do we say in this scenario? Advising to import the trait may not be a good fix, though we could look for trait impls on |
Giving the existing "import the trait" error would at least be an improvement. |
Marking as a diagnostics issue. cc @rust-lang/compiler, perhaps we could prioritize this? It's possible that even small wins ("import the trait") here would be very good. Even just almost always doing this might be a lot better if given with the right wording. |
OK, so, the challenge here is that method resolution succeeds. I am a bit torn. Perhaps the easiest (and maybe even best) way to solve this is to modify method resolution itself to check for this particular case. That is, when method resolution succeeds, if this is a trait method, we could quickly scan the where-clauses for the method, looking specifically for I'm out of time this morning for writing detailed mentoring instructions, but let me give a few pointers. I'm happy to elaborate further in the future. The method searching code is found in this module. It works in two phases: the first phase, probing, finds which method applies. That doesn't have to change here, I think. The second phase, confirmation, does a bit of further work. Here is the implementation of the So basically my proposal is to interject there and detect this particular case and issue a custom error. |
triage: P-medium |
@raphlinus and I ran into this bug this morning when using I think @nikomatsakis's solution would have worked well for us. If it detects you trying to call a trait method with a |
When trying to perform static dispatch on something which derefs to a trait object, and the target trait is not in scope, we had confusing error messages if the target method had a `Self: Sized` bound. We add a more precise error message in this case: "consider using trait ...". Fixes rust-lang#35976.
Add a more precise error message for issue #35976 When trying to perform static dispatch on something which derefs to a trait object, and the target trait is not in scope, we had confusing error messages if the target method had a `Self: Sized` bound. We add a more precise error message in this case: "consider using trait ...". Fixes #35976. r? @nikomatsakis
First reported at rust-lang/futures-rs#97
xx.rs:
main.rs:
This code works.
If
use futures::Future
is commented out inmain.rs
, compiler complains:I'm not sure if is it a bug, or just a usability problem, is it in futures-rs or in rust language, but it is hard to understand error message.
rustc 1.11.0 (9b21dcd 2016-08-15), futures-rs from master
cc @stepancheg
cc @jonathandturner
cc @nikomatsakis
The text was updated successfully, but these errors were encountered: