diff options
| author | Miguel Ojeda <ojeda@kernel.org> | 2021-01-10 15:59:17 +0100 |
|---|---|---|
| committer | Miguel Ojeda <ojeda@kernel.org> | 2021-01-10 15:59:58 +0100 |
| commit | 76299b3f42a402aa896b76fccd725f52080f374d (patch) | |
| tree | ab8d2ceda96b53f60e53e24a85d44c05c25d9226 | |
| parent | 679f6f347355726f9335fdcbf0d3b81b2e490c38 (diff) | |
Add `SAFETY` annotations
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
| -rw-r--r-- | library/core/src/option.rs | 1 | ||||
| -rw-r--r-- | library/core/src/result.rs | 2 |
2 files changed, 3 insertions, 0 deletions
diff --git a/library/core/src/option.rs b/library/core/src/option.rs index 18b494b3175..5d34f5ca155 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -455,6 +455,7 @@ impl<T> Option<T> { debug_assert!(self.is_some()); match self { Some(val) => val, + // SAFETY: the safety contract must be upheld by the caller. None => unsafe { hint::unreachable_unchecked() }, } } diff --git a/library/core/src/result.rs b/library/core/src/result.rs index a0f5c7746cc..a357750b92f 100644 --- a/library/core/src/result.rs +++ b/library/core/src/result.rs @@ -849,6 +849,7 @@ impl<T, E> Result<T, E> { debug_assert!(self.is_ok()); match self { Ok(t) => t, + // SAFETY: the safety contract must be upheld by the caller. Err(_) => unsafe { hint::unreachable_unchecked() }, } } @@ -879,6 +880,7 @@ impl<T, E> Result<T, E> { pub unsafe fn unwrap_err_unchecked(self) -> E { debug_assert!(self.is_err()); match self { + // SAFETY: the safety contract must be upheld by the caller. Ok(_) => unsafe { hint::unreachable_unchecked() }, Err(e) => e, } |
