Add SAFETY annotations

Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
This commit is contained in:
Miguel Ojeda 2021-01-10 15:59:17 +01:00
parent 679f6f3473
commit 76299b3f42
2 changed files with 3 additions and 0 deletions

View File

@ -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() },
}
}

View File

@ -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,
}