From 9bbfd681c9fa47f462a89e8f5eedd3fa2a5de2e7 Mon Sep 17 00:00:00 2001 From: James Miller Date: Wed, 21 Jan 2015 09:35:24 +1300 Subject: Add assumptions that the pointer is non-null --- src/liballoc/rc.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/liballoc') diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 0f2a11cc1db..837d709e882 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -933,12 +933,26 @@ trait RcBoxPtr { impl RcBoxPtr for Rc { #[inline(always)] - fn inner(&self) -> &RcBox { unsafe { &(**self._ptr) } } + fn inner(&self) -> &RcBox { + 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 RcBoxPtr for Weak { #[inline(always)] - fn inner(&self) -> &RcBox { unsafe { &(**self._ptr) } } + fn inner(&self) -> &RcBox { + 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)] -- cgit 1.4.1-3-g733a5