-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Incomplete error message: unable to infer enough type information about _
#25633
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 matters to me too. |
@rust-lang/compiler: I feel like this should be prioritized since it is very painful to deal with for newcomers to Rust. Could we nominate and discuss at next meeting? I don't know what can be done, but at least saying where the |
@Mark-Simulacrum current output for this example:
In a sense, I think this issue is fixed, though we decided to punt on figuring how to display the "partial type information" we have available. |
Though to me it's relatively obvious, so I might be inferring too much here, I think it would be amazing if we change "cannot infer type for I'm fine with closing this if we disagree, though. |
@Mark-Simulacrum ah, that's an interesting idea; I agree that just giving this free-floating name |
To avoid the difficulty in showing the generics, we could even go with "cannot infer type for generic I'm somewhat on the fence with using |
@Mark-Simulacrum one challenge is that I definitely feel like printing the name given on the definition has not proven especially clarifying and would like to do something else. Perhaps, in the event that the type we cannot infer is "embedded" within a bigger type, we could say something like this:
This doesn't look as good now that I've typed it out. ;) |
Drawing from that, perhaps just using I think I somewhat dislike the approach with
|
Current output is
It could be
|
When encountering code where type inference fails, add more actionable information: ``` fn main() { let foo = Vec::new(); } ``` ``` error[E0282]: type annotations needed for `std::vec::Vec<_>` --> $DIR/vector-no-ann.rs:2:16 | LL | let foo = Vec::new(); | --- ^^^^^^^^ cannot infer type for `T` | | | consider giving `foo` the type `std::vec::Vec<_>` with the type parameter `T` specified ``` We still need to modify type printing to optionally accept a `TypeVariableTable` in order to properly print `std::vec::Vec<T>`. CC rust-lang#25633.
Add more detail to type inference error When encountering code where type inference fails, add more actionable information: ``` fn main() { let foo = Vec::new(); } ``` ``` error[E0282]: type annotations needed in `std::vec::Vec<T>` --> $DIR/vector-no-ann.rs:2:16 | LL | let foo = Vec::new(); | --- ^^^^^^^^ cannot infer type for `T` in `std::vec::Vec<T>` | | | consider giving `foo` a type ``` Fix #25633.
Gives me:
This is confusing because it doesn't say what the
_
is that it can't figure out. Perhaps it could say something like:The text was updated successfully, but these errors were encountered: