diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f7541ec5..277dbf89 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -85,12 +85,6 @@ jobs: cargo test --all --all-features env: RUSTFLAGS: -Dwarnings --cfg pin_project_show_unpin_struct - - name: cargo check -Zallow-features - if: matrix.rust == 'nightly' - run: | - cargo check --all --all-features - env: - RUSTFLAGS: -Dwarnings --cfg pin_project_show_unpin_struct -Zallow-features=proc_macro_hygiene,stmt_expr_attributes # Refs: https://github.com/rust-lang/cargo/issues/5657 - name: cargo check -Zminimal-versions if: matrix.rust == 'nightly' diff --git a/pin-project-internal/build.rs b/pin-project-internal/build.rs deleted file mode 100644 index 953ca3ad..00000000 --- a/pin-project-internal/build.rs +++ /dev/null @@ -1,37 +0,0 @@ -use std::env; - -fn main() { - // While this crate supports stable Rust, it currently requires - // nightly Rust in order for rustdoc to correctly document auto-generated - // `Unpin` impls. This does not affect the runtime functionality of this crate, - // nor does it affect the safety of the api provided by this crate. - // - // This is disabled by default and can be enabled using - // `--cfg pin_project_show_unpin_struct` in RUSTFLAGS. - // - // Refs: - // * https://github.com/taiki-e/pin-project/pull/53#issuecomment-525906867 - // * https://github.com/taiki-e/pin-project/pull/70 - // * https://github.com/rust-lang/rust/issues/63281 - if cfg!(pin_project_show_unpin_struct) && feature_allowed("proc_macro_def_site") { - println!("cargo:rustc-cfg=proc_macro_def_site"); - } -} - -// Based on https://github.com/alexcrichton/proc-macro2/pull/176 -fn feature_allowed(feature: &str) -> bool { - if let Some(rustflags) = env::var_os("RUSTFLAGS") { - for mut flag in rustflags.to_string_lossy().split(' ') { - if flag.starts_with("-Z") { - flag = &flag["-Z".len()..]; - } - if flag.starts_with("allow-features=") { - flag = &flag["allow-features=".len()..]; - return flag.split(',').any(|allowed| allowed == feature); - } - } - } - - // No allow-features= flag, allowed by default. - true -} diff --git a/pin-project-internal/src/lib.rs b/pin-project-internal/src/lib.rs index da4cd9b4..9a678f07 100644 --- a/pin-project-internal/src/lib.rs +++ b/pin-project-internal/src/lib.rs @@ -10,7 +10,19 @@ #![warn(rust_2018_idioms, single_use_lifetimes, unreachable_pub)] #![warn(clippy::all, clippy::pedantic)] #![allow(clippy::use_self, clippy::needless_doctest_main)] -#![cfg_attr(proc_macro_def_site, feature(proc_macro_def_site))] +// While this crate supports stable Rust, it currently requires +// nightly Rust in order for rustdoc to correctly document auto-generated +// `Unpin` impls. This does not affect the runtime functionality of this crate, +// nor does it affect the safety of the api provided by this crate. +// +// This is disabled by default and can be enabled using +// `--cfg pin_project_show_unpin_struct` in RUSTFLAGS. +// +// Refs: +// * https://github.com/taiki-e/pin-project/pull/53#issuecomment-525906867 +// * https://github.com/taiki-e/pin-project/pull/70 +// * https://github.com/rust-lang/rust/issues/63281 +#![cfg_attr(pin_project_show_unpin_struct, feature(proc_macro_def_site))] extern crate proc_macro; diff --git a/pin-project-internal/src/pin_project/derive.rs b/pin-project-internal/src/pin_project/derive.rs index 004399fe..9c249190 100644 --- a/pin-project-internal/src/pin_project/derive.rs +++ b/pin-project-internal/src/pin_project/derive.rs @@ -86,11 +86,11 @@ impl DeriveContext { let orig_ident = &self.ident; let make_span = || { - #[cfg(proc_macro_def_site)] + #[cfg(pin_project_show_unpin_struct)] { proc_macro::Span::def_site().into() } - #[cfg(not(proc_macro_def_site))] + #[cfg(not(pin_project_show_unpin_struct))] { proc_macro2::Span::call_site() } @@ -159,7 +159,8 @@ impl DeriveContext { }; full_where_clause.predicates.push(unpin_clause); - let attrs = if cfg!(proc_macro_def_site) { quote!() } else { quote!(#[doc(hidden)]) }; + let attrs = + if cfg!(pin_project_show_unpin_struct) { quote!() } else { quote!(#[doc(hidden)]) }; let inner_data = quote! { // This needs to have the same visibility as the original type, @@ -186,7 +187,7 @@ impl DeriveContext { impl #impl_generics ::core::marker::Unpin for #orig_ident #ty_generics #full_where_clause {} }; - if cfg!(proc_macro_def_site) { + if cfg!(pin_project_show_unpin_struct) { // On nightly, we use def-site hygiene to make it impossible // for user code to refer to any of the types we define. // This allows us to omit wrapping the generated types