-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Confusing "type parameter" in error message. #47319
Comments
Well, I think rather we can say something like "generic Likely a rather simple fix, but I wasn't able to quickly find where this diagnostic gets emitted. |
I would go further and say that the full output should be:
I believe you could modify As for the main span's label, these are the lines where the "expected {}, found {}" is being produced. You could either enclose it with a check for an expected/found type parameter, or (better yet) modify |
This seems a little unnecessary to me as the names are often obvious enough. But I'm not opposed to this. |
Anyone working on this? |
Usually (except in the case of nested Furthermore, consider the current snippet: we don't know wether this was in an
Feel free to take it on! |
Another pretty confusing instance of this in #47499, only with two type parameters. |
Has anyone taken ownership? I'd be willing to start a patch this weekend if no one is working on it. |
I believe @gaurikholkar wanted to take it up, but I don't know if she's already started. |
I've strated working on it @kevincox |
Made the following changes to my locally and WIP. |
I guess we go with the |
As things stand, I believe that will be the best bet. Could you try and see how hard it would be to add a |
Triage: @gaurikholkar , did you ever finish this work? |
Hi @estebank, if no one is working on this (which seems to be the case) then I'd like to pick this up (as a first contribution to the compiler) if that's OK. I think it makes sense to make two separate PRs, the first one for the "modify sort_string to include the type argument's name" part and the second for the span part, since these changes are fairly unrelated to each other, and the former one is trivial and seems to be helpful on its own. Or it can be just separate commits in a single PR if that is preferable. Please let me know what's the best way here. Also does the recommendation from #47319 (comment) still stand or is there a better way now, given the amount of time passed? |
@dkadashev I believe that is indeed the case. |
Status update: after playing with this for a while and hitting pretty much the same problems described in #47574 I think I finally have a fix (nice and small). Preparing a PR now (will take some time though - clean builds, etc.) |
@rustbot claim |
Some examples. Two parameters case that was covered by #47499:
One parameter case from the top of this ticket:
Same for
|
Part of rust-lang#47319. This just adds type parameter name to type mismatch error message, so e.g. the following: ``` expected enum `std::option::Option`, found type parameter ``` becomes ``` expected enum `std::option::Option`, found type parameter `T` ```
…tion, r=estebank Show type parameter name and definition in type mismatch error messages Fixes rust-lang#47319 r? estebank
…tion, r=estebank Show type parameter name and definition in type mismatch error messages Fixes rust-lang#47319 r? estebank
I have thought this is odd for a while, however after teaching a Rust introduction class I found numerous attendees stumbling on this weird error for a simple and common case.
The "found type parameter" part is confusing, as I (and most students) interpret this as some sort of weird syntax-like error. For example it feels similar to the "expected
{
, found;
" you get from syntax errors.I think that simply adding
`T`
after the message would make this much more understandable.Possibly more controversial is dropping "parameter" or "type parameter" I don't think they add much value to the error message.
This issue has been assigned to @dkadashev via this comment.
The text was updated successfully, but these errors were encountered: