Rollup merge of #80886 - RalfJung:stable-raw-ref-macros, r=m-ou-se
Stabilize raw ref macros This stabilizes `raw_ref_macros` (https://github.com/rust-lang/rust/issues/73394), which is possible now that https://github.com/rust-lang/rust/issues/74355 is fixed. However, as I already said in https://github.com/rust-lang/rust/issues/73394#issuecomment-751342185, I am not particularly happy with the current names of the macros. So I propose we also change them, which means I am proposing to stabilize the following in `core::ptr`: ```rust pub macro const_addr_of($e:expr) { &raw const $e } pub macro mut_addr_of($e:expr) { &raw mut $e } ``` The macro name change means we need another round of FCP. Cc `````@rust-lang/libs````` Fixes #73394
This commit is contained in:
commit
b94d84d38a
11 changed files with 30 additions and 37 deletions
|
@ -545,8 +545,8 @@ impl<'a, K, V, Type> NodeRef<marker::ValMut<'a>, K, V, Type> {
|
|||
// to avoid aliasing with outstanding references to other elements,
|
||||
// in particular, those returned to the caller in earlier iterations.
|
||||
let leaf = Self::as_leaf_ptr(&mut self);
|
||||
let keys = unsafe { &raw const (*leaf).keys };
|
||||
let vals = unsafe { &raw mut (*leaf).vals };
|
||||
let keys = unsafe { ptr::addr_of!((*leaf).keys) };
|
||||
let vals = unsafe { ptr::addr_of_mut!((*leaf).vals) };
|
||||
// We must coerce to unsized array pointers because of Rust issue #74679.
|
||||
let keys: *const [_] = keys;
|
||||
let vals: *mut [_] = vals;
|
||||
|
|
|
@ -116,7 +116,6 @@
|
|||
#![feature(pattern)]
|
||||
#![feature(ptr_internals)]
|
||||
#![feature(range_bounds_assert_len)]
|
||||
#![feature(raw_ref_op)]
|
||||
#![feature(rustc_attrs)]
|
||||
#![feature(receiver_trait)]
|
||||
#![cfg_attr(bootstrap, feature(min_const_generics))]
|
||||
|
|
|
@ -398,7 +398,7 @@ impl<T> Rc<T> {
|
|||
|
||||
unsafe {
|
||||
let inner = init_ptr.as_ptr();
|
||||
ptr::write(&raw mut (*inner).value, data);
|
||||
ptr::write(ptr::addr_of_mut!((*inner).value), data);
|
||||
|
||||
let prev_value = (*inner).strong.get();
|
||||
debug_assert_eq!(prev_value, 0, "No prior strong references should exist");
|
||||
|
@ -804,7 +804,7 @@ impl<T: ?Sized> Rc<T> {
|
|||
// SAFETY: This cannot go through Deref::deref or Rc::inner because
|
||||
// this is required to retain raw/mut provenance such that e.g. `get_mut` can
|
||||
// write through the pointer after the Rc is recovered through `from_raw`.
|
||||
unsafe { &raw const (*ptr).value }
|
||||
unsafe { ptr::addr_of_mut!((*ptr).value) }
|
||||
}
|
||||
|
||||
/// Constructs an `Rc<T>` from a raw pointer.
|
||||
|
@ -1917,7 +1917,7 @@ impl<T: ?Sized> Weak<T> {
|
|||
// SAFETY: if is_dangling returns false, then the pointer is dereferencable.
|
||||
// The payload may be dropped at this point, and we have to maintain provenance,
|
||||
// so use raw pointer manipulation.
|
||||
unsafe { &raw const (*ptr).value }
|
||||
unsafe { ptr::addr_of_mut!((*ptr).value) }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -384,7 +384,7 @@ impl<T> Arc<T> {
|
|||
// reference into a strong reference.
|
||||
unsafe {
|
||||
let inner = init_ptr.as_ptr();
|
||||
ptr::write(&raw mut (*inner).data, data);
|
||||
ptr::write(ptr::addr_of_mut!((*inner).data), data);
|
||||
|
||||
// The above write to the data field must be visible to any threads which
|
||||
// observe a non-zero strong count. Therefore we need at least "Release" ordering
|
||||
|
@ -800,7 +800,7 @@ impl<T: ?Sized> Arc<T> {
|
|||
// SAFETY: This cannot go through Deref::deref or RcBoxPtr::inner because
|
||||
// this is required to retain raw/mut provenance such that e.g. `get_mut` can
|
||||
// write through the pointer after the Rc is recovered through `from_raw`.
|
||||
unsafe { &raw const (*ptr).data }
|
||||
unsafe { ptr::addr_of_mut!((*ptr).data) }
|
||||
}
|
||||
|
||||
/// Constructs an `Arc<T>` from a raw pointer.
|
||||
|
@ -1677,7 +1677,7 @@ impl<T: ?Sized> Weak<T> {
|
|||
// SAFETY: if is_dangling returns false, then the pointer is dereferencable.
|
||||
// The payload may be dropped at this point, and we have to maintain provenance,
|
||||
// so use raw pointer manipulation.
|
||||
unsafe { &raw mut (*ptr).data }
|
||||
unsafe { ptr::addr_of_mut!((*ptr).data) }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue