-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Improved error message for impl on typedef. #12385
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
Conversation
item.span, | ||
self_type.ty) { | ||
None => { | ||
// Error already reported from CoherenceChecker's |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This branch is only triggered when self_type.ty
is a typedef, right? Could the comment be updated to include this information?
This addresses GH #9767.
How about this comment? It's a lot more specific. |
That comment looks good, yes. I don't understand the code fully, but it seems like Also, what about something like struct Foo;
type Bar = Foo;
impl Bar { ... } where the typedef is pointing to a non-primitive? |
Yes, it does--but that case already emitted an error. Only the text of the error message changed in that particular branch. |
@@ -276,8 +295,7 @@ impl CoherenceChecker { | |||
None => { | |||
let session = self.crate_context.tcx.sess; | |||
session.span_err(item.span, | |||
"no base type found for inherent implementation; \ | |||
implement a trait or new type instead"); | |||
"cannot provide impl for typedefs"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure that this branch only happens for typedefs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm very unfamiliar with this code, so I'm mostly just curious
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% positive. All of the existing tests passed, but that's an argument from code coverage. Where would I look to find other potential test cases?
@chromatic I'm not quite sure what you mean by "yes" (since I asked two questions). |
@huonw, Sorry, that was really misleading of me!
|
Impl-ing directly on primitive types like |
This discussion may have identified multiple issues. This list may not be exhaustive, but it's a start:
2a) If so, is the syntax you gave correct? 2b) If not, what should the error message be? (There's no test for that.)
3a) If so, is the syntax you gave correct? 3b) If not, what should the error message be? (There's no test for that.)
4a) If so, what should those error messages be? (There are no tests for that.)
I am very willing to continue addressing this issue, but it seems like these questions need to be answered before the code work can continue. |
Most of these questions aren't really brought up by this issue specifically. The primitive/non-primitive distinction essentially only cropped up as an artifact of the implementation you've given us (because the compiler doesn't seem to provide a quick-and-easy way to identify if a type is a
"Cannot impl a
Maybe, some loose discussion has happened in a few places (spread across IRC and a few github issues).
Probably.
Preferably "Cannot impl directly on a built-in type, use a trait" (or something like that).
I think
Why would we change from 3b) If not, what should the error message be? (There's no test for that.) See 1.
A few, but barely related to type synonyms.
Eh? There are a few tests for invalid impls.
This PR is purporting to fix error messages for |
Closing due to a lack of activity, but feel free to reopen with a rebase! |
This addresses GH #9767. The text of the error message can, of course, change to meet reviewer preferences.