Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 493c037

Browse files
committed
Eliminate mut reference UB in Drop impl for Rc<T>
This changes `self.ptr.as_mut()` with `get_mut_unchecked` which does not use an intermediate reference. Arc<T> already handled this case properly.
1 parent b4bdc07 commit 493c037

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

library/alloc/src/rc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ unsafe impl<#[may_dangle] T: ?Sized> Drop for Rc<T> {
11951195
self.dec_strong();
11961196
if self.strong() == 0 {
11971197
// destroy the contained object
1198-
ptr::drop_in_place(self.ptr.as_mut());
1198+
ptr::drop_in_place(Self::get_mut_unchecked(self));
11991199

12001200
// remove the implicit "strong weak" pointer now that we've
12011201
// destroyed the contents.

0 commit comments

Comments
 (0)