diff --git a/Cargo.toml b/Cargo.toml index cee2a4d1..e189b6d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,6 +37,7 @@ macrotest = "1.0" prettyplease = { version = "0.2.37", features = ["verbatim"] } [lints.rust] +stable_features = "allow" non_ascii_idents = "deny" unexpected_cfgs = { level = "warn", check-cfg = [ 'cfg(UI_TESTS)', diff --git a/build.rs b/build.rs index fddbb5dc..34d262b0 100644 --- a/build.rs +++ b/build.rs @@ -1,18 +1,17 @@ -use rustc_version::{version, Version}; +use rustc_version::{version_meta, Channel, Version}; fn main() { - println!("cargo::rustc-check-cfg=cfg(RUSTC_LINT_REASONS_IS_STABLE)"); - println!("cargo::rustc-check-cfg=cfg(RUSTC_NEW_UNINIT_IS_STABLE)"); + println!("cargo::rustc-check-cfg=cfg(RUSTC_USE_FEATURE)"); println!("cargo::rustc-check-cfg=cfg(CONFIG_RUSTC_HAS_UNSAFE_PINNED)"); - if version().unwrap() >= Version::parse("1.81.0").unwrap() - || version().unwrap() >= Version::parse("1.81.0-nightly").unwrap() - { - println!("cargo:rustc-cfg=RUSTC_LINT_REASONS_IS_STABLE"); - } - if version().unwrap() >= Version::parse("1.82.0").unwrap() { - println!("cargo:rustc-cfg=RUSTC_NEW_UNINIT_IS_STABLE"); + + let meta = version_meta().unwrap(); + + let use_feature = meta.channel == Channel::Nightly || std::env::var("RUSTC_BOOTSTRAP").is_ok(); + if use_feature { + println!("cargo:rustc-cfg=RUSTC_USE_FEATURE"); } - if version().unwrap() >= Version::parse("1.89.0-nightly").unwrap() { + + if meta.semver >= Version::parse("1.89.0-nightly").unwrap() && use_feature { println!("cargo:rustc-cfg=CONFIG_RUSTC_HAS_UNSAFE_PINNED"); } } diff --git a/examples/linked_list.rs b/examples/linked_list.rs index 8445a589..d40b5516 100644 --- a/examples/linked_list.rs +++ b/examples/linked_list.rs @@ -2,7 +2,7 @@ #![allow(clippy::undocumented_unsafe_blocks)] #![cfg_attr(feature = "alloc", feature(allocator_api))] -#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] use core::{ cell::Cell, diff --git a/examples/mutex.rs b/examples/mutex.rs index 9f295226..6b4d4920 100644 --- a/examples/mutex.rs +++ b/examples/mutex.rs @@ -2,7 +2,7 @@ #![allow(clippy::undocumented_unsafe_blocks)] #![cfg_attr(feature = "alloc", feature(allocator_api))] -#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] #![allow(clippy::missing_safety_doc)] use core::{ diff --git a/examples/pthread_mutex.rs b/examples/pthread_mutex.rs index 4e082ec7..d5bfd493 100644 --- a/examples/pthread_mutex.rs +++ b/examples/pthread_mutex.rs @@ -3,7 +3,7 @@ // inspired by #![allow(clippy::undocumented_unsafe_blocks)] #![cfg_attr(feature = "alloc", feature(allocator_api))] -#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] #[cfg(not(windows))] mod pthread_mtx { diff --git a/examples/static_init.rs b/examples/static_init.rs index 0e165daa..30b6cb43 100644 --- a/examples/static_init.rs +++ b/examples/static_init.rs @@ -2,7 +2,7 @@ #![allow(clippy::undocumented_unsafe_blocks)] #![cfg_attr(feature = "alloc", feature(allocator_api))] -#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] #![allow(unused_imports)] use core::{ diff --git a/internal/Cargo.toml b/internal/Cargo.toml index d3af5351..c8810106 100644 --- a/internal/Cargo.toml +++ b/internal/Cargo.toml @@ -21,4 +21,5 @@ syn = { version = "2.0.86", features = ["full", "parsing", "visit-mut"] } rustc_version = "0.4" [lints.rust] +stable_features = "allow" unexpected_cfgs = { level = "warn", check-cfg = ['cfg(kernel)'] } diff --git a/internal/build.rs b/internal/build.rs index 2fdb56a9..f254d07f 100644 --- a/internal/build.rs +++ b/internal/build.rs @@ -1,10 +1,12 @@ -use rustc_version::{version, Version}; +use rustc_version::{version_meta, Channel}; fn main() { - println!("cargo::rustc-check-cfg=cfg(RUSTC_LINT_REASONS_IS_STABLE)"); - if version().unwrap() >= Version::parse("1.81.0").unwrap() - || version().unwrap() >= Version::parse("1.81.0-nightly").unwrap() - { - println!("cargo:rustc-cfg=RUSTC_LINT_REASONS_IS_STABLE"); + println!("cargo::rustc-check-cfg=cfg(RUSTC_USE_FEATURE)"); + + let meta = version_meta().unwrap(); + + let use_feature = meta.channel == Channel::Nightly || std::env::var("RUSTC_BOOTSTRAP").is_ok(); + if use_feature { + println!("cargo:rustc-cfg=RUSTC_USE_FEATURE"); } } diff --git a/internal/src/lib.rs b/internal/src/lib.rs index 08372c8f..08ca5c2f 100644 --- a/internal/src/lib.rs +++ b/internal/src/lib.rs @@ -6,7 +6,7 @@ //! `pin-init` proc macros. -#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] // Documentation is done in the pin-init crate instead. #![allow(missing_docs)] diff --git a/src/lib.rs b/src/lib.rs index 49945fc0..260d1635 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -264,12 +264,9 @@ //! [`impl Init`]: crate::Init //! [Rust-for-Linux]: https://rust-for-linux.com/ -#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] #![cfg_attr( - all( - any(feature = "alloc", feature = "std"), - not(RUSTC_NEW_UNINIT_IS_STABLE) - ), + all(any(feature = "alloc", feature = "std"), RUSTC_USE_FEATURE), feature(new_uninit) )] #![forbid(missing_docs, unsafe_op_in_unsafe_fn)] diff --git a/tests/alloc_fail.rs b/tests/alloc_fail.rs index bc7937bf..2a058e8e 100644 --- a/tests/alloc_fail.rs +++ b/tests/alloc_fail.rs @@ -1,5 +1,5 @@ #![cfg_attr(feature = "alloc", feature(allocator_api))] -#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] #[test] #[cfg(feature = "alloc")] diff --git a/tests/cfgs.rs b/tests/cfgs.rs index a28d0db4..8350f607 100644 --- a/tests/cfgs.rs +++ b/tests/cfgs.rs @@ -1,4 +1,4 @@ -#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] use pin_init::{pin_data, pin_init, PinInit}; diff --git a/tests/const-generic-default.rs b/tests/const-generic-default.rs index 7660272c..0c234296 100644 --- a/tests/const-generic-default.rs +++ b/tests/const-generic-default.rs @@ -1,4 +1,4 @@ -#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] use pin_init::*; diff --git a/tests/init-scope.rs b/tests/init-scope.rs index 2ea700ab..0a94cf15 100644 --- a/tests/init-scope.rs +++ b/tests/init-scope.rs @@ -1,5 +1,5 @@ #![allow(dead_code)] -#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] use pin_init::*; diff --git a/tests/many_generics.rs b/tests/many_generics.rs index d45ac287..0c1d9bdf 100644 --- a/tests/many_generics.rs +++ b/tests/many_generics.rs @@ -1,4 +1,4 @@ -#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] #![allow(dead_code)] use core::{marker::PhantomPinned, pin::Pin}; diff --git a/tests/ring_buf.rs b/tests/ring_buf.rs index 9029f511..c1aad66e 100644 --- a/tests/ring_buf.rs +++ b/tests/ring_buf.rs @@ -1,5 +1,5 @@ #![allow(clippy::undocumented_unsafe_blocks)] -#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] #![cfg_attr(feature = "alloc", feature(allocator_api))] #[cfg(all(not(feature = "std"), feature = "alloc"))] diff --git a/tests/ui.rs b/tests/ui.rs index 4eb03f85..f20e0bd6 100644 --- a/tests/ui.rs +++ b/tests/ui.rs @@ -1,4 +1,4 @@ -#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] #[test] #[cfg_attr(not(UI_TESTS), ignore)] diff --git a/tests/ui/compile-fail/pin_data/no_pin_on_phantompinned.stderr b/tests/ui/compile-fail/pin_data/no_pin_on_phantompinned.stderr index 63d59d69..fedd62ab 100644 --- a/tests/ui/compile-fail/pin_data/no_pin_on_phantompinned.stderr +++ b/tests/ui/compile-fail/pin_data/no_pin_on_phantompinned.stderr @@ -21,26 +21,3 @@ error: The field `pin4` of type `PhantomPinned` only has an effect if it has the | 9 | pin4: ::core::marker::PhantomPinned, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error[E0425]: cannot find type `PhantomPinned` in this scope - --> tests/ui/compile-fail/pin_data/no_pin_on_phantompinned.rs:6:11 - | -6 | pin1: PhantomPinned, - | ^^^^^^^^^^^^^ not found in this scope - | -help: consider importing this struct - | -1 + use std::marker::PhantomPinned; - | - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `marker` - --> tests/ui/compile-fail/pin_data/no_pin_on_phantompinned.rs:7:11 - | -7 | pin2: marker::PhantomPinned, - | ^^^^^^ use of unresolved module or unlinked crate `marker` - | - = help: if you wanted to use a crate named `marker`, use `cargo add marker` to add it to your `Cargo.toml` -help: consider importing this module - | -1 + use std::marker; - | diff --git a/tests/ui/expand/many_generics.expanded.rs b/tests/ui/expand/many_generics.expanded.rs index 44a4efa1..35f99102 100644 --- a/tests/ui/expand/many_generics.expanded.rs +++ b/tests/ui/expand/many_generics.expanded.rs @@ -1,4 +1,3 @@ -#![feature(lint_reasons)] #![allow(dead_code)] use core::{marker::PhantomPinned, pin::Pin}; use pin_init::*; diff --git a/tests/zeroing.rs b/tests/zeroing.rs index 6d10ad77..3f013c3a 100644 --- a/tests/zeroing.rs +++ b/tests/zeroing.rs @@ -1,4 +1,4 @@ -#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] use core::{marker::PhantomPinned, ptr::addr_of_mut};