summaryrefslogtreecommitdiff
path: root/library/core/src/intrinsics.rs
diff options
context:
space:
mode:
Diffstat (limited to 'library/core/src/intrinsics.rs')
-rw-r--r--library/core/src/intrinsics.rs35
1 files changed, 30 insertions, 5 deletions
diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs
index 79bd0bbb0c1..23ded42fa66 100644
--- a/library/core/src/intrinsics.rs
+++ b/library/core/src/intrinsics.rs
@@ -1187,7 +1187,7 @@ extern "rust-intrinsic" {
/// Below are common applications of `transmute` which can be replaced with safer
/// constructs.
///
- /// Turning raw bytes (`&[u8]`) into `u32`, `f64`, etc.:
+ /// Turning raw bytes (`[u8; SZ]`) into `u32`, `f64`, etc.:
///
/// ```
/// let raw_bytes = [0x78, 0x56, 0x34, 0x12];
@@ -2257,12 +2257,23 @@ extern "rust-intrinsic" {
/// This is an implementation detail of [`crate::ptr::read`] and should
/// not be used anywhere else. See its comments for why this exists.
///
- /// This intrinsic can *only* be called where the argument is a local without
- /// projections (`read_via_copy(p)`, not `read_via_copy(*p)`) so that it
+ /// This intrinsic can *only* be called where the pointer is a local without
+ /// projections (`read_via_copy(ptr)`, not `read_via_copy(*ptr)`) so that it
/// trivially obeys runtime-MIR rules about derefs in operands.
- #[rustc_const_unstable(feature = "const_ptr_read", issue = "80377")]
+ #[rustc_const_stable(feature = "const_ptr_read", since = "CURRENT_RUSTC_VERSION")]
#[rustc_nounwind]
- pub fn read_via_copy<T>(p: *const T) -> T;
+ pub fn read_via_copy<T>(ptr: *const T) -> T;
+
+ /// This is an implementation detail of [`crate::ptr::write`] and should
+ /// not be used anywhere else. See its comments for why this exists.
+ ///
+ /// This intrinsic can *only* be called where the pointer is a local without
+ /// projections (`write_via_move(ptr, x)`, not `write_via_move(*ptr, x)`) so
+ /// that it trivially obeys runtime-MIR rules about derefs in operands.
+ #[cfg(not(bootstrap))]
+ #[rustc_const_unstable(feature = "const_ptr_write", issue = "86302")]
+ #[rustc_nounwind]
+ pub fn write_via_move<T>(ptr: *mut T, value: T);
/// Returns the value of the discriminant for the variant in 'v';
/// if `T` has no discriminant, returns `0`.
@@ -2512,6 +2523,7 @@ macro_rules! assert_unsafe_precondition {
}
}
#[allow(non_snake_case)]
+ #[inline]
const fn comptime$(<$($tt)*>)?($(_:$ty),*) {}
::core::intrinsics::const_eval_select(($($i,)*), comptime, runtime);
@@ -2828,3 +2840,16 @@ pub const unsafe fn transmute_unchecked<Src, Dst>(src: Src) -> Dst {
// SAFETY: It's a transmute -- the caller promised it's fine.
unsafe { transmute_copy(&ManuallyDrop::new(src)) }
}
+
+/// Polyfill for bootstrap
+#[cfg(bootstrap)]
+pub const unsafe fn write_via_move<T>(ptr: *mut T, value: T) {
+ use crate::mem::*;
+ // SAFETY: the caller must guarantee that `dst` is valid for writes.
+ // `dst` cannot overlap `src` because the caller has mutable access
+ // to `dst` while `src` is owned by this function.
+ unsafe {
+ copy_nonoverlapping::<T>(&value, ptr, 1);
+ forget(value);
+ }
+}