@@ -544,8 +544,8 @@ impl<T> Option<T> {
544
544
/// ```
545
545
#[ must_use = "if you intended to assert that this has a value, consider `.unwrap()` instead" ]
546
546
#[ inline]
547
- #[ rustc_const_stable( feature = "const_option" , since = "1.48.0" ) ]
548
547
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
548
+ #[ rustc_const_stable( feature = "const_option" , since = "1.48.0" ) ]
549
549
pub const fn is_some ( & self ) -> bool {
550
550
matches ! ( * self , Some ( _) )
551
551
}
@@ -564,8 +564,8 @@ impl<T> Option<T> {
564
564
#[ must_use = "if you intended to assert that this doesn't have a value, consider \
565
565
`.and_then(|_| panic!(\" `Option` had a value when expected `None`\" ))` instead"]
566
566
#[ inline]
567
- #[ rustc_const_stable( feature = "const_option" , since = "1.48.0" ) ]
568
567
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
568
+ #[ rustc_const_stable( feature = "const_option" , since = "1.48.0" ) ]
569
569
pub const fn is_none ( & self ) -> bool {
570
570
!self . is_some ( )
571
571
}
@@ -1318,8 +1318,10 @@ impl<T> Option<T> {
1318
1318
/// ```
1319
1319
#[ inline]
1320
1320
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1321
- pub fn take ( & mut self ) -> Option < T > {
1322
- mem:: take ( self )
1321
+ #[ rustc_const_unstable( feature = "const_option" , issue = "67441" ) ]
1322
+ pub const fn take ( & mut self ) -> Option < T > {
1323
+ // FIXME replace `mem::replace` by `mem::take` when the latter is const ready
1324
+ mem:: replace ( self , None )
1323
1325
}
1324
1326
1325
1327
/// Replaces the actual value in the option by the value given in parameter,
@@ -1340,8 +1342,9 @@ impl<T> Option<T> {
1340
1342
/// assert_eq!(old, None);
1341
1343
/// ```
1342
1344
#[ inline]
1345
+ #[ rustc_const_unstable( feature = "const_option" , issue = "67441" ) ]
1343
1346
#[ stable( feature = "option_replace" , since = "1.31.0" ) ]
1344
- pub fn replace ( & mut self , value : T ) -> Option < T > {
1347
+ pub const fn replace ( & mut self , value : T ) -> Option < T > {
1345
1348
mem:: replace ( self , Some ( value) )
1346
1349
}
1347
1350
@@ -1446,8 +1449,14 @@ impl<T: Copy> Option<&T> {
1446
1449
/// assert_eq!(copied, Some(12));
1447
1450
/// ```
1448
1451
#[ stable( feature = "copied" , since = "1.35.0" ) ]
1449
- pub fn copied ( self ) -> Option < T > {
1450
- self . map ( |& t| t)
1452
+ #[ rustc_const_unstable( feature = "const_option" , issue = "67441" ) ]
1453
+ pub const fn copied ( self ) -> Option < T > {
1454
+ // FIXME: this implementation, which sidesteps using `Option::map` since it's not const
1455
+ // ready yet, should be reverted when possible to avoid code repetition
1456
+ match self {
1457
+ Some ( & v) => Some ( v) ,
1458
+ None => None ,
1459
+ }
1451
1460
}
1452
1461
}
1453
1462
0 commit comments