-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Allow syntax extensions which modify and decorate #33738
Allow syntax extensions which modify and decorate #33738
Conversation
r? @sfackler (rust_highfive has picked a reviewer for you, use r? to override) |
afadda2
to
1eab42e
Compare
This has been something I've been meaning to do for a while - I think the whole split into decorators and modifiers was a bad design decision on my part. To that end, I'd like to move towards removing the other variants and making this the only one. cc @nrc |
meta_item: &ast::MetaItem, | ||
item: Annotatable, | ||
push: &mut FnMut(Annotatable)) | ||
-> Annotatable; |
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 like we can drop the return type and just have implementors push all of the things they're creating/preserving into push
?
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.
That is a good idea, I'm adding this in now.
519c8de
to
9251609
Compare
57c0733
to
83a8e22
Compare
☔ The latest upstream changes (presumably #33766) made this pull request unmergeable. Please resolve the merge conflicts. |
Looks like travis is failing and it needs a rebase. Looks good to me otherwise though. r? @nrc |
cc @cswords |
a64bb3a
to
d0c8eba
Compare
Travis seems to be having unrelated issues. |
☔ The latest upstream changes (presumably #33706) made this pull request unmergeable. Please resolve the merge conflicts. |
d0c8eba
to
14a8f0a
Compare
Am working on fixing this up. |
b7a0f2c
to
58d1ae6
Compare
@nrc: Have rewritten the PR so that renovators must push all items which they want to preserve. This is ready for review. |
Why must users push the items themselves? That seems a bit counter-intuitive. At the least it needs to be documented somewhere. Given that the renovator behaviour is a strict super-set of decorator and modifier, it would be cool to see their code refactored to just use the renovator code. Would that be possible? |
@nrc: @sfackler suggested this behaviour in this comment. I agree with it, and it gives the most flexibility to extensions. Happy to document it more.
It's tricky to merge the three, as there is special handling for the new things that modifiers create. I can merge the |
This adds a new SyntaxExtension type - Renovator. A renovator is a syntax extension which can modify *and* decorate the items it is attached to - the union of `MultiModifier` and `MultiDecorator`. This allows things such as syntax extensions which modify existing methods for types, and implement traits all in one.
58d1ae6
to
dbd5017
Compare
☔ The latest upstream changes (presumably #34010) made this pull request unmergeable. Please resolve the merge conflicts. |
Ok, that sounds good, more docs would be good though.
What about the new things renovators create? Is this not the same handling? |
Modifiers have this special handling expand all the new stuff from the modifier. Decorators and renovators don't need it. |
Why don't renovators need it, I'd have thought a renovator which doesn't create new items should behave exactly like a modifier? |
No idea, it's just what the current code does. On Sat, Jun 11, 2016 at 2:51 AM, Nick Cameron [email protected]
|
This PR is superseded by #34253 which achieves a similar goal without adding a new class of macro. Sorry this PR didn't get to land and thanks for submitting it. |
This adds a new
SyntaxExtension
type -Renovator
.A renovator is a syntax extension which can modify and decorate the items it is attached to - the union of
MultiModifier
andMultiDecorator
.This allows things such as syntax extensions which modify existing methods for types, and implement traits all in one.
This shouldn't break any existing code, and it only touches unstable compiler internals.