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

Remove "renamed" feature #100

Merged
merged 1 commit into from
Sep 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ all-features = true
[workspace]
members = ["pin-project-internal"]

[features]
# Enable to allow using this crate as a renamed dependency
renamed = ["pin-project-internal/renamed"]

[dependencies]
pin-project-internal = { version = "=0.4.0-alpha.11", path = "pin-project-internal", default-features = false }

Expand Down
1 change: 0 additions & 1 deletion ci/azure-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ jobs:

- script: |
cargo ${{ parameters.cmd }} --all
cargo ${{ parameters.cmd }} --all --all-features
displayName: cargo ${{ parameters.cmd }}

- ${{ if eq(parameters.toolchain, 'nightly') }}:
Expand Down
10 changes: 0 additions & 10 deletions pin-project-internal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,10 @@ all-features = true
[lib]
proc-macro = true

[features]
# Enable to allow using the crate with a renamed 'pin-project' dependency
renamed = ["proc-macro-crate", "serde", "lazy_static"]

[dependencies]
proc-macro2 = "1.0"
quote = "1.0"
syn = { version = "1.0", features = ["full", "visit-mut"] }

proc-macro-crate = { version = "0.1.4", optional = true }
# Required until a new toml-rs release is made with https://github.com/alexcrichton/toml-rs/pull/311,
# and proc-macro-crate updates to that new version of toml-rs.
serde = { version = "1.0.97", optional = true }
lazy_static = { version = "1.3", optional = true }

[dev-dependencies]
pin-project = { version = "0.4.0-alpha.11", path = ".." }
8 changes: 0 additions & 8 deletions pin-project-internal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,11 +538,3 @@ pub fn derive_unpin(input: TokenStream) -> TokenStream {
let input = syn::parse_macro_input!(input);
pin_project::derive(input).into()
}

#[cfg(feature = "renamed")]
lazy_static::lazy_static! {
pub(crate) static ref PIN_PROJECT_CRATE: String = {
proc_macro_crate::crate_name("pin-project")
.expect("pin-project-internal was used without pin-project!")
};
}
17 changes: 5 additions & 12 deletions pin-project-internal/src/pin_project/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use syn::{
};

use crate::utils::{
self, collect_cfg, crate_path, determine_visibility, proj_ident, proj_lifetime_name, Immutable,
Mutable, VecExt, DEFAULT_LIFETIME_NAME,
self, collect_cfg, determine_visibility, proj_ident, proj_lifetime_name, Immutable, Mutable,
VecExt, DEFAULT_LIFETIME_NAME,
};

use super::PIN;
Expand Down Expand Up @@ -89,8 +89,6 @@ impl Parse for Args {
}

struct Context {
crate_path: Ident,

/// Name of the original type.
orig_ident: Ident,

Expand Down Expand Up @@ -126,10 +124,9 @@ impl Context {
) -> Result<Self> {
let Args { pinned_drop, unsafe_unpin } = syn::parse2(args)?;

let crate_path = crate_path();
if unsafe_unpin.is_none() {
attrs.push(
syn::parse_quote!(#[derive(#crate_path::__private::__PinProjectAutoImplUnpin)]),
syn::parse_quote!(#[derive(::pin_project::__private::__PinProjectAutoImplUnpin)]),
);
}

Expand All @@ -138,7 +135,6 @@ impl Context {
let lifetime = Lifetime::new(&lifetime_name, Span::call_site());

Ok(Self {
crate_path,
orig_ident: orig_ident.clone(),
proj_ident: proj_ident(orig_ident, Mutable),
proj_ref_ident: proj_ident(orig_ident, Immutable),
Expand Down Expand Up @@ -187,12 +183,11 @@ impl Context {
};

let mut generics = self.generics.clone();
let crate_path = &self.crate_path;
let orig_ident = &self.orig_ident;

generics.make_where_clause().predicates.push(
syn::parse2(quote_spanned! { unsafe_unpin =>
::#crate_path::__private::Wrapper<Self>: ::#crate_path::UnsafeUnpin
::pin_project::__private::Wrapper<Self>: ::pin_project::UnsafeUnpin
})
.unwrap(),
);
Expand All @@ -210,10 +205,8 @@ impl Context {
let (impl_generics, ty_generics, where_clause) = self.generics.split_for_impl();

if let Some(pinned_drop) = self.pinned_drop {
let crate_path = &self.crate_path;

let call = quote_spanned! { pinned_drop =>
::#crate_path::__private::PinnedDrop::drop(pinned_self)
::pin_project::__private::PinnedDrop::drop(pinned_self)
};

quote! {
Expand Down
9 changes: 2 additions & 7 deletions pin-project-internal/src/pinned_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ use proc_macro2::TokenStream;
use quote::{quote, quote_spanned, ToTokens};
use syn::{parse::Nothing, spanned::Spanned, *};

use crate::utils::crate_path;

pub(crate) fn attribute(mut input: ItemImpl) -> TokenStream {
if let Err(e) = parse(&mut input) {
let crate_path = crate_path();
let self_ty = &input.self_ty;
let (impl_generics, _, where_clause) = input.generics.split_for_impl();

Expand All @@ -20,7 +17,7 @@ pub(crate) fn attribute(mut input: ItemImpl) -> TokenStream {
// We already know that we will get a compile error, so this won't
// accidentally compile successfully.
tokens.extend(quote! {
impl #impl_generics ::#crate_path::__private::PinnedDrop for #self_ty #where_clause {
impl #impl_generics ::pin_project::__private::PinnedDrop for #self_ty #where_clause {
unsafe fn drop(self: ::core::pin::Pin<&mut Self>) {}
}
});
Expand Down Expand Up @@ -96,10 +93,8 @@ fn parse_method(method: &ImplItemMethod) -> Result<()> {
fn parse(item: &mut ItemImpl) -> Result<()> {
if let Some((_, path, _)) = &mut item.trait_ {
if path.is_ident("PinnedDrop") {
let crate_path = crate_path();

*path = syn::parse2(quote_spanned! { path.span() =>
::#crate_path::__private::PinnedDrop
::pin_project::__private::PinnedDrop
})
.unwrap();
} else {
Expand Down
25 changes: 0 additions & 25 deletions pin-project-internal/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,31 +94,6 @@ impl VecExt for Vec<Attribute> {
}
}

/// If the 'renamed' feature is enabled, we detect
/// the actual name of the 'pin-project' crate in the consumer's Cargo.toml.
#[cfg(feature = "renamed")]
pub(crate) fn crate_path() -> Ident {
// This is fairly subtle.
// Normally, you would use `env!("CARGO_PKG_NAME")` to get the name of the package,
// since it's set at compile time.
// However, we're in a proc macro, which runs while *another* crate is being compiled.
// By retreiving the runtime value of `CARGO_PKG_NAME`, we can figure out the name
// of the crate that's calling us.
let cur_crate = std::env::var("CARGO_PKG_NAME")
.expect("Could not find CARGO_PKG_NAME environemnt variable");
format_ident!(
"{}",
if cur_crate == "pin-project" { "pin_project" } else { crate::PIN_PROJECT_CRATE.as_str() },
)
}

/// If the 'renamed' feature is not enabled, we just
/// assume that the 'pin-project' dependency has not been renamed.
#[cfg(not(feature = "renamed"))]
pub(crate) fn crate_path() -> Ident {
format_ident!("pin_project")
}

macro_rules! error {
($span:expr, $msg:expr) => {
syn::Error::new_spanned(&$span, $msg)
Expand Down