133133//! [`Box<T>`]: ../../std/boxed/struct.Box.html
134134//! [`i32`]: ../../std/primitive.i32.html
135135
136- // ignore-tidy-undocumented-unsafe
137-
138136#![ stable( feature = "rust1" , since = "1.0.0" ) ]
139137
140138use crate :: iter:: { FromIterator , FusedIterator , TrustedLen } ;
@@ -301,6 +299,8 @@ impl<T> Option<T> {
301299 #[ inline]
302300 #[ stable( feature = "pin" , since = "1.33.0" ) ]
303301 pub fn as_pin_ref ( self : Pin < & Self > ) -> Option < Pin < & T > > {
302+ // SAFETY: `x` is guaranteed to be pinned because it comes from `self`
303+ // which is pinned.
304304 unsafe { Pin :: get_ref ( self ) . as_ref ( ) . map ( |x| Pin :: new_unchecked ( x) ) }
305305 }
306306
@@ -310,6 +310,8 @@ impl<T> Option<T> {
310310 #[ inline]
311311 #[ stable( feature = "pin" , since = "1.33.0" ) ]
312312 pub fn as_pin_mut ( self : Pin < & mut Self > ) -> Option < Pin < & mut T > > {
313+ // SAFETY: `get_unchecked_mut` is never used to move the `Option` inside `self`.
314+ // `x` is guaranteed to be pinned because it comes from `self` which is pinned.
313315 unsafe { Pin :: get_unchecked_mut ( self ) . as_mut ( ) . map ( |x| Pin :: new_unchecked ( x) ) }
314316 }
315317
@@ -858,6 +860,8 @@ impl<T> Option<T> {
858860
859861 match * self {
860862 Some ( ref mut v) => v,
863+ // SAFETY: a `None` variant for `self` would have been replaced by a `Some`
864+ // variant in the code above.
861865 None => unsafe { hint:: unreachable_unchecked ( ) } ,
862866 }
863867 }
0 commit comments