@@ -540,8 +540,8 @@ impl<T> Option<T> {
540
540
/// ```
541
541
#[ must_use = "if you intended to assert that this has a value, consider `.unwrap()` instead" ]
542
542
#[ inline]
543
- #[ rustc_const_stable( feature = "const_option" , since = "1.48.0" ) ]
544
543
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
544
+ #[ rustc_const_stable( feature = "const_option" , since = "1.48.0" ) ]
545
545
pub const fn is_some ( & self ) -> bool {
546
546
matches ! ( * self , Some ( _) )
547
547
}
@@ -560,8 +560,8 @@ impl<T> Option<T> {
560
560
#[ must_use = "if you intended to assert that this doesn't have a value, consider \
561
561
`.and_then(|_| panic!(\" `Option` had a value when expected `None`\" ))` instead"]
562
562
#[ inline]
563
- #[ rustc_const_stable( feature = "const_option" , since = "1.48.0" ) ]
564
563
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
564
+ #[ rustc_const_stable( feature = "const_option" , since = "1.48.0" ) ]
565
565
pub const fn is_none ( & self ) -> bool {
566
566
!self . is_some ( )
567
567
}
@@ -1312,8 +1312,10 @@ impl<T> Option<T> {
1312
1312
/// ```
1313
1313
#[ inline]
1314
1314
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1315
- pub fn take ( & mut self ) -> Option < T > {
1316
- mem:: take ( self )
1315
+ #[ rustc_const_unstable( feature = "const_option" , issue = "67441" ) ]
1316
+ pub const fn take ( & mut self ) -> Option < T > {
1317
+ // FIXME replace `mem::replace` by `mem::take` when the latter is const ready
1318
+ mem:: replace ( self , None )
1317
1319
}
1318
1320
1319
1321
/// Replaces the actual value in the option by the value given in parameter,
@@ -1334,8 +1336,9 @@ impl<T> Option<T> {
1334
1336
/// assert_eq!(old, None);
1335
1337
/// ```
1336
1338
#[ inline]
1339
+ #[ rustc_const_unstable( feature = "const_option" , issue = "67441" ) ]
1337
1340
#[ stable( feature = "option_replace" , since = "1.31.0" ) ]
1338
- pub fn replace ( & mut self , value : T ) -> Option < T > {
1341
+ pub const fn replace ( & mut self , value : T ) -> Option < T > {
1339
1342
mem:: replace ( self , Some ( value) )
1340
1343
}
1341
1344
@@ -1440,8 +1443,14 @@ impl<T: Copy> Option<&T> {
1440
1443
/// assert_eq!(copied, Some(12));
1441
1444
/// ```
1442
1445
#[ stable( feature = "copied" , since = "1.35.0" ) ]
1443
- pub fn copied ( self ) -> Option < T > {
1444
- self . map ( |& t| t)
1446
+ #[ rustc_const_unstable( feature = "const_option" , issue = "67441" ) ]
1447
+ pub const fn copied ( self ) -> Option < T > {
1448
+ // FIXME: this implementation, which sidesteps using `Option::map` since it's not const
1449
+ // ready yet, should be reverted when possible to avoid code repetition
1450
+ match self {
1451
+ Some ( & v) => Some ( v) ,
1452
+ None => None ,
1453
+ }
1445
1454
}
1446
1455
}
1447
1456
0 commit comments