]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
rust: pin-init: build: simplify use of nightly features
authorGary Guo <gary@garyguo.net>
Thu, 19 Mar 2026 09:35:24 +0000 (10:35 +0100)
committerBenno Lossin <lossin@kernel.org>
Wed, 25 Mar 2026 09:56:16 +0000 (10:56 +0100)
We use some features that are already stable in later versions of Rust,
but only available as unstable features in older Rust versions that the
kernel needs to support.

Instead of checking if a feature is already stable, simply enable them
and allow the warning if the feature is already stable. This avoids the
need of hardcoding whether a feature has been stabilized at a given
version.

`#[feature(...)]` is used when cfg `USE_RUSTC_FEATURES` is enabled. The
build script automatically does this when a nightly compiler is detected
or `RUSTC_BOOTSTRAP` is set.

Signed-off-by: Gary Guo <gary@garyguo.net>
Link: https://github.com/Rust-for-Linux/pin-init/commit/885c5d83d7eb778a796d4a17380a0898b0d0a571
[ Added kernel build system changes to always enable USE_RUSTC_FEATURES.
  Moved this commit earlier (swapped with the next one) to avoid a build
  error. - Benno ]
Link: https://patch.msgid.link/20260319093542.3756606-2-lossin@kernel.org
Signed-off-by: Benno Lossin <lossin@kernel.org>
rust/Makefile
rust/pin-init/examples/linked_list.rs
rust/pin-init/examples/mutex.rs
rust/pin-init/examples/pthread_mutex.rs
rust/pin-init/examples/static_init.rs
rust/pin-init/internal/src/lib.rs
rust/pin-init/src/lib.rs

index 9801af2e1e027a720918284361b598ad846834f5..e92daeb3542b50208d906a234455ce1aaf7e8b28 100644 (file)
@@ -118,7 +118,7 @@ syn-flags := \
     $(call cfgs-to-flags,$(syn-cfgs))
 
 pin_init_internal-cfgs := \
-    kernel
+    kernel USE_RUSTC_FEATURES
 
 pin_init_internal-flags := \
     --extern proc_macro2 \
@@ -127,7 +127,7 @@ pin_init_internal-flags := \
     $(call cfgs-to-flags,$(pin_init_internal-cfgs))
 
 pin_init-cfgs := \
-    kernel
+    kernel USE_RUSTC_FEATURES
 
 pin_init-flags := \
     --extern pin_init_internal \
index 8445a5890cb77a9db33f6e6e3c4ec3e276598e17..226e33e4a95797a484bdb4dbed643ec69bef3d45 100644 (file)
@@ -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(USE_RUSTC_FEATURES, feature(lint_reasons))]
 
 use core::{
     cell::Cell,
index 9f295226cd64f61b2846c33cde1818d78a67b233..e534c367f6440888793837532310c9f0be72315b 100644 (file)
@@ -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(USE_RUSTC_FEATURES, feature(lint_reasons))]
 #![allow(clippy::missing_safety_doc)]
 
 use core::{
index 4e082ec7d5de26a32a7a2c2e47e6be80ef16dfcb..562ca5d3d08ceb4cb87a4eb8ed3ab837a57d6eb0 100644 (file)
@@ -3,7 +3,7 @@
 // inspired by <https://github.com/nbdd0121/pin-init/blob/trunk/examples/pthread_mutex.rs>
 #![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(USE_RUSTC_FEATURES, feature(lint_reasons))]
 
 #[cfg(not(windows))]
 mod pthread_mtx {
index 0e165daa9798daf76d339e1759f4972d788ad95e..df562134a53c877d2949365e68b9c658a4110b1c 100644 (file)
@@ -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(USE_RUSTC_FEATURES, feature(lint_reasons))]
 #![allow(unused_imports)]
 
 use core::{
index 08372c8f65f05950a9d693b2ab89e6dd561de716..b08dfe003031700130911459ac7de66f7c59768e 100644 (file)
@@ -6,7 +6,7 @@
 
 //! `pin-init` proc macros.
 
-#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))]
+#![cfg_attr(USE_RUSTC_FEATURES, feature(lint_reasons))]
 // Documentation is done in the pin-init crate instead.
 #![allow(missing_docs)]
 
index fe4c85ae3f02a89aef14966ed5e61708898235c6..b1de166b5626716feab8e4cf2a93e9031dbd586d 100644 (file)
 //! [`impl Init<T, E>`]: crate::Init
 //! [Rust-for-Linux]: https://rust-for-linux.com/
 
-#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))]
+#![cfg_attr(USE_RUSTC_FEATURES, feature(lint_reasons))]
 #![cfg_attr(
-    all(
-        any(feature = "alloc", feature = "std"),
-        not(RUSTC_NEW_UNINIT_IS_STABLE)
-    ),
+    all(any(feature = "alloc", feature = "std"), USE_RUSTC_FEATURES),
     feature(new_uninit)
 )]
 #![forbid(missing_docs, unsafe_op_in_unsafe_fn)]