summaryrefslogtreecommitdiff
path: root/rust/pin-init/examples/linked_list.rs
diff options
context:
space:
mode:
authorBenno Lossin <benno.lossin@proton.me>2025-05-23 14:54:11 +0200
committerBenno Lossin <lossin@kernel.org>2025-06-11 21:13:56 +0200
commit58cebd68882edd407c7f65ebb4a42034bc1ffc6d (patch)
tree45091b6a2622f9130b7aa0830d1c5dc3bf44be15 /rust/pin-init/examples/linked_list.rs
parente832374ccadf4d1ce7bd40a85b9320bd7fbb3628 (diff)
rust: pin-init: examples, tests: add conditional compilation in order to compile under any feature combination
In the CI, all examples & tests should be run under all feature combinations. Currently several examples & tests use `std` without conditionally enabling it. Thus make them all compile under any feature combination by conditionally disabling the code that uses e.g. `std`. Link: https://github.com/Rust-for-Linux/pin-init/pull/50/commits/fdfb70efddbc711b4543c850ee38a2f5a8d17cb6 Link: https://lore.kernel.org/all/20250523125424.192843-2-lossin@kernel.org Signed-off-by: Benno Lossin <lossin@kernel.org>
Diffstat (limited to 'rust/pin-init/examples/linked_list.rs')
-rw-r--r--rust/pin-init/examples/linked_list.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/rust/pin-init/examples/linked_list.rs b/rust/pin-init/examples/linked_list.rs
index 0bbc7b8d83a1..f9e117c7dfe0 100644
--- a/rust/pin-init/examples/linked_list.rs
+++ b/rust/pin-init/examples/linked_list.rs
@@ -14,8 +14,9 @@ use core::{
use pin_init::*;
-#[expect(unused_attributes)]
+#[allow(unused_attributes)]
mod error;
+#[allow(unused_imports)]
use error::Error;
#[pin_data(PinnedDrop)]
@@ -39,6 +40,7 @@ impl ListHead {
}
#[inline]
+ #[allow(dead_code)]
pub fn insert_next(list: &ListHead) -> impl PinInit<Self, Infallible> + '_ {
try_pin_init!(&this in Self {
prev: list.next.prev().replace(unsafe { Link::new_unchecked(this)}),
@@ -112,6 +114,7 @@ impl Link {
}
#[inline]
+ #[allow(dead_code)]
fn prev(&self) -> &Link {
unsafe { &(*self.0.get().as_ptr()).prev }
}
@@ -138,7 +141,12 @@ impl Link {
}
#[allow(dead_code)]
+#[cfg(not(any(feature = "std", feature = "alloc")))]
+fn main() {}
+
+#[allow(dead_code)]
#[cfg_attr(test, test)]
+#[cfg(any(feature = "std", feature = "alloc"))]
fn main() -> Result<(), Error> {
let a = Box::pin_init(ListHead::new())?;
stack_pin_init!(let b = ListHead::insert_next(&a));