Skip to content

Commit

Permalink
Access alloc field directly in Arc/Rc::into_raw_with_allocator.
Browse files Browse the repository at this point in the history
... since fn allocator doesn't exist yet.
  • Loading branch information
zachs18 committed May 17, 2024
1 parent 28cb2d7 commit c895f6e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions library/alloc/src/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1379,7 +1379,7 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
let this = mem::ManuallyDrop::new(this);
let ptr = Self::as_ptr(&this);
// Safety: `this` is ManuallyDrop so the allocator will not be double-dropped
let alloc = unsafe { ptr::read(Self::allocator(&this)) };
let alloc = unsafe { ptr::read(&this.alloc) };
(ptr, alloc)
}

Expand Down Expand Up @@ -3061,7 +3061,7 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
let this = mem::ManuallyDrop::new(self);
let result = this.as_ptr();
// Safety: `this` is ManuallyDrop so the allocator will not be double-dropped
let alloc = unsafe { ptr::read(this.allocator()) };
let alloc = unsafe { ptr::read(&this.alloc) };
(result, alloc)
}

Expand Down
4 changes: 2 additions & 2 deletions library/alloc/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1520,7 +1520,7 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
let this = mem::ManuallyDrop::new(this);
let ptr = Self::as_ptr(&this);
// Safety: `this` is ManuallyDrop so the allocator will not be double-dropped
let alloc = unsafe { ptr::read(Self::allocator(&this)) };
let alloc = unsafe { ptr::read(&this.alloc) };
(ptr, alloc)
}

Expand Down Expand Up @@ -2803,7 +2803,7 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
let this = mem::ManuallyDrop::new(self);
let result = this.as_ptr();
// Safety: `this` is ManuallyDrop so the allocator will not be double-dropped
let alloc = unsafe { ptr::read(Self::allocator(&this)) };
let alloc = unsafe { ptr::read(&this.alloc) };
(result, alloc)
}

Expand Down

0 comments on commit c895f6e

Please sign in to comment.