Skip to content
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

Apply attr proc macros before cfg processing #44528

Merged
merged 1 commit into from
Sep 29, 2017

Conversation

tmnilsson
Copy link
Contributor

Fixes #39336.
r? @jseyfried

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @jseyfried (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@aidanhs
Copy link
Member

aidanhs commented Sep 13, 2017

Thanks for the PR @tmnilsson, we'll check in now and again to make sure @jseyfried (or another reviewer) gets to this soon!

@alexcrichton alexcrichton added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 14, 2017
@carols10cents
Copy link
Member

carols10cents commented Sep 18, 2017

review ping @jseyfried! pinging you on IRC too.... or not because either I don't know your nick or you're not online :) sneaky!

let item = if !attr.is_some() {
Annotatable::Item(fully_configure!(self, item, noop_fold_item))
}
else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: } else { is more idiomatic

@@ -867,7 +867,12 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {

let (attr, traits, mut item) = self.classify_item(item);
if attr.is_some() || !traits.is_empty() {
let item = Annotatable::Item(fully_configure!(self, item, noop_fold_item));
let item = if !attr.is_some() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: !attr.is_some() -> attr.is_none()

@jseyfried
Copy link
Contributor

@tmnilsson looks good so far!

Could you test that
#[derive(Foo)] #[foo] struct S { #[cfg(any())] x: i32 } gets fully configured (i.e. x is removed), given

#[proc_macro_derive(Foo, attributes(foo))]
fn derive_foo(input: TokenStream) -> TokenStream { input }

The issue here is that when collecting #[derive(Foo)] #[foo] struct S { ... }, we don't know whether #[foo] is an attribute proc-macro or just an "inert" attribute used to give information to #[derive(Foo)], so we collect is as an attribute proc macro first (i.e. your code won't fully configure).

If we learn that #[foo] is not in fact a proc macro, we re-collect into a derive invocation here: https://github.com/tmnilsson/rust/blob/835992d4b14800cac0c450f893c050fdedd18dca/src/libsyntax/ext/expand.rs#L285.

I believe you'll need to fully_configure! the item at this line to ensure that we don't regress examples like this that compile today.

@arielb1 arielb1 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 19, 2017
@tmnilsson
Copy link
Contributor Author

Thanks for the feedback! That example would not get fully configured, as you expected. I wasn't even aware of inert attributes, actually. Anyway, I moved the full configure as you suggested, and that seems to make it work.

Annotatable::Item(cfg.fold_item(item).pop().unwrap())
}
Annotatable::TraitItem(item) => {
Annotatable::TraitItem(P(cfg.fold_trait_item(item.unwrap()).pop().unwrap()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: item.map(|item| cfg.fold_trait_item(item).pop().unwrap()) is more idiomatic and efficient here (i.e. with P). Same for ImplItem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, fixed.

@jseyfried
Copy link
Contributor

jseyfried commented Sep 26, 2017

@tmnilsson Excellent, thanks!
r=me modulo optional nit.

Also FYI we usually rebase PR branch over newer master and force push instead of merging master into PR branch.

Now items are not fully configured until right before expanding derives.
@jseyfried
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Sep 28, 2017

📌 Commit 0f97b6b has been approved by jseyfried

@bors
Copy link
Contributor

bors commented Sep 28, 2017

⌛ Testing commit 0f97b6b with merge 46ef620...

bors added a commit that referenced this pull request Sep 28, 2017
…ried

Apply attr proc macros before cfg processing

Fixes #39336.
r? @jseyfried
@bors
Copy link
Contributor

bors commented Sep 29, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: jseyfried
Pushing 46ef620 to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants