diff options
Diffstat (limited to 'library/core/src')
| -rw-r--r-- | library/core/src/intrinsics.rs | 14 | ||||
| -rw-r--r-- | library/core/src/ptr/mod.rs | 8 |
2 files changed, 10 insertions, 12 deletions
diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index d77c2a00eb7..ee8846675ce 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -2020,16 +2020,12 @@ extern "rust-intrinsic" { #[rustc_safe_intrinsic] pub fn saturating_sub<T: Copy>(a: T, b: T) -> T; - /// This is a *typed* read, `copy *p` in MIR. + /// This is an implementation detail of [`crate::ptr::read`] and should + /// not be used anywhere else. See its comments for why this exists. /// - /// The stabilized form of this intrinsic is [`crate::ptr::read`], so - /// that can be implemented without needing to do an *untyped* copy - /// via [`copy_nonoverlapping`], and thus can get proper metadata. - /// - /// This intrinsic can *only* be called with a copy or move of a local. - /// (It allows neither constants nor projections.) - /// - /// To avoid introducing any `noalias` requirements, it just takes a pointer. + /// 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 + /// trivially obeys runtime-MIR rules about derefs in operands. #[cfg(not(bootstrap))] #[rustc_const_unstable(feature = "const_ptr_read", issue = "80377")] pub fn read_via_copy<T>(p: *const T) -> T; diff --git a/library/core/src/ptr/mod.rs b/library/core/src/ptr/mod.rs index 86929e2c488..5884a8ca308 100644 --- a/library/core/src/ptr/mod.rs +++ b/library/core/src/ptr/mod.rs @@ -1136,10 +1136,12 @@ pub const unsafe fn replace<T>(dst: *mut T, mut src: T) -> T { #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub const unsafe fn read<T>(src: *const T) -> T { // It would be semantically correct to implement this via `copy_nonoverlapping` - // and `MaybeUninit`, as was done before PR #109035. + // and `MaybeUninit`, as was done before PR #109035. Calling `assume_init` + // provides enough information to know that this is a typed operation. - // However, it switched to intrinsic that lowers to `_0 = *src` in MIR in - // order to address a few implementation issues: + // However, as of March 2023 the compiler was not capable of taking advantage + // of that information. Thus the implementation here switched to an intrinsic, + // which lowers to `_0 = *src` in MIR, to address a few issues: // // - Using `MaybeUninit::assume_init` after a `copy_nonoverlapping` was not // turning the untyped copy into a typed load. As such, the generated |
