@@ -739,6 +739,7 @@ impl<T> Option<T> {
739
739
#[ stable( feature = "pin" , since = "1.33.0" ) ]
740
740
#[ rustc_const_unstable( feature = "const_option_ext" , issue = "91930" ) ]
741
741
pub const fn as_pin_ref ( self : Pin < & Self > ) -> Option < Pin < & T > > {
742
+ // FIXME(const-hack): use `map` once that is possible
742
743
match Pin :: get_ref ( self ) . as_ref ( ) {
743
744
// SAFETY: `x` is guaranteed to be pinned because it comes from `self`
744
745
// which is pinned.
@@ -758,6 +759,7 @@ impl<T> Option<T> {
758
759
// SAFETY: `get_unchecked_mut` is never used to move the `Option` inside `self`.
759
760
// `x` is guaranteed to be pinned because it comes from `self` which is pinned.
760
761
unsafe {
762
+ // FIXME(const-hack): use `map` once that is possible
761
763
match Pin :: get_unchecked_mut ( self ) . as_mut ( ) {
762
764
Some ( x) => Some ( Pin :: new_unchecked ( x) ) ,
763
765
None => None ,
@@ -1290,10 +1292,7 @@ impl<T> Option<T> {
1290
1292
where
1291
1293
T : Deref ,
1292
1294
{
1293
- match self . as_ref ( ) {
1294
- Some ( t) => Some ( t. deref ( ) ) ,
1295
- None => None ,
1296
- }
1295
+ self . as_ref ( ) . map ( |t| t. deref ( ) )
1297
1296
}
1298
1297
1299
1298
/// Converts from `Option<T>` (or `&mut Option<T>`) to `Option<&mut T::Target>`.
@@ -1316,10 +1315,7 @@ impl<T> Option<T> {
1316
1315
where
1317
1316
T : DerefMut ,
1318
1317
{
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 ( ) )
1323
1319
}
1324
1320
1325
1321
/////////////////////////////////////////////////////////////////////////
@@ -1633,13 +1629,7 @@ impl<T> Option<T> {
1633
1629
#[ inline]
1634
1630
#[ stable( feature = "option_entry" , since = "1.20.0" ) ]
1635
1631
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)
1643
1633
}
1644
1634
1645
1635
/// Inserts the default value into the option if it is [`None`], then
@@ -1725,7 +1715,7 @@ impl<T> Option<T> {
1725
1715
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1726
1716
#[ rustc_const_unstable( feature = "const_option" , issue = "67441" ) ]
1727
1717
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
1729
1719
mem:: replace ( self , None )
1730
1720
}
1731
1721
@@ -1894,7 +1884,7 @@ impl<T> Option<&T> {
1894
1884
where
1895
1885
T : Copy ,
1896
1886
{
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
1898
1888
// ready yet, should be reverted when possible to avoid code repetition
1899
1889
match self {
1900
1890
Some ( & v) => Some ( v) ,
0 commit comments