diff options
| author | James Miller <james@aatch.net> | 2015-01-21 09:35:24 +1300 |
|---|---|---|
| committer | James Miller <james@aatch.net> | 2015-01-21 09:35:24 +1300 |
| commit | 9bbfd681c9fa47f462a89e8f5eedd3fa2a5de2e7 (patch) | |
| tree | b51262f21894bebd7d976bb54f3e6ea33010f5be /src/liballoc | |
| parent | a729a404945de10f99e2530a5c28952996532b29 (diff) | |
| download | rust-9bbfd681c9fa47f462a89e8f5eedd3fa2a5de2e7.tar.gz rust-9bbfd681c9fa47f462a89e8f5eedd3fa2a5de2e7.zip | |
Add assumptions that the pointer is non-null
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/rc.rs | 18 |
1 files changed, 16 insertions, 2 deletions
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<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)] |
