We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ebe145e commit deea7a9Copy full SHA for deea7a9
library/alloc/src/boxed.rs
@@ -259,7 +259,12 @@ impl<T> Box<T> {
259
#[rustc_diagnostic_item = "box_new"]
260
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
261
pub fn new(x: T) -> Self {
262
- return box_new(x);
+ let mut b = Box::new_uninit();
263
+ let ptr = mem::MaybeUninit::as_mut_ptr(&mut *b);
264
+ // SAFETY: we just allocated the box to store `x`.
265
+ unsafe { core::intrinsics::write_via_move(ptr, x) };
266
+ // SAFETY: we just initialized `b`.
267
+ unsafe { b.assume_init() }
268
}
269
270
/// Constructs a new box with uninitialized contents.
0 commit comments