File tree Expand file tree Collapse file tree 2 files changed +10
-12
lines changed Expand file tree Collapse file tree 2 files changed +10
-12
lines changed Original file line number Diff line number Diff line change @@ -2020,16 +2020,12 @@ extern "rust-intrinsic" {
2020
2020
#[ rustc_safe_intrinsic]
2021
2021
pub fn saturating_sub < T : Copy > ( a : T , b : T ) -> T ;
2022
2022
2023
- /// This is a *typed* read, `copy *p` in MIR.
2023
+ /// This is an implementation detail of [`crate::ptr::read`] and should
2024
+ /// not be used anywhere else. See its comments for why this exists.
2024
2025
///
2025
- /// The stabilized form of this intrinsic is [`crate::ptr::read`], so
2026
- /// that can be implemented without needing to do an *untyped* copy
2027
- /// via [`copy_nonoverlapping`], and thus can get proper metadata.
2028
- ///
2029
- /// This intrinsic can *only* be called with a copy or move of a local.
2030
- /// (It allows neither constants nor projections.)
2031
- ///
2032
- /// To avoid introducing any `noalias` requirements, it just takes a pointer.
2026
+ /// This intrinsic can *only* be called where the argument is a local without
2027
+ /// projections (`read_via_copy(p)`, not `read_via_copy(*p)`) so that it
2028
+ /// trivially obeys runtime-MIR rules about derefs in operands.
2033
2029
#[ cfg( not( bootstrap) ) ]
2034
2030
#[ rustc_const_unstable( feature = "const_ptr_read" , issue = "80377" ) ]
2035
2031
pub fn read_via_copy < T > ( p : * const T ) -> T ;
Original file line number Diff line number Diff line change @@ -1136,10 +1136,12 @@ pub const unsafe fn replace<T>(dst: *mut T, mut src: T) -> T {
1136
1136
#[ cfg_attr( miri, track_caller) ] // even without panics, this helps for Miri backtraces
1137
1137
pub const unsafe fn read < T > ( src : * const T ) -> T {
1138
1138
// It would be semantically correct to implement this via `copy_nonoverlapping`
1139
- // and `MaybeUninit`, as was done before PR #109035.
1139
+ // and `MaybeUninit`, as was done before PR #109035. Calling `assume_init`
1140
+ // provides enough information to know that this is a typed operation.
1140
1141
1141
- // However, it switched to intrinsic that lowers to `_0 = *src` in MIR in
1142
- // order to address a few implementation issues:
1142
+ // However, as of March 2023 the compiler was not capable of taking advantage
1143
+ // of that information. Thus the implementation here switched to an intrinsic,
1144
+ // which lowers to `_0 = *src` in MIR, to address a few issues:
1143
1145
//
1144
1146
// - Using `MaybeUninit::assume_init` after a `copy_nonoverlapping` was not
1145
1147
// turning the untyped copy into a typed load. As such, the generated
You can’t perform that action at this time.
0 commit comments