-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Elide generic arguments in "no method found" errors if they're irrelevant #81576
Comments
@rustbot label +A-diagnostics +D-papercut +T-compiler |
Not sure, but I bet it's hard. How can you know what traits are implemented before you've run trait-resolution/typeck/etc.? @rustbot label: E-hard |
Method resolution occurs during typecheck (and involves trait resolution), so this might not be that difficult. |
Ah, I forget that methods have to be resolved during typeck. Yeah, might not be as hard as I thought: @rustbot label: +E-medium -E-hard |
@rustbot claim |
…estebank E0599 suggestions and elision of generic argument if no canditate is found fixes rust-lang#81576 changes: In error E0599 (method not found) generic argument are eluded if the method was not found anywhere. If the method was found in another inherent implementation suggest that it was found elsewhere. Example ```rust struct Wrapper<T>(T); struct Wrapper2<T> { x: T, } impl Wrapper2<i8> { fn method(&self) {} } fn main() { let wrapper = Wrapper(i32); wrapper.method(); let wrapper2 = Wrapper2{x: i32}; wrapper2.method(); } ``` ``` Error[E0599]: no method named `method` found for struct `Wrapper<_>` in the current scope .... error[E0599]: no method named `method` found for struct `Wrapper2<i32>` in the current scope ... = note: The method was found for Wrapper2<i8>. ``` I am not very happy with the ```no method named `test` found for struct `Vec<_, _>` in the current scope```. I think it might be better to show only one generic argument `Vec<_>` if there is a default one. But I haven't yet found a way to do that,
…estebank E0599 suggestions and elision of generic argument if no canditate is found fixes rust-lang#81576 changes: In error E0599 (method not found) generic argument are eluded if the method was not found anywhere. If the method was found in another inherent implementation suggest that it was found elsewhere. Example ```rust struct Wrapper<T>(T); struct Wrapper2<T> { x: T, } impl Wrapper2<i8> { fn method(&self) {} } fn main() { let wrapper = Wrapper(i32); wrapper.method(); let wrapper2 = Wrapper2{x: i32}; wrapper2.method(); } ``` ``` Error[E0599]: no method named `method` found for struct `Wrapper<_>` in the current scope .... error[E0599]: no method named `method` found for struct `Wrapper2<i32>` in the current scope ... = note: The method was found for Wrapper2<i8>. ``` I am not very happy with the ```no method named `test` found for struct `Vec<_, _>` in the current scope```. I think it might be better to show only one generic argument `Vec<_>` if there is a default one. But I haven't yet found a way to do that,
Inspired by this question on discord:
Repro: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=e270ca9a0ae009a8f34af6bc31c0ce90
Error:
It would be nice if rustc could notice that
Map<T>
never hasextend
for anyT
, and use that information to simplify the error message to justin order to focus the user better on the relevant part.
Can the name resolution engine do that? (It can for a generic parameter, of course, but then it's only looking at the known trait bounds, which is a little different.)
The text was updated successfully, but these errors were encountered: