Skip to content

Commit 108162c

Browse files
committed
---
yaml --- r: 178954 b: refs/heads/master c: 706be5b h: refs/heads/master v: v3
1 parent 7c9ee1a commit 108162c

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: d0e82a68a9bf32eff2509e9f2579c5aa0fc61e92
2+
refs/heads/master: 706be5ba1f65ede0ffe095df8fa79706cbb562c8
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: ac134f7ca435551964996ee88319241cd3c7c110
55
refs/heads/try: ccf8fedf1cffcb8f6f3581d53d220039e192fe77

trunk/src/liballoc/rc.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ use core::option::Option::{Some, None};
160160
use core::ptr::{self, PtrExt};
161161
use core::result::Result;
162162
use core::result::Result::{Ok, Err};
163+
use core::intrinsics::assume;
163164

164165
use heap::deallocate;
165166

@@ -769,12 +770,34 @@ trait RcBoxPtr<T> {
769770

770771
impl<T> RcBoxPtr<T> for Rc<T> {
771772
#[inline(always)]
772-
fn inner(&self) -> &RcBox<T> { unsafe { &(**self._ptr) } }
773+
fn inner(&self) -> &RcBox<T> {
774+
unsafe {
775+
// Safe to assume this here, as if it weren't true, we'd be breaking
776+
// the contract anyway.
777+
// This allows the null check to be elided in the destructor if we
778+
// manipulated the reference count in the same function.
779+
if cfg!(not(stage0)) { // NOTE remove cfg after next snapshot
780+
assume(!self._ptr.is_null());
781+
}
782+
&(**self._ptr)
783+
}
784+
}
773785
}
774786

775787
impl<T> RcBoxPtr<T> for Weak<T> {
776788
#[inline(always)]
777-
fn inner(&self) -> &RcBox<T> { unsafe { &(**self._ptr) } }
789+
fn inner(&self) -> &RcBox<T> {
790+
unsafe {
791+
// Safe to assume this here, as if it weren't true, we'd be breaking
792+
// the contract anyway.
793+
// This allows the null check to be elided in the destructor if we
794+
// manipulated the reference count in the same function.
795+
if cfg!(not(stage0)) { // NOTE remove cfg after next snapshot
796+
assume(!self._ptr.is_null());
797+
}
798+
&(**self._ptr)
799+
}
800+
}
778801
}
779802

780803
#[cfg(test)]

0 commit comments

Comments
 (0)