Skip to contentSkip to conversation

pin-init sync: test & CI fixes

PATCH Applied Benno Lossin 2 participants 7 messages May 23, 2025 – Jun 9, 2025

Subsystems (2)
lore
Share & tools
lore

Benno Lossin

author maintainer
#0 lore raw

cover pin-init sync: test & CI fixes

Several smaller problems I found in the CI related to enabled features & tests.

Upstream PR: https://github.com/Rust-for-Linux/pin-init/pull/50

Benno Lossin (3):
rust: pin-init: examples, tests: add conditional compilation in order
to compile under any feature combination
rust: pin-init: examples: pthread_mutex: disable the main test for
miri
rust: pin-init: feature-gate the stack_init_reuse test on the std
feature

 rust/pin-init/examples/big_struct_in_place.rs | 26 ++---
 rust/pin-init/examples/linked_list.rs         | 10 +-
 rust/pin-init/examples/mutex.rs               | 97 +++++++++++--------
 rust/pin-init/examples/pthread_mutex.rs       |  5 +-
 rust/pin-init/examples/static_init.rs         | 75 +++++++-------
 rust/pin-init/src/__internal.rs               |  1 +
 6 files changed, 123 insertions(+), 91 deletions(-)

base-commit: ae8b3a83fb9de394f609035041cd7a668fda2ab3

Signature · 1 line
2.49.0
author maintainer
#1 lore raw

PATCH 1/3 rust: pin-init: examples, tests: add conditional compilation in order to compile under any feature combination

From: Benno Lossin <[email protected]>

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.

---
 rust/pin-init/examples/big_struct_in_place.rs | 26 ++---
 rust/pin-init/examples/linked_list.rs         | 10 +-
 rust/pin-init/examples/mutex.rs               | 97 +++++++++++--------
 rust/pin-init/examples/pthread_mutex.rs       |  3 +
 rust/pin-init/examples/static_init.rs         | 75 +++++++-------
 5 files changed, 121 insertions(+), 90 deletions(-)
rust/pin-init/examples/big_struct_in_place.rs +15 -11
index 30d44a334ffd..b0ee793a0a0c 100644
@@ -4,6 +4,7 @@
 
 // Struct with size over 1GiB
 #[derive(Debug)]
+#[allow(dead_code)]
 pub struct BigStruct {
     buf: [u8; 1024 * 1024 * 1024],
     a: u64,
@@ -25,15 +26,18 @@ pub fn new() -> impl Init<Self> {
 }
 
 fn main() {
-    // we want to initialize the struct in-place, otherwise we would get a stackoverflow
-    let buf: Box<BigStruct> = Box::init(init!(BigStruct {
-        buf <- zeroed(),
-        a: 7,
-        b: 186,
-        c: 7789,
-        d: 34,
-        managed_buf <- ManagedBuf::new(),
-    }))
-    .unwrap();
-    println!("{}", core::mem::size_of_val(&*buf));
+    #[cfg(any(feature = "std", feature = "alloc"))]
+    {
+        // we want to initialize the struct in-place, otherwise we would get a stackoverflow
+        let buf: Box<BigStruct> = Box::init(init!(BigStruct {
+            buf <- zeroed(),
+            a: 7,
+            b: 186,
+            c: 7789,
+            d: 34,
+            managed_buf <- ManagedBuf::new(),
+        }))
+        .unwrap();
+        println!("{}", core::mem::size_of_val(&*buf));
+    }
 }
rust/pin-init/examples/linked_list.rs +9 -1
index 0bbc7b8d83a1..f9e117c7dfe0 100644
@@ -14,8 +14,9 @@
 
 use pin_init::*;
 
-#[expect(unused_attributes)]
+#[allow(unused_attributes)]
 mod error;
+#[allow(unused_imports)]
 use error::Error;
 
 #[pin_data(PinnedDrop)]
@@ -39,6 +40,7 @@ pub fn new() -> impl PinInit<Self, Infallible> {
     }
 
     #[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 @@ fn next(&self) -> &Link {
     }
 
     #[inline]
+    #[allow(dead_code)]
     fn prev(&self) -> &Link {
         unsafe { &(*self.0.get().as_ptr()).prev }
     }
@@ -137,8 +140,13 @@ fn set(&self, val: &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));
rust/pin-init/examples/mutex.rs +56 -41

143 lines not on this page · raw message

rust/pin-init/examples/pthread_mutex.rs +3 -0
index 5acc5108b954..c709dabba7eb 100644
@@ -44,6 +44,7 @@ fn drop(self: Pin<&mut Self>) {
     pub enum Error {
         #[allow(dead_code)]
         IO(std::io::Error),
+        #[allow(dead_code)]
         Alloc,
     }
 
@@ -61,6 +62,7 @@ fn from(_: AllocError) -> Self {
     }
 
     impl<T> PThreadMutex<T> {
+        #[allow(dead_code)]
         pub fn new(data: T) -> impl PinInit<Self, Error> {
             fn init_raw() -> impl PinInit<UnsafeCell<libc::pthread_mutex_t>, Error> {
                 let init = |slot: *mut UnsafeCell<libc::pthread_mutex_t>| {
@@ -103,6 +105,7 @@ fn init_raw() -> impl PinInit<UnsafeCell<libc::pthread_mutex_t>, Error> {
         }? Error)
         }
 
+        #[allow(dead_code)]
         pub fn lock(&self) -> PThreadMutexGuard<'_, T> {
             // SAFETY: raw is always initialized
             unsafe { libc::pthread_mutex_lock(self.raw.get()) };
rust/pin-init/examples/static_init.rs +38 -37

98 lines not on this page · raw message

Signature · 1 line
2.49.0
author maintainer
#2 lore raw

PATCH 2/3 rust: pin-init: examples: pthread_mutex: disable the main test for miri

In reply to Benno Lossin

From: Benno Lossin <[email protected]>

miri takes a long time to execute the test, so disable it.

---
 rust/pin-init/examples/pthread_mutex.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
rust/pin-init/examples/pthread_mutex.rs +1 -1
index c709dabba7eb..6c4d18238956 100644
@@ -139,7 +139,7 @@ fn deref_mut(&mut self) -> &mut Self::Target {
     }
 }
 
-#[cfg_attr(test, test)]
+#[cfg_attr(all(test, not(miri)), test)]
 fn main() {
     #[cfg(all(any(feature = "std", feature = "alloc"), not(windows)))]
     {
Signature · 1 line
2.49.0
reviewer
#3 lore raw

Re: [PATCH 2/3] rust: pin-init: examples: pthread_mutex: disable the main test for miri

Quoted 6 lines · Benno Lossin

From: Benno Lossin <[email protected]>

miri takes a long time to execute the test, so disable it.

I usually recommend ignoring tests rather than cfg'ing them out entirely.

#[cfg_attr(miri, ignore)]

author maintainer
#4 lore raw

Re: [PATCH 2/3] rust: pin-init: examples: pthread_mutex: disable the main test for miri

Quoted 5 lines · Alice Ryhl
Quoted 4 lines · Benno Lossin

From: Benno Lossin <[email protected]>

miri takes a long time to execute the test, so disable it.

Quoted 7 lines
Quoted 2 lines

I usually recommend ignoring tests rather than cfg'ing them out entirely.

#[cfg_attr(miri, ignore)]

Oh I didn't know you can do that!

This patch sadly already is in the main branch and I have the policy that I don't rebase that one, so I'll make another patch to fix that. (and in the future I'll wait with merging for reviews on the list :)

---
Cheers,
Benno

author maintainer
#5 lore raw

PATCH 3/3 rust: pin-init: feature-gate the `stack_init_reuse` test on the `std` feature

In reply to Benno Lossin

From: Benno Lossin <[email protected]>

When trying to run cargo check --all-targets --no-default-features, an error is reported by the test, as it cannot find the std crate. This is to be expected, since the --no-default-features flag enables the no-std behavior of the crate. Thus exclude the test in that scenario.

---
 rust/pin-init/src/__internal.rs | 1 +
 1 file changed, 1 insertion(+)
rust/pin-init/src/__internal.rs +1 -0
index 557b5948cddc..90f18e9a2912 100644
@@ -188,6 +188,7 @@ pub fn init<E>(self: Pin<&mut Self>, init: impl PinInit<T, E>) -> Result<Pin<&mu
 }
 
 #[test]
+#[cfg(feature = "std")]
 fn stack_init_reuse() {
     use ::std::{borrow::ToOwned, println, string::String};
     use core::pin::pin;
Signature · 1 line
2.49.0
author maintainer Applied
#6 lore raw
In reply to Benno Lossin
Quoted 22 lines · Benno Lossin

Several smaller problems I found in the CI related to enabled features & tests.

Upstream PR: https://github.com/Rust-for-Linux/pin-init/pull/50

Benno Lossin (3):
rust: pin-init: examples, tests: add conditional compilation in order
to compile under any feature combination
rust: pin-init: examples: pthread_mutex: disable the main test for
miri
rust: pin-init: feature-gate the stack_init_reuse test on the std
feature

 rust/pin-init/examples/big_struct_in_place.rs | 26 ++---
 rust/pin-init/examples/linked_list.rs         | 10 +-
 rust/pin-init/examples/mutex.rs               | 97 +++++++++++--------
 rust/pin-init/examples/pthread_mutex.rs       |  5 +-
 rust/pin-init/examples/static_init.rs         | 75 +++++++-------
 rust/pin-init/src/__internal.rs               |  1 +
 6 files changed, 123 insertions(+), 91 deletions(-)
Quoted 1 line

base-commit: ae8b3a83fb9de394f609035041cd7a668fda2ab3

Applied to pin-init-next -- thanks everyone!

---
Cheers,
Benno