Skip to content

Commit d36e960

Browse files
tcoratgerclaude
andauthored
Remove MaybeUninit slice helpers now stabilized in std (#1606)
Removes two `MaybeUninit` slice helpers from `binius-utils` and switches the one caller to the standard-library method. Pure refactor — no behavior change. ### The problem `crates/utils/src/mem.rs` carried two hand-rolled helpers, each with a comment saying "this can be removed when [rust-lang/rust#63569](rust-lang/rust#63569) is stabilized": - `slice_assume_init_mut(&mut [MaybeUninit<T>]) -> &mut [T]` - `slice_assume_init_ref(&[MaybeUninit<T>]) -> &[T]` That issue has since stabilized. The methods now live on the slice type itself as `<[MaybeUninit<T>]>::assume_init_mut()` and `assume_init_ref()`, available on stable from edition 2024 — which is what this repo builds on (Rust 1.95.0). ### The change One caller used `slice_assume_init_mut`, in `crates/hash/src/binary_merkle_tree.rs`: ```diff - slice_assume_init_mut(prev_layer) + prev_layer.assume_init_mut() - slice_assume_init_mut(next_layer) + next_layer.assume_init_mut() ``` The two operations are identical — both reinterpret an initialized `[MaybeUninit<T>]` as `[T]` — so the `unsafe` safety argument at each call site is unchanged. ### Scope - **removed:** `slice_assume_init_mut` and `slice_assume_init_ref` from `mem.rs`. The latter had zero call sites — it was dead code. - **kept:** `slice_uninit_mut` (`&mut [T] -> &mut [MaybeUninit<T>]`) — std still has no stable equivalent for that direction. - **changed:** two call sites + one import in `binary_merkle_tree.rs`. ### Verification - `cargo check --workspace --all-targets`, `cargo clippy -p binius-utils -p binius-hash`, nightly `cargo fmt --all` — clean - `cargo test -p binius-hash` — 7 passed - Confirmed the std methods compile with no `#![feature(...)]` gate against the repo's 1.95.0 toolchain 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 6867453 commit d36e960

2 files changed

Lines changed: 2 additions & 35 deletions

File tree

crates/hash/src/binary_merkle_tree.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::{fmt::Debug, mem::MaybeUninit};
66
use binius_field::Field;
77
use binius_utils::{
88
checked_arithmetics::log2_strict_usize,
9-
mem::slice_assume_init_mut,
109
rand::par_rand,
1110
rayon::{prelude::*, slice::ParallelSlice},
1211
};
@@ -126,7 +125,7 @@ where
126125

127126
let mut prev_layer = unsafe {
128127
// SAFETY: prev-layer was initialized by hash_leaves
129-
slice_assume_init_mut(prev_layer)
128+
prev_layer.assume_init_mut()
130129
};
131130
let parallel_compression = H::ParCompression::default();
132131
for i in 1..(log_len + 1) {
@@ -137,7 +136,7 @@ where
137136

138137
prev_layer = unsafe {
139138
// SAFETY: next_layer was just initialized by compress_layer
140-
slice_assume_init_mut(next_layer)
139+
next_layer.assume_init_mut()
141140
};
142141
}
143142

crates/utils/src/mem.rs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,35 +30,3 @@ pub fn slice_uninit_mut<T>(slice: &mut [T]) -> &mut [MaybeUninit<T>] {
3030
std::slice::from_raw_parts_mut(slice.as_mut_ptr() as *mut MaybeUninit<T>, slice.len())
3131
}
3232
}
33-
34-
/// This can be removed when MaybeUninit::slice_assume_init_mut is stabilized
35-
/// <https://github.com/rust-lang/rust/issues/63569>
36-
///
37-
/// # Safety
38-
///
39-
/// It is up to the caller to guarantee that the `MaybeUninit<T>` elements
40-
/// really are in an initialized state.
41-
/// Calling this when the content is not yet fully initialized causes undefined behavior.
42-
///
43-
/// See [`assume_init_mut`] for more details and examples.
44-
///
45-
/// [`assume_init_mut`]: MaybeUninit::assume_init_mut
46-
pub const unsafe fn slice_assume_init_mut<T>(slice: &mut [MaybeUninit<T>]) -> &mut [T] {
47-
unsafe { std::mem::transmute(slice) }
48-
}
49-
50-
/// This can be removed when MaybeUninit::slice_assume_init_ref is stabilized
51-
/// <https://github.com/rust-lang/rust/issues/63569>
52-
///
53-
/// # Safety
54-
///
55-
/// It is up to the caller to guarantee that the `MaybeUninit<T>` elements
56-
/// really are in an initialized state.
57-
/// Calling this when the content is not yet fully initialized causes undefined behavior.
58-
///
59-
/// See [`assume_init_ref`] for more details and examples.
60-
///
61-
/// [`assume_init_ref`]: MaybeUninit::assume_init_ref
62-
pub const unsafe fn slice_assume_init_ref<T>(slice: &[MaybeUninit<T>]) -> &[T] {
63-
unsafe { std::mem::transmute(slice) }
64-
}

0 commit comments

Comments
 (0)