Skip to content

Commit 3ca2b21

Browse files
committed
move intrinsic to alloc::intrinsics
1 parent fae65f8 commit 3ca2b21

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

library/alloc/src/boxed.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -248,16 +248,6 @@ unsafe fn box_new_uninit(size: usize, align: usize) -> *mut u8 {
248248
}
249249
}
250250

251-
/// Writes `x` into `b`.
252-
///
253-
/// This is needed for `vec!`, which can't afford any extra copies of the argument (or else debug
254-
/// builds regress), has to be written fully as a call chain without `let` (or else the temporary
255-
/// lifetimes of the arguments change), and can't use an `unsafe` block as that would then also
256-
/// include the user-provided `$x`.
257-
#[rustc_intrinsic]
258-
#[unstable(feature = "liballoc_internals", issue = "none")]
259-
pub fn write_box_via_move<T>(b: Box<MaybeUninit<T>>, x: T) -> Box<MaybeUninit<T>>;
260-
261251
/// Helper internally invoked by `write_box_via_move` (since doing the same in pure MIR,
262252
/// including all the same lifetime effects, seems impossible).
263253
#[lang = "box_uninit_as_mut_ptr"]

library/alloc/src/intrinsics.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//! Intrinsics that cannot be moved to `core` because they depend on `alloc` types.
2+
#![unstable(feature = "liballoc_internals", issue = "none")]
3+
4+
use core::mem::MaybeUninit;
5+
6+
use crate::boxed::Box;
7+
8+
/// Writes `x` into `b`.
9+
///
10+
/// This is needed for `vec!`, which can't afford any extra copies of the argument (or else debug
11+
/// builds regress), has to be written fully as a call chain without `let` (or else the temporary
12+
/// lifetimes of the arguments change), and can't use an `unsafe` block as that would then also
13+
/// include the user-provided `$x`.
14+
#[rustc_intrinsic]
15+
pub fn write_box_via_move<T>(b: Box<MaybeUninit<T>>, x: T) -> Box<MaybeUninit<T>>;

library/alloc/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ pub mod collections;
218218
#[cfg(all(not(no_rc), not(no_sync), not(no_global_oom_handling)))]
219219
pub mod ffi;
220220
pub mod fmt;
221+
pub mod intrinsics;
221222
#[cfg(not(no_rc))]
222223
pub mod rc;
223224
pub mod slice;

library/alloc/src/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ macro_rules! vec {
5454
// This function isn't actually safe but the way we use it here is. We can't use an
5555
// unsafe block as that would also wrap `$x`.
5656
$crate::boxed::box_uninit_array_into_vec_unsafe(
57-
$crate::boxed::write_box_via_move($crate::boxed::Box::new_uninit(), [$($x),+])
57+
$crate::intrinsics::write_box_via_move($crate::boxed::Box::new_uninit(), [$($x),+])
5858
)
5959
);
6060
}

tests/mir-opt/building/write_box_via_move.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
//@ compile-flags: -Zmir-opt-level=0
33
#![feature(liballoc_internals)]
44

5+
extern crate alloc;
6+
57
// Can't emit `built.after` here as that contains user type annotations which contain DefId that
68
// change all the time.
79
// EMIT_MIR write_box_via_move.box_new.CleanupPostBorrowck.after.mir
@@ -11,7 +13,7 @@ fn box_new<T: Copy>(x: T) -> Box<[T; 1024]> {
1113
let mut b = Box::new_uninit();
1214
// Ensure the array gets constructed directly into the deref'd pointer.
1315
// CHECK: (*[[TEMP1:_.+]]) = [{{(move|copy) _.+}}; 1024];
14-
unsafe { std::boxed::write_box_via_move(b, [x; 1024]).assume_init() }
16+
unsafe { alloc::intrinsics::write_box_via_move(b, [x; 1024]).assume_init() }
1517
}
1618

1719
// EMIT_MIR write_box_via_move.vec_macro.CleanupPostBorrowck.after.mir

0 commit comments

Comments
 (0)