@@ -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 /////////////////////////////////////////////////////////////////////////
@@ -1633,13 +1629,7 @@ impl<T> Option<T> {
16331629 #[ inline]
16341630 #[ stable( feature = "option_entry" , since = "1.20.0" ) ]
16351631 pub fn get_or_insert ( & mut self , value : T ) -> & mut T {
1636- if let None = * self {
1637- * self = Some ( value) ;
1638- }
1639-
1640- // SAFETY: a `None` variant for `self` would have been replaced by a `Some`
1641- // variant in the code above.
1642- unsafe { self . as_mut ( ) . unwrap_unchecked ( ) }
1632+ self . get_or_insert_with ( || value)
16431633 }
16441634
16451635 /// Inserts the default value into the option if it is [`None`], then
@@ -1725,7 +1715,7 @@ impl<T> Option<T> {
17251715 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
17261716 #[ rustc_const_unstable( feature = "const_option" , issue = "67441" ) ]
17271717 pub const fn take ( & mut self ) -> Option < T > {
1728- // FIXME replace `mem::replace` by `mem::take` when the latter is const ready
1718+ // FIXME(const-hack) replace `mem::replace` by `mem::take` when the latter is const ready
17291719 mem:: replace ( self , None )
17301720 }
17311721
@@ -1894,7 +1884,7 @@ impl<T> Option<&T> {
18941884 where
18951885 T : Copy ,
18961886 {
1897- // FIXME: this implementation, which sidesteps using `Option::map` since it's not const
1887+ // FIXME(const-hack) : this implementation, which sidesteps using `Option::map` since it's not const
18981888 // ready yet, should be reverted when possible to avoid code repetition
18991889 match self {
19001890 Some ( & v) => Some ( v) ,
0 commit comments