-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Hint the generic type and possible bounds on the unimplemented trait error #28660
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
The errors mention
|
@arielb1 The original declaration of |
The errors look clear enough to me (but ops may want a " Spanning the type parameter seems so weird (even the current error messages are a bit on the heavy side, and adding a bound isn't always the correct solution - e.g. in the println case you may actually have wanted to use |
@arielb1 it doesn't if you don't already know what it's talking about, it does confuse people and these days it even gives the wrong advice:
The problem here is that Rust newcomers may not yet understand generic trait bounds[0] and thus how to fix it (see link above for an example), at best the error message is unhelpful and at worst it sends them on a wild goose chase. It would make perfect sense for the compiler to, when it's working on a generic type (rather than a concrete one), suggest adding trait bounds to the trait declaration e.g.
That wouldn't work either (for the same reason) and would yield essentially the same unhelpful error message. Although in specific context it's true that pointing to a related trait could help e.g. a [0] or worse may come from C++ as the link's author does and think they need template instantiation |
I feel like this is fixed in 1.9+:
|
The message for the
so this seems fixed indeed. |
Codes like these currently do not point to the original declaration of
T
for missing trait bounds. In some cases rustc even does not indicate which trait is unimplemented (f
). HintingT: Trait
bounds would be helpful for those cases.#19950 (Provide better error reporting for unimplemented traits) is related and in principle would be a superset, but the issue currently only discusses about nominal types and not generic types.
The text was updated successfully, but these errors were encountered: