Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions libs/Patches.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ into the main commit for that patch, and then the *Update* line can be removed.
functions to call built-in Crucible allocation functions instead (e.g.
`crucible::alloc::allocate`).

* Specialize `Clone` impl for `Box` to use Crucible's allocator (last applied: Feburary 26, 2026)

The default `Clone` impl for `Box` is parameterized over an arbitrary
allocator, and as a result, it has to call the `new_uninit_in` function,
which `crucible-mir` cannot easily support. We add a specialized version of
the `Clone` impl for the `Global` allocator that instead calls the more
Crucible-friendly `new_uninit` function. (See also the `` Use crucible's
allocator in `Box` constructors `` patch above.)

* Define `Arc`/`Rc` constructors in terms of `{Arc,Rc}::new` (last applied: January 20, 2026)

This ensures that all `Arc`/`Rc` constructors are defined in terms of
Expand Down
20 changes: 18 additions & 2 deletions libs/alloc/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1755,7 +1755,7 @@ impl<T: Clone, A: Allocator + Clone> Clone for Box<T, A> {
/// assert_ne!(&*x as *const i32, &*y as *const i32);
/// ```
#[inline]
fn clone(&self) -> Self {
default fn clone(&self) -> Self {
// Pre-allocate memory to allow writing the cloned value directly.
let mut boxed = Self::new_uninit_in(self.1.clone());
unsafe {
Expand All @@ -1782,11 +1782,27 @@ impl<T: Clone, A: Allocator + Clone> Clone for Box<T, A> {
/// assert_eq!(yp, &*y);
/// ```
#[inline]
fn clone_from(&mut self, source: &Self) {
default fn clone_from(&mut self, source: &Self) {
(**self).clone_from(&(**source));
}
}

// A specialized version of the Clone impl that uses new_uninit() instead of
// new_uninit_in(), as the former is more Crucible-friendly.
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Clone> Clone for Box<T, Global> {
#[inline]
fn clone(&self) -> Self {
// Pre-allocate memory to allow writing the cloned value directly.
let mut boxed = Self::new_uninit();
unsafe {
(**self).clone_to_uninit(boxed.as_mut_ptr().cast());
boxed.assume_init()
}
}
}

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "box_slice_clone", since = "1.3.0")]
impl<T: Clone, A: Allocator + Clone> Clone for Box<[T], A> {
Expand Down