-
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
Add self argument destructuring. Closes #7613. #12566
Conversation
SelfStatic => None, | ||
SelfValue(pat) | SelfRegion(_,_,pat) | SelfUniq(pat) => pat, | ||
} | ||
} |
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.
Does ExplicitSelf
really need to contain the pattern?
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.
Seems the place of least resistance to add it, to me.
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.
ExplicitSelf
is only alive because we can't use Self
in all methods, otherwise I would've killed it completely.
Nothing uses the bundled pattern, other than the code extracting it to produce the proper ast::Arg
structure, which is only needed in the parser, which has direct access to the pattern anyway.
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 would think that pretty printing justifies the addition of the pattern.
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.
Pretty printing could just take the pattern out of the first argument, couldn't it?
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.
Good point. It'll certainly make diffs much smaller.
Great work! debuginfo probably needs updating. cc @michaelwoerister |
The PR looks fine to me. However, I think its test coverage is a bit lacking. In particular, patterns in trait declarations are not covered. For example:
should not be allowed (the trait doesn't know what type Self is to destructure it). If at all possible, I think the ideal syntax, to be in line with other arguments, would be |
I think |
Thanks! Let's please hold off on merging this for further discussion, since there has been no discussion about this feature lately and I had no plans to implement it in the near future. |
Sorry for the delay. Per today's meeting, we have a different plan to make self arguments destructurable. With universal function-call syntax (UFCS #11938) there will not be any distinction between static methods and instance methods - they will both be 'associated functions'. At that point any function who's first argument is the self type will be callable with method syntax, and Closing. |
No description provided.