-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Custom errors for well-known traits #20783
Comments
It would probably be a lot more work but it would be nice to do this in an extensible way so that the functionality could be exposed to library authors somehow. |
I've long wanted this but have been hesitant to ask for special casing. Perhaps a |
Yes, I had the same thought regarding extensibilty. At first I wasn't sure how to do it, but after thinking on it more, I bet something really simple, like the following, would work:
basically you supply a format string, and we will give it arguments named after your type parameters with the stringified versions of each type. |
It'd be helpful to have more examples where this could be applied. |
I'd be happy to mentor this. Shouldn't be too hard. |
If anyone gets this error, it's that I had a |
I've thought about a slightly more general version of an |
Some notes on how you might do this. This is specific to my original proposal.
|
@P1start makes sense. In any case, seems like we should start with something and grow as we go. This wouldn't a stable attribute anyway (at least not for some time). |
I have simplified |
@nikomatsakis Perhaps not the common case but I'd love to have this for a library for generic programming that I'm working on. For example, the shapeless folks use something similar. |
@Manishearth if my understanding of the code is correct, this currently replaces the current error message with the custom one. I think this is incorrect, and instead the |
Yeah, I've fixed it to a |
…nimplemented traits (fixes rust-lang#20783)
Consider these comments by the one and only @steveklabnik:
wouldn't it be nicer if the compiler saw that error involved
FromIterator
and printed something like "the type you are iterating over doesn't match the expected type of the collection you are creating"?Nominating for 1.0 (not beta), because this could be a big usability benefit. I'm sure there are other "well-known" traits we could do this for.
The text was updated successfully, but these errors were encountered: