mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
Document unsafety in core::option
This commit is contained in:
parent
76882666eb
commit
37514dedab
@ -133,8 +133,6 @@
|
|||||||
//! [`Box<T>`]: ../../std/boxed/struct.Box.html
|
//! [`Box<T>`]: ../../std/boxed/struct.Box.html
|
||||||
//! [`i32`]: ../../std/primitive.i32.html
|
//! [`i32`]: ../../std/primitive.i32.html
|
||||||
|
|
||||||
// ignore-tidy-undocumented-unsafe
|
|
||||||
|
|
||||||
#![stable(feature = "rust1", since = "1.0.0")]
|
#![stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
|
||||||
use crate::iter::{FromIterator, FusedIterator, TrustedLen};
|
use crate::iter::{FromIterator, FusedIterator, TrustedLen};
|
||||||
@ -301,6 +299,8 @@ impl<T> Option<T> {
|
|||||||
#[inline]
|
#[inline]
|
||||||
#[stable(feature = "pin", since = "1.33.0")]
|
#[stable(feature = "pin", since = "1.33.0")]
|
||||||
pub fn as_pin_ref(self: Pin<&Self>) -> Option<Pin<&T>> {
|
pub fn as_pin_ref(self: Pin<&Self>) -> Option<Pin<&T>> {
|
||||||
|
// SAFETY: `x` is guaranteed to be pinned because it comes from `self`
|
||||||
|
// which is pinned.
|
||||||
unsafe { Pin::get_ref(self).as_ref().map(|x| Pin::new_unchecked(x)) }
|
unsafe { Pin::get_ref(self).as_ref().map(|x| Pin::new_unchecked(x)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -310,6 +310,8 @@ impl<T> Option<T> {
|
|||||||
#[inline]
|
#[inline]
|
||||||
#[stable(feature = "pin", since = "1.33.0")]
|
#[stable(feature = "pin", since = "1.33.0")]
|
||||||
pub fn as_pin_mut(self: Pin<&mut Self>) -> Option<Pin<&mut T>> {
|
pub fn as_pin_mut(self: Pin<&mut Self>) -> Option<Pin<&mut T>> {
|
||||||
|
// SAFETY: `get_unchecked_mut` is never used to move the `Option` inside `self`.
|
||||||
|
// `x` is guaranteed to be pinned because it comes from `self` which is pinned.
|
||||||
unsafe { Pin::get_unchecked_mut(self).as_mut().map(|x| Pin::new_unchecked(x)) }
|
unsafe { Pin::get_unchecked_mut(self).as_mut().map(|x| Pin::new_unchecked(x)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -858,6 +860,8 @@ impl<T> Option<T> {
|
|||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
Some(ref mut v) => v,
|
Some(ref mut v) => v,
|
||||||
|
// SAFETY: a `None` variant for `self` would have been replaced by a `Some`
|
||||||
|
// variant in the code above.
|
||||||
None => unsafe { hint::unreachable_unchecked() },
|
None => unsafe { hint::unreachable_unchecked() },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user