Uh oh!
There was an error while loading. Please reload this page.
Run decorators on expanded AST - #34010
Conversation
jseyfried
commented
Jun 1, 2016
cc @durka |
nrc
commented
Jun 1, 2016
This is (I think) a breaking change since a decorator author could be using macros in the AST as input to their functionality. I think I prefer the expansion order to be the same for all attributes, seems confusing to have difference expansion orders. Other than #32950, is there any reason to do this? re #32950, I think a better fix is to implement |
durka
commented
Jun 1, 2016
What if the decorator produces more decorators? |
durka
commented
Jun 1, 2016
cc #33769, the previous attempt to fix this |
jseyfried
commented
Jun 1, 2016
@durka decorator-generated items would still get expanded. |
Agreed, but I'm pretty sure it wouldn't break anything in practice.
I agree that this would be a downside.
I believe some use cases of decorators might benefit from having access to expanded AST, but I don't have any specific examples in mind (besides #32950, of course). In lieu of specific examples, a thought experiment: if we allowed macros in field declaration positions (not saying this would be a good idea), for example structFoo{x:i32,
mac!(),//< say `mac!()` expands to `y: i32`}then |
jseyfried
commented
Jun 1, 2016
That being said, I only weakly support this PR -- @nrc if you still don't think this is a good idea I'll close. |
durka
commented
Jun 1, 2016
Only a plugin-breaking-change, to be clear, since the only stable "decorator author" is rustc. |
It does seem to make some intuitive sense that a decorator on an item would be the last thing to be expanded, after any macros which generate parts of the item. But what about |
Agreed, although it could theoretically break code that uses (unstable) decorator plugins without breaking the plugins themselves (highly unlikely, imo).
We would expand macro_rules! mac {(#[derive($i:ident)] $it:item) => { println!(stringify!($i));}}fnmain(){mac!{ #[derive(Foo)]structBar;}// prints "Foo"}After expanding |
nrc
commented
Jun 7, 2016
Hmm, I'm still not super-happy about having different expansion orders, but this seems to be a fine solution other than that. I think it should probably land. We'll have an opportunity to change direction with the procedural macro overhaul in any case. @bors: r+ |
bors
commented
Jun 7, 2016
📌 Commit 635a82e has been approved by |
bors
commented
Jun 8, 2016
⌛ Testing commit 635a82e with merge ff13155... |
Fixes#32950.
r? @nrc