@@ -739,6 +739,7 @@ impl<T> Option<T> {
739739 #[ stable( feature = "pin" , since = "1.33.0" ) ]
740740 #[ rustc_const_unstable( feature = "const_option_ext" , issue = "91930" ) ]
741741 pub const fn as_pin_ref ( self : Pin < & Self > ) -> Option < Pin < & T > > {
742+ // FIXME(const-hack): use `map` once that is possible
742743 match Pin :: get_ref ( self ) . as_ref ( ) {
743744 // SAFETY: `x` is guaranteed to be pinned because it comes from `self`
744745 // which is pinned.
@@ -758,6 +759,7 @@ impl<T> Option<T> {
758759 // SAFETY: `get_unchecked_mut` is never used to move the `Option` inside `self`.
759760 // `x` is guaranteed to be pinned because it comes from `self` which is pinned.
760761 unsafe {
762+ // FIXME(const-hack): use `map` once that is possible
761763 match Pin :: get_unchecked_mut ( self ) . as_mut ( ) {
762764 Some ( x) => Some ( Pin :: new_unchecked ( x) ) ,
763765 None => None ,
@@ -1290,10 +1292,7 @@ impl<T> Option<T> {
12901292 where
12911293 T : Deref ,
12921294 {
1293- match self . as_ref ( ) {
1294- Some ( t) => Some ( t. deref ( ) ) ,
1295- None => None ,
1296- }
1295+ self . as_ref ( ) . map ( |t| t. deref ( ) )
12971296 }
12981297
12991298 /// Converts from `Option<T>` (or `&mut Option<T>`) to `Option<&mut T::Target>`.
@@ -1316,10 +1315,7 @@ impl<T> Option<T> {
13161315 where
13171316 T : DerefMut ,
13181317 {
1319- match self . as_mut ( ) {
1320- Some ( t) => Some ( t. deref_mut ( ) ) ,
1321- None => None ,
1322- }
1318+ self . as_mut ( ) . map ( |t| t. deref_mut ( ) )
13231319 }
13241320
13251321 /////////////////////////////////////////////////////////////////////////
@@ -1632,13 +1628,7 @@ impl<T> Option<T> {
16321628 #[ inline]
16331629 #[ stable( feature = "option_entry" , since = "1.20.0" ) ]
16341630 pub fn get_or_insert ( & mut self , value : T ) -> & mut T {
1635- if let None = * self {
1636- * self = Some ( value) ;
1637- }
1638-
1639- // SAFETY: a `None` variant for `self` would have been replaced by a `Some`
1640- // variant in the code above.
1641- unsafe { self . as_mut ( ) . unwrap_unchecked ( ) }
1631+ self . get_or_insert_with ( || value)
16421632 }
16431633
16441634 /// Inserts the default value into the option if it is [`None`], then
@@ -1724,7 +1714,7 @@ impl<T> Option<T> {
17241714 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
17251715 #[ rustc_const_unstable( feature = "const_option" , issue = "67441" ) ]
17261716 pub const fn take ( & mut self ) -> Option < T > {
1727- // FIXME replace `mem::replace` by `mem::take` when the latter is const ready
1717+ // FIXME(const-hack) replace `mem::replace` by `mem::take` when the latter is const ready
17281718 mem:: replace ( self , None )
17291719 }
17301720
0 commit comments