public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
* [rpms/rust-circular-buffer] epel9: EPEL9: Patch for Rust 1.92
@ 2026-07-17 14:31 Benjamin A. Beasley
  0 siblings, 0 replies; only message in thread
From: Benjamin A. Beasley @ 2026-07-17 14:31 UTC (permalink / raw)
  To: git-commits

A new commit has been pushed.

Repo   : rpms/rust-circular-buffer
Branch : epel9
Commit : c0be996b07262883478ab9c2df46e79a49043b0b
Author : Benjamin A. Beasley <code@musicinmybrain.net>
Date   : 2026-07-17T07:01:50+01:00
Stats  : +219/-1 in 4 file(s)
URL    : https://src.fedoraproject.org/rpms/rust-circular-buffer/c/c0be996b07262883478ab9c2df46e79a49043b0b?branch=epel9

Log:
EPEL9: Patch for Rust 1.92

---
diff --git a/0001-EPEL9-Revert-Use-stabilized-Rust-features.patch b/0001-EPEL9-Revert-Use-stabilized-Rust-features.patch
new file mode 100644
index 0000000..427aa8b
--- /dev/null
+++ b/0001-EPEL9-Revert-Use-stabilized-Rust-features.patch
@@ -0,0 +1,188 @@
+From ecabab9dabcb25a1a1378cf8c67f12ba4a9bcc93 Mon Sep 17 00:00:00 2001
+From: "Benjamin A. Beasley" <code@musicinmybrain.net>
+Date: Fri, 17 Jul 2026 06:51:23 +0100
+Subject: [PATCH] EPEL9: Revert "Use stabilized Rust features"
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Don’t require Rust 1.93 yet; EPEL9 has 1.92 for now.
+
+This reverts commit 2cf0a457fc60af1e9d1cd99e0349aa5844fe7fd4.
+---
+ src/drain.rs |  6 +++--
+ src/lib.rs   | 74 +++++++++++++++++++++++++++++++++++++++++++++++-----
+ 2 files changed, 71 insertions(+), 9 deletions(-)
+
+diff --git a/src/drain.rs b/src/drain.rs
+index 286693d..485b3b8 100644
+--- a/src/drain.rs
++++ b/src/drain.rs
+@@ -5,6 +5,8 @@ use crate::CircularBuffer;
+ use crate::add_mod;
+ use crate::iter::Iter;
+ use crate::iter::translate_range_bounds;
++use crate::slice_assume_init_mut;
++use crate::slice_assume_init_ref;
+ use core::fmt;
+ use core::iter::FusedIterator;
+ use core::marker::PhantomData;
+@@ -132,7 +134,7 @@ impl<'a, T> Drain<'a, T> {
+         };
+ 
+         // SAFETY: The elements in these slices are guaranteed to be initialized
+-        unsafe { (right.assume_init_ref(), left.assume_init_ref()) }
++        unsafe { (slice_assume_init_ref(right), slice_assume_init_ref(left)) }
+     }
+ 
+     fn as_mut_slices(&mut self) -> (&mut [T], &mut [T]) {
+@@ -160,7 +162,7 @@ impl<'a, T> Drain<'a, T> {
+         };
+ 
+         // SAFETY: The elements in these slices are guaranteed to be initialized
+-        unsafe { (right.assume_init_mut(), left.assume_init_mut()) }
++        unsafe { (slice_assume_init_mut(right), slice_assume_init_mut(left)) }
+     }
+ }
+ 
+diff --git a/src/lib.rs b/src/lib.rs
+index c852d3f..f15dc22 100644
+--- a/src/lib.rs
++++ b/src/lib.rs
+@@ -303,6 +303,22 @@ const fn sub_mod(x: usize, y: usize, m: usize) -> usize {
+     add_mod(x, m - y, m)
+ }
+ 
++#[inline]
++const unsafe fn slice_assume_init_ref<T>(slice: &[MaybeUninit<T>]) -> &[T] {
++    // TODO: replace with `slice.assume_init_ref()` once it's stabilized
++    //
++    // SAFETY: upheld by the caller
++    unsafe { &*(slice as *const [MaybeUninit<T>] as *const [T]) }
++}
++
++#[inline]
++unsafe fn slice_assume_init_mut<T>(slice: &mut [MaybeUninit<T>]) -> &mut [T] {
++    // TODO: replace with `slice.assume_init_mut()` once it's stabilized
++    //
++    // SAFETY: upheld by the caller
++    unsafe { &mut *(slice as *mut [MaybeUninit<T>] as *mut [T]) }
++}
++
+ /// Internal structure shared by `CircularBuffer`, `FixedCircularBuffer`, and `HeapCircularBuffer`.
+ ///
+ /// The main purpose of this structure is to allow safe coercion to `CircularBuffer`. It may go
+@@ -690,7 +706,7 @@ impl<T> CircularBuffer<T> {
+         };
+ 
+         // SAFETY: The elements in the slice are guaranteed to be initialized
+-        unsafe { slice.assume_init_mut() }
++        unsafe { slice_assume_init_mut(slice) }
+     }
+ 
+     /// Returns a pair of slices which contain the elements of this buffer.
+@@ -737,7 +753,7 @@ impl<T> CircularBuffer<T> {
+         };
+ 
+         // SAFETY: The elements in these slices are guaranteed to be initialized
+-        unsafe { (front.assume_init_ref(), back.assume_init_ref()) }
++        unsafe { (slice_assume_init_ref(front), slice_assume_init_ref(back)) }
+     }
+ 
+     /// Returns a pair of mutable slices which contain the elements of this buffer.
+@@ -789,7 +805,7 @@ impl<T> CircularBuffer<T> {
+         };
+ 
+         // SAFETY: The elements in these slices are guaranteed to be initialized
+-        unsafe { (front.assume_init_mut(), back.assume_init_mut()) }
++        unsafe { (slice_assume_init_mut(front), slice_assume_init_mut(back)) }
+     }
+ 
+     #[inline]
+@@ -917,7 +933,7 @@ impl<T> CircularBuffer<T> {
+                 // SAFETY: the caller of `drop_range` is responsible to check that this slice was
+                 // initialized.
+                 unsafe {
+-                    ptr::drop_in_place(self.0.assume_init_mut());
++                    ptr::drop_in_place(slice_assume_init_mut(self.0));
+                 }
+             }
+         }
+@@ -1936,6 +1952,50 @@ where
+         debug_assert!(self.inner.start < self.capacity(), "start out-of-bounds");
+         debug_assert!(self.inner.size <= self.capacity(), "size out-of-bounds");
+ 
++        // TODO: replace with `slice.write_clone_of_slice()` once it's stabilized
++        fn write_uninit_slice_cloned<T: Clone>(dst: &mut [MaybeUninit<T>], src: &[T]) {
++            // Each call to `clone()` may panic, therefore we need to track how many elements we
++            // successfully cloned so that we can drop them in case of panic. This `Guard` struct
++            // does exactly that: it keeps track of how many items have been successfully cloned
++            // and drops them if the guard is dropped.
++            //
++            // This implementation was highly inspired by the implementation of
++            // `MaybeUninit::clone_from_slice`
++            struct Guard<'a, T> {
++                dst: &'a mut [MaybeUninit<T>],
++                initialized: usize,
++            }
++
++            impl<T> Drop for Guard<'_, T> {
++                fn drop(&mut self) {
++                    let initialized = &mut self.dst[..self.initialized];
++                    // SAFETY: this slice contain only initialized objects; `MaybeUninit<T>` has
++                    // the same alignment and size as `T`
++                    unsafe {
++                        let initialized =
++                            &mut *(initialized as *mut [MaybeUninit<T>] as *mut [T]);
++                        ptr::drop_in_place(initialized);
++                    }
++                }
++            }
++
++            debug_assert_eq!(dst.len(), src.len());
++            let len = dst.len();
++            let mut guard = Guard {
++                dst,
++                initialized: 0,
++            };
++            #[allow(clippy::needless_range_loop)]
++            for i in 0..len {
++                guard.dst[i].write(src[i].clone());
++                guard.initialized += 1;
++            }
++
++            // All the `clone()` calls succeded; get rid of the guard without running its `drop()`
++            // implementation
++            mem::forget(guard);
++        }
++
+         if other.len() < self.capacity() {
+             // All the elements of `other` fit into the buffer
+             let free_size = self.capacity() - self.inner.size;
+@@ -1952,12 +2012,12 @@ where
+             let (right, left) = self.slices_uninit_mut();
+ 
+             let write_len = core::cmp::min(right.len(), other.len());
+-            right[..write_len].write_clone_of_slice(&other[..write_len]);
++            write_uninit_slice_cloned(&mut right[..write_len], &other[..write_len]);
+ 
+             let other = &other[write_len..];
+             debug_assert!(left.len() >= other.len());
+             let write_len = other.len();
+-            left[..write_len].write_clone_of_slice(other);
++            write_uninit_slice_cloned(&mut left[..write_len], other);
+ 
+             self.inner.size = final_size;
+         } else {
+@@ -1968,7 +2028,7 @@ where
+ 
+             let other = &other[other.len() - self.capacity()..];
+             debug_assert_eq!(self.inner.items.len(), other.len());
+-            self.inner.items.write_clone_of_slice(other);
++            write_uninit_slice_cloned(&mut self.inner.items, other);
+ 
+             self.inner.size = self.capacity();
+         }
+-- 
+2.55.0
+

diff --git a/circular-buffer-fix-metadata.diff b/circular-buffer-fix-metadata.diff
index f446c22..33af930 100644
--- a/circular-buffer-fix-metadata.diff
+++ b/circular-buffer-fix-metadata.diff
@@ -1,5 +1,14 @@
 --- circular-buffer-2.0.0/Cargo.toml	2006-07-24T01:21:28+00:00
-+++ circular-buffer-2.0.0/Cargo.toml	2026-07-02T06:58:29.289943+00:00
++++ circular-buffer-2.0.0/Cargo.toml	2026-07-17T06:01:41.637917+00:00
+@@ -11,7 +11,7 @@
+ 
+ [package]
+ edition = "2024"
+-rust-version = "1.93.0"
++rust-version = "1.87"
+ name = "circular-buffer"
+ version = "2.0.0"
+ authors = ["Andrea Corbellini <corbellini.andrea@gmail.com>"]
 @@ -79,9 +79,6 @@
  optional = true
  default-features = false

diff --git a/rust-circular-buffer.spec b/rust-circular-buffer.spec
index 2246ed2..2d27c47 100644
--- a/rust-circular-buffer.spec
+++ b/rust-circular-buffer.spec
@@ -14,7 +14,14 @@ URL:            https://crates.io/crates/circular-buffer
 Source:         %{crates_source}
 # Manually created patch for downstream crate metadata changes
 # * Do not depend on criterion; it is needed only for benchmarks.
+# * EPEL9: allow Rust 1.92 (and back to 1.87); see
+#   0001-EPEL9-Revert-Use-stabilized-Rust-features.patch.
 Patch:          circular-buffer-fix-metadata.diff
+# * EPEL9: Revert "Use stabilized Rust features"
+# * Don’t require Rust 1.93 yet; EPEL9 has 1.92 for now.
+# * This reverts commit 2cf0a457fc60af1e9d1cd99e0349aa5844fe7fd4.
+# * This is the source changes only.
+Patch10:        0001-EPEL9-Revert-Use-stabilized-Rust-features.patch
 
 BuildRequires:  cargo-rpm-macros >= 24
 

diff --git a/rust2rpm.toml b/rust2rpm.toml
index 25b65b9..f86eaf6 100644
--- a/rust2rpm.toml
+++ b/rust2rpm.toml
@@ -1,6 +1,20 @@
 [package]
 cargo-toml-patch-comments = [
     "Do not depend on criterion; it is needed only for benchmarks.",
+    """\
+EPEL9: allow Rust 1.92 (and back to 1.87); see \
+0001-EPEL9-Revert-Use-stabilized-Rust-features.patch.\
+""",
+]
+
+[[package.extra-patches]]
+number = 10
+file = "0001-EPEL9-Revert-Use-stabilized-Rust-features.patch"
+comments = [
+    "EPEL9: Revert \"Use stabilized Rust features\"",
+    "Don’t require Rust 1.93 yet; EPEL9 has 1.92 for now.",
+    "This reverts commit 2cf0a457fc60af1e9d1cd99e0349aa5844fe7fd4.",
+    "This is the source changes only.",
 ]
 
 [features]

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-07-17 14:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-17 14:31 [rpms/rust-circular-buffer] epel9: EPEL9: Patch for Rust 1.92 Benjamin A. Beasley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox