Skip to content

Commit

Permalink
rust: rbtree: avoid box_uninit_write feature
Browse files Browse the repository at this point in the history
Like commit 0903b9e ("rust: alloc: eschew
`Box<MaybeUninit<T>>::write`"), but for the new `rbtree` code.

That is, `feature(new_uninit)` [1] got partially stabilized [2]
for Rust 1.82.0 (expected to be released on 2024-10-17), but it
did not include `Box<MaybeUninit<T>>::write`, which got split into
`feature(box_uninit_write)` [3].

To avoid relying on a new unstable feature, rewrite the `write` +
`assume_init` pair manually.

Link: rust-lang/rust#63291 [1]
Link: rust-lang/rust#129401 [2]
Link: rust-lang/rust#129397 [3]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
  • Loading branch information
ojeda committed Sep 4, 2024
1 parent 68d3b6a commit 0a83b9d
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions rust/kernel/rbtree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1059,15 +1059,14 @@ impl<K, V> RBTreeNodeReservation<K, V> {
/// Initialises a node reservation.
///
/// It then becomes an [`RBTreeNode`] that can be inserted into a tree.
pub fn into_node(self, key: K, value: V) -> RBTreeNode<K, V> {
let node = Box::write(
self.node,
Node {
key,
value,
links: bindings::rb_node::default(),
},
);
pub fn into_node(mut self, key: K, value: V) -> RBTreeNode<K, V> {
self.node.write(Node {
key,
value,
links: bindings::rb_node::default(),
});
// SAFETY: We just wrote to it.
let node = unsafe { self.node.assume_init() };
RBTreeNode { node }
}
}
Expand Down

0 comments on commit 0a83b9d

Please sign in to comment.