Add assumptions that the pointer is non-null

This commit is contained in:
James Miller 2015-01-21 09:35:24 +13:00
parent a729a40494
commit 9bbfd681c9

View file

@ -933,12 +933,26 @@ trait RcBoxPtr<T> {
impl<T> RcBoxPtr<T> for Rc<T> {
#[inline(always)]
fn inner(&self) -> &RcBox<T> { unsafe { &(**self._ptr) } }
fn inner(&self) -> &RcBox<T> {
unsafe {
// Safe to assume this here, as if it weren't true, we'd be breaking
// the contract anyway
assume(!self._ptr.is_null());
&(**self._ptr)
}
}
}
impl<T> RcBoxPtr<T> for Weak<T> {
#[inline(always)]
fn inner(&self) -> &RcBox<T> { unsafe { &(**self._ptr) } }
fn inner(&self) -> &RcBox<T> {
unsafe {
// Safe to assume this here, as if it weren't true, we'd be breaking
// the contract anyway
assume(!self._ptr.is_null());
&(**self._ptr)
}
}
}
#[cfg(test)]