Skip to content

Commit 4718ee9

Browse files
committed
Add an intrinsic that lowers to AggregateKind::RawPtr
1 parent 3ecfe74 commit 4718ee9

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

core/src/intrinsics.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2779,6 +2779,32 @@ pub unsafe fn vtable_align(_ptr: *const ()) -> usize {
27792779
unreachable!()
27802780
}
27812781

2782+
/// Lowers in MIR to `Rvalue::Aggregate` with `AggregateKind::RawPtr`.
2783+
///
2784+
/// This is used to implement functions like `slice::from_raw_parts_mut` and
2785+
/// `ptr::from_raw_parts` in a way compatible with the compiler being able to
2786+
/// change the possible layouts of pointers.
2787+
#[rustc_nounwind]
2788+
#[unstable(feature = "core_intrinsics", issue = "none")]
2789+
#[rustc_intrinsic]
2790+
#[rustc_intrinsic_must_be_overridden]
2791+
#[cfg(not(bootstrap))]
2792+
pub const fn aggregate_raw_ptr<P: AggregateRawPtr<D, Metadata = M>, D, M>(_data: D, _meta: M) -> P {
2793+
// No fallback because `libcore` doesn't want to know the layout
2794+
unreachable!()
2795+
}
2796+
2797+
#[unstable(feature = "core_intrinsics", issue = "none")]
2798+
pub trait AggregateRawPtr<D> {
2799+
type Metadata: Copy;
2800+
}
2801+
impl<P: ?Sized, T: ptr::Thin> AggregateRawPtr<*const T> for *const P {
2802+
type Metadata = <P as ptr::Pointee>::Metadata;
2803+
}
2804+
impl<P: ?Sized, T: ptr::Thin> AggregateRawPtr<*mut T> for *mut P {
2805+
type Metadata = <P as ptr::Pointee>::Metadata;
2806+
}
2807+
27822808
// Some functions are defined here because they accidentally got made
27832809
// available in this module on stable. See <https://github.com/rust-lang/rust/issues/15702>.
27842810
// (`transmute` also falls into this category, but it cannot be wrapped due to the

0 commit comments

Comments
 (0)