Skip to content

Commit 9bbfd68

Browse files
committed
Add assumptions that the pointer is non-null
1 parent a729a40 commit 9bbfd68

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/liballoc/rc.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -933,12 +933,26 @@ trait RcBoxPtr<T> {
933933

934934
impl<T> RcBoxPtr<T> for Rc<T> {
935935
#[inline(always)]
936-
fn inner(&self) -> &RcBox<T> { unsafe { &(**self._ptr) } }
936+
fn inner(&self) -> &RcBox<T> {
937+
unsafe {
938+
// Safe to assume this here, as if it weren't true, we'd be breaking
939+
// the contract anyway
940+
assume(!self._ptr.is_null());
941+
&(**self._ptr)
942+
}
943+
}
937944
}
938945

939946
impl<T> RcBoxPtr<T> for Weak<T> {
940947
#[inline(always)]
941-
fn inner(&self) -> &RcBox<T> { unsafe { &(**self._ptr) } }
948+
fn inner(&self) -> &RcBox<T> {
949+
unsafe {
950+
// Safe to assume this here, as if it weren't true, we'd be breaking
951+
// the contract anyway
952+
assume(!self._ptr.is_null());
953+
&(**self._ptr)
954+
}
955+
}
942956
}
943957

944958
#[cfg(test)]

0 commit comments

Comments
 (0)