From: Benno Lossin <lossin@kernel.org>
To: "Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Antonio Hickey" <contact@antoniohickey.com>,
"Christian Schrefl" <chrisi.schrefl@gmail.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Oleksandr Babak" <alexanderbabak@proton.me>
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/5] rust: pin-init: build: simplify use of nightly features
Date: Thu, 19 Mar 2026 10:35:24 +0100 [thread overview]
Message-ID: <20260319093542.3756606-2-lossin@kernel.org> (raw)
In-Reply-To: <20260319093542.3756606-1-lossin@kernel.org>
From: Gary Guo <gary@garyguo.net>
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 ]
Signed-off-by: Benno Lossin <lossin@kernel.org>
---
rust/Makefile | 4 ++--
rust/pin-init/examples/linked_list.rs | 2 +-
rust/pin-init/examples/mutex.rs | 2 +-
rust/pin-init/examples/pthread_mutex.rs | 2 +-
rust/pin-init/examples/static_init.rs | 2 +-
rust/pin-init/internal/src/lib.rs | 2 +-
rust/pin-init/src/lib.rs | 7 ++-----
7 files changed, 9 insertions(+), 12 deletions(-)
diff --git a/rust/Makefile b/rust/Makefile
index 9801af2e1e02..e92daeb3542b 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -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 \
diff --git a/rust/pin-init/examples/linked_list.rs b/rust/pin-init/examples/linked_list.rs
index 8445a5890cb7..226e33e4a957 100644
--- a/rust/pin-init/examples/linked_list.rs
+++ b/rust/pin-init/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(USE_RUSTC_FEATURES, feature(lint_reasons))]
use core::{
cell::Cell,
diff --git a/rust/pin-init/examples/mutex.rs b/rust/pin-init/examples/mutex.rs
index 9f295226cd64..e534c367f644 100644
--- a/rust/pin-init/examples/mutex.rs
+++ b/rust/pin-init/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(USE_RUSTC_FEATURES, feature(lint_reasons))]
#![allow(clippy::missing_safety_doc)]
use core::{
diff --git a/rust/pin-init/examples/pthread_mutex.rs b/rust/pin-init/examples/pthread_mutex.rs
index 4e082ec7d5de..562ca5d3d08c 100644
--- a/rust/pin-init/examples/pthread_mutex.rs
+++ b/rust/pin-init/examples/pthread_mutex.rs
@@ -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 {
diff --git a/rust/pin-init/examples/static_init.rs b/rust/pin-init/examples/static_init.rs
index 0e165daa9798..df562134a53c 100644
--- a/rust/pin-init/examples/static_init.rs
+++ b/rust/pin-init/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(USE_RUSTC_FEATURES, feature(lint_reasons))]
#![allow(unused_imports)]
use core::{
diff --git a/rust/pin-init/internal/src/lib.rs b/rust/pin-init/internal/src/lib.rs
index 08372c8f65f0..b08dfe003031 100644
--- a/rust/pin-init/internal/src/lib.rs
+++ b/rust/pin-init/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(USE_RUSTC_FEATURES, feature(lint_reasons))]
// Documentation is done in the pin-init crate instead.
#![allow(missing_docs)]
diff --git a/rust/pin-init/src/lib.rs b/rust/pin-init/src/lib.rs
index fe4c85ae3f02..b1de166b5626 100644
--- a/rust/pin-init/src/lib.rs
+++ b/rust/pin-init/src/lib.rs
@@ -264,12 +264,9 @@
//! [`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)]
--
2.53.0
next prev parent reply other threads:[~2026-03-19 9:40 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-19 9:35 [PATCH 0/5] pin-init upstream sync for v7.0 Benno Lossin
2026-03-19 9:35 ` Benno Lossin [this message]
2026-03-19 9:35 ` [PATCH 2/5] rust: pin-init: properly document let binding workaround Benno Lossin
2026-03-19 11:04 ` Gary Guo
2026-03-19 14:44 ` Benno Lossin
2026-03-19 15:18 ` Gary Guo
2026-03-19 9:35 ` [PATCH 3/5] rust: pin-init: doc: de-clutter documentation with fake-variadics Benno Lossin
2026-03-19 9:35 ` [PATCH 4/5] rust: pin-init: implement ZeroableOption for NonZero* integer types Benno Lossin
2026-03-19 9:35 ` [PATCH 5/5] rust: pin-init: replace `addr_of_mut!` with `&raw mut` Benno Lossin
2026-03-19 11:07 ` Gary Guo
2026-03-19 14:46 ` Benno Lossin
2026-03-19 9:42 ` [PATCH 0/5] pin-init upstream sync for v7.0 Benno Lossin
2026-03-26 8:23 ` Benno Lossin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260319093542.3756606-2-lossin@kernel.org \
--to=lossin@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=alexanderbabak@proton.me \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=chrisi.schrefl@gmail.com \
--cc=contact@antoniohickey.com \
--cc=dakr@kernel.org \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox