Use &raw in the standard library · qinheping/verify-rust-std@ff45313 (original) (raw)

`@@ -787,7 +787,7 @@ impl<T, A: Allocator> Rc<T, A> {

`

787

787

``

788

788

`let strong = unsafe {

`

789

789

`let inner = init_ptr.as_ptr();

`

790

``

`-

ptr::write(ptr::addr_of_mut!((*inner).value), data);

`

``

790

`+

ptr::write(&raw mut (*inner).value, data);

`

791

791

``

792

792

`let prev_value = (*inner).strong.get();

`

793

793

`debug_assert_eq!(prev_value, 0, "No prior strong references should exist");

`

`@@ -1442,7 +1442,7 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {

`

1442

1442

`// SAFETY: This cannot go through Deref::deref or Rc::inner because

`

1443

1443

`` // this is required to retain raw/mut provenance such that e.g. get_mut can

``

1444

1444

`` // write through the pointer after the Rc is recovered through from_raw.

``

1445

``

`-

unsafe { ptr::addr_of_mut!((*ptr).value) }

`

``

1445

`+

unsafe { &raw mut (*ptr).value }

`

1446

1446

`}

`

1447

1447

``

1448

1448

`` /// Constructs an Rc<T, A> from a raw pointer in the provided allocator.

``

`@@ -2042,8 +2042,8 @@ impl<T: ?Sized> Rc {

`

2042

2042

`unsafe {

`

2043

2043

`debug_assert_eq!(Layout::for_value_raw(inner), layout);

`

2044

2044

``

2045

``

`-

ptr::addr_of_mut!((*inner).strong).write(Cell::new(1));

`

2046

``

`-

ptr::addr_of_mut!((*inner).weak).write(Cell::new(1));

`

``

2045

`+

(&raw mut (*inner).strong).write(Cell::new(1));

`

``

2046

`+

(&raw mut (*inner).weak).write(Cell::new(1));

`

2047

2047

`}

`

2048

2048

``

2049

2049

`Ok(inner)

`

`@@ -2072,8 +2072,8 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {

`

2072

2072

``

2073

2073

`// Copy value as bytes

`

2074

2074

` ptr::copy_nonoverlapping(

`

2075

``

`-

core::ptr::addr_of!(*src) as *const u8,

`

2076

``

`-

ptr::addr_of_mut!((*ptr).value) as *mut u8,

`

``

2075

`+

(&raw const *src) as *const u8,

`

``

2076

`+

(&raw mut (*ptr).value) as *mut u8,

`

2077

2077

` value_size,

`

2078

2078

`);

`

2079

2079

``

`@@ -2107,11 +2107,7 @@ impl Rc<[T]> {

`

2107

2107

`unsafe fn copy_from_slice(v: &[T]) -> Rc<[T]> {

`

2108

2108

`unsafe {

`

2109

2109

`let ptr = Self::allocate_for_slice(v.len());

`

2110

``

`-

ptr::copy_nonoverlapping(

`

2111

``

`-

v.as_ptr(),

`

2112

``

`-

ptr::addr_of_mut!((*ptr).value) as *mut T,

`

2113

``

`-

v.len(),

`

2114

``

`-

);

`

``

2110

`+

ptr::copy_nonoverlapping(v.as_ptr(), (&raw mut (*ptr).value) as *mut T, v.len());

`

2115

2111

`Self::from_ptr(ptr)

`

2116

2112

`}

`

2117

2113

`}

`

`@@ -2149,7 +2145,7 @@ impl Rc<[T]> {

`

2149

2145

`let layout = Layout::for_value_raw(ptr);

`

2150

2146

``

2151

2147

`// Pointer to first element

`

2152

``

`-

let elems = ptr::addr_of_mut!((*ptr).value) as *mut T;

`

``

2148

`+

let elems = (&raw mut (*ptr).value) as *mut T;

`

2153

2149

``

2154

2150

`let mut guard = Guard { mem: NonNull::new_unchecked(mem), elems, layout, n_elems: 0 };

`

2155

2151

``

`@@ -2577,7 +2573,7 @@ impl<T: ?Sized + fmt::Debug, A: Allocator> fmt::Debug for Rc<T, A> {

`

2577

2573

`#[stable(feature = "rust1", since = "1.0.0")]

`

2578

2574

`impl<T: ?Sized, A: Allocator> fmt::Pointer for Rc<T, A> {

`

2579

2575

`fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

`

2580

``

`-

fmt::Pointer::fmt(&core::ptr::addr_of!(**self), f)

`

``

2576

`+

fmt::Pointer::fmt(&(&raw const **self), f)

`

2581

2577

`}

`

2582

2578

`}

`

2583

2579

``

`@@ -2718,7 +2714,7 @@ impl<T, A: Allocator> From<Vec<T, A>> for Rc<[T], A> {

`

2718

2714

`let (vec_ptr, len, cap, alloc) = v.into_raw_parts_with_alloc();

`

2719

2715

``

2720

2716

`let rc_ptr = Self::allocate_for_slice_in(len, &alloc);

`

2721

``

`-

ptr::copy_nonoverlapping(vec_ptr, ptr::addr_of_mut!((*rc_ptr).value) as *mut T, len);

`

``

2717

`+

ptr::copy_nonoverlapping(vec_ptr, (&raw mut (*rc_ptr).value) as *mut T, len);

`

2722

2718

``

2723

2719

`` // Create a Vec<T, &A> with length 0, to deallocate the buffer

``

2724

2720

`// without dropping its contents or the allocator

`

`@@ -3084,7 +3080,7 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {

`

3084

3080

`// SAFETY: if is_dangling returns false, then the pointer is dereferenceable.

`

3085

3081

`// The payload may be dropped at this point, and we have to maintain provenance,

`

3086

3082

`// so use raw pointer manipulation.

`

3087

``

`-

unsafe { ptr::addr_of_mut!((*ptr).value) }

`

``

3083

`+

unsafe { &raw mut (*ptr).value }

`

3088

3084

`}

`

3089

3085

`}

`

3090

3086

``