From bc45f14e55b85936f6e80d475e51928a354894e2 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sat, 21 Sep 2019 14:45:46 +0900 Subject: [PATCH] Remove "renamed" feature --- Cargo.toml | 4 --- ci/azure-test.yml | 1 - pin-project-internal/Cargo.toml | 10 -------- pin-project-internal/src/lib.rs | 8 ------ .../src/pin_project/attribute.rs | 17 ++++--------- pin-project-internal/src/pinned_drop.rs | 9 ++----- pin-project-internal/src/utils.rs | 25 ------------------- 7 files changed, 7 insertions(+), 67 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d4b4740e..364ed95d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 } diff --git a/ci/azure-test.yml b/ci/azure-test.yml index eb8f1dd6..aec1b6c5 100644 --- a/ci/azure-test.yml +++ b/ci/azure-test.yml @@ -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') }}: diff --git a/pin-project-internal/Cargo.toml b/pin-project-internal/Cargo.toml index 88546f56..7adbbe18 100644 --- a/pin-project-internal/Cargo.toml +++ b/pin-project-internal/Cargo.toml @@ -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 = ".." } diff --git a/pin-project-internal/src/lib.rs b/pin-project-internal/src/lib.rs index 2e2e893c..d24af1c0 100644 --- a/pin-project-internal/src/lib.rs +++ b/pin-project-internal/src/lib.rs @@ -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!") - }; -} diff --git a/pin-project-internal/src/pin_project/attribute.rs b/pin-project-internal/src/pin_project/attribute.rs index 41271771..a01a998b 100644 --- a/pin-project-internal/src/pin_project/attribute.rs +++ b/pin-project-internal/src/pin_project/attribute.rs @@ -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; @@ -89,8 +89,6 @@ impl Parse for Args { } struct Context { - crate_path: Ident, - /// Name of the original type. orig_ident: Ident, @@ -126,10 +124,9 @@ impl Context { ) -> Result { 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)]), ); } @@ -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), @@ -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: ::#crate_path::UnsafeUnpin + ::pin_project::__private::Wrapper: ::pin_project::UnsafeUnpin }) .unwrap(), ); @@ -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! { diff --git a/pin-project-internal/src/pinned_drop.rs b/pin-project-internal/src/pinned_drop.rs index 93bc9286..44a13b7b 100644 --- a/pin-project-internal/src/pinned_drop.rs +++ b/pin-project-internal/src/pinned_drop.rs @@ -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(); @@ -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>) {} } }); @@ -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 { diff --git a/pin-project-internal/src/utils.rs b/pin-project-internal/src/utils.rs index 7b5713a6..851f8710 100644 --- a/pin-project-internal/src/utils.rs +++ b/pin-project-internal/src/utils.rs @@ -94,31 +94,6 @@ impl VecExt for Vec { } } -/// 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)