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

Move most of the processing to proc-macro-derive #135

Merged
merged 2 commits into from
Oct 14, 2019
Merged

Conversation

taiki-e
Copy link
Owner

@taiki-e taiki-e commented Oct 13, 2019

To generate the correct Unpin implementation and the projection methods, we need to collect the types of the pinned fields. However, since proc-macro-attribute is applied before #[cfg] and #[cfg_attr] on fields, we cannot be collecting field types properly at this timing. So instead of generating the Unpin implementation and the projection methods here, delegate their processing to proc-macro-derive.

#77 moved only the automatic generation of Unpin implementation to proc-macro-derive but found that it could not support #[cfg_attr], so this moves more processing.

See also #68 (comment).

This also adds support for the use of #[cfg] on tuple structs and tuple variants.

Closes #123

@taiki-e taiki-e added the C-enhancement Category: A new feature or an improvement for an existing one label Oct 13, 2019
@taiki-e taiki-e self-assigned this Oct 13, 2019
@taiki-e taiki-e force-pushed the internal-derive branch 2 times, most recently from b183603 to ea9323a Compare October 14, 2019 07:18
@taiki-e taiki-e changed the title Move all of the field-dependent processing to proc-macro-derive Move most of the processing to proc-macro-derive Oct 14, 2019
@taiki-e taiki-e marked this pull request as ready for review October 14, 2019 07:19
Ok(quote! {
#(#attrs)*
#body
})
}

#[allow(dead_code)] // https://github.com/rust-lang/rust/issues/56750
Copy link
Owner Author

Choose a reason for hiding this comment

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

It seems to have been fixed in the latest nightly, but it is left for compatibility with other versions.

By moving most of the remaining processing to proc-macro-derive,
we don't have to parse AST with proc-macro-attribute, so we can improve
compile time.
@taiki-e
Copy link
Owner Author

taiki-e commented Oct 14, 2019

bors r+

bors bot added a commit that referenced this pull request Oct 14, 2019
135: Move most of the processing to proc-macro-derive r=taiki-e a=taiki-e

To generate the correct `Unpin` implementation and the projection methods, we need to collect the types of the pinned fields.  However, since proc-macro-attribute is applied before `#[cfg]` and `#[cfg_attr]` on fields, we cannot be collecting field types properly at this timing. So instead of generating the `Unpin` implementation and the projection methods here, delegate their processing to proc-macro-derive.

#77 moved only the automatic generation of `Unpin` implementation to proc-macro-derive but found that it could not support `#[cfg_attr]`, so this moves more processing.

See also #68 (comment).

This also adds support for the use of `#[cfg]` on tuple structs and tuple variants.

Closes #123

Co-authored-by: Taiki Endo <te316e89@gmail.com>
@bors
Copy link
Contributor

bors bot commented Oct 14, 2019

Build succeeded

  • style (clippy)
  • style (rustdoc)
  • style (rustfmt)
  • test (1.33.0)
  • test (1.36.0)
  • test (beta)
  • test (macos)
  • test (nightly)
  • test (stable)

@bors bors bot merged commit b1bdd9a into master Oct 14, 2019
@bors bors bot deleted the internal-derive branch October 14, 2019 09:39
@taiki-e taiki-e removed their assignment Oct 14, 2019
@taiki-e taiki-e added the A-pin-projection Area: #[pin_project] label May 7, 2020
@taiki-e taiki-e added relnotes and removed C-enhancement Category: A new feature or an improvement for an existing one labels Jan 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-pin-projection Area: #[pin_project]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make #[pin_project] interoperable with [cfg_attr()]
1 participant