Skip to content

Commit 8aee582

Browse files
committed
Auto merge of #30593 - steveklabnik:small_rc_refactoring, r=Gankro
This hairy conditional doesn't need to be so. It _does_ need to be a thin pointer, otherwise, it will fail to compile, so let's pull that out into a temporary for future readers of the source. /cc @nrc @SimonSapin @gankro @durka , who brought this up on IRC
2 parents 7f3201d + 2cff12e commit 8aee582

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/liballoc/arc.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -555,9 +555,9 @@ impl<T: ?Sized> Drop for Arc<T> {
555555
// This structure has #[unsafe_no_drop_flag], so this drop glue may run
556556
// more than once (but it is guaranteed to be zeroed after the first if
557557
// it's run more than once)
558-
let ptr = *self._ptr;
559-
// if ptr.is_null() { return }
560-
if ptr as *mut u8 as usize == 0 || ptr as *mut u8 as usize == mem::POST_DROP_USIZE {
558+
let thin = *self._ptr as *const ();
559+
560+
if thin as usize == mem::POST_DROP_USIZE {
561561
return;
562562
}
563563

@@ -710,9 +710,10 @@ impl<T: ?Sized> Drop for Weak<T> {
710710
/// ```
711711
fn drop(&mut self) {
712712
let ptr = *self._ptr;
713+
let thin = ptr as *const ();
713714

714715
// see comments above for why this check is here
715-
if ptr as *mut u8 as usize == 0 || ptr as *mut u8 as usize == mem::POST_DROP_USIZE {
716+
if thin as usize == mem::POST_DROP_USIZE {
716717
return;
717718
}
718719

src/liballoc/rc.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,9 @@ impl<T: ?Sized> Drop for Rc<T> {
449449
fn drop(&mut self) {
450450
unsafe {
451451
let ptr = *self._ptr;
452-
if !(*(&ptr as *const _ as *const *const ())).is_null() &&
453-
ptr as *const () as usize != mem::POST_DROP_USIZE {
452+
let thin = ptr as *const ();
453+
454+
if thin as usize != mem::POST_DROP_USIZE {
454455
self.dec_strong();
455456
if self.strong() == 0 {
456457
// destroy the contained object
@@ -782,8 +783,9 @@ impl<T: ?Sized> Drop for Weak<T> {
782783
fn drop(&mut self) {
783784
unsafe {
784785
let ptr = *self._ptr;
785-
if !(*(&ptr as *const _ as *const *const ())).is_null() &&
786-
ptr as *const () as usize != mem::POST_DROP_USIZE {
786+
let thin = ptr as *const ();
787+
788+
if thin as usize != mem::POST_DROP_USIZE {
787789
self.dec_weak();
788790
// the weak count starts at 1, and will only go to zero if all
789791
// the strong pointers have disappeared.

0 commit comments

Comments
 (0)