@@ -540,8 +540,8 @@ impl<T> Option<T> {
540540 /// ```
541541 #[ must_use = "if you intended to assert that this has a value, consider `.unwrap()` instead" ]
542542 #[ inline]
543- #[ rustc_const_stable( feature = "const_option" , since = "1.48.0" ) ]
544543 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
544+ #[ rustc_const_stable( feature = "const_option" , since = "1.48.0" ) ]
545545 pub const fn is_some ( & self ) -> bool {
546546 matches ! ( * self , Some ( _) )
547547 }
@@ -560,8 +560,8 @@ impl<T> Option<T> {
560560 #[ must_use = "if you intended to assert that this doesn't have a value, consider \
561561 `.and_then(|_| panic!(\" `Option` had a value when expected `None`\" ))` instead"]
562562 #[ inline]
563- #[ rustc_const_stable( feature = "const_option" , since = "1.48.0" ) ]
564563 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
564+ #[ rustc_const_stable( feature = "const_option" , since = "1.48.0" ) ]
565565 pub const fn is_none ( & self ) -> bool {
566566 !self . is_some ( )
567567 }
@@ -1312,8 +1312,10 @@ impl<T> Option<T> {
13121312 /// ```
13131313 #[ inline]
13141314 #[ 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 )
13171319 }
13181320
13191321 /// Replaces the actual value in the option by the value given in parameter,
@@ -1334,8 +1336,9 @@ impl<T> Option<T> {
13341336 /// assert_eq!(old, None);
13351337 /// ```
13361338 #[ inline]
1339+ #[ rustc_const_unstable( feature = "const_option" , issue = "67441" ) ]
13371340 #[ 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 > {
13391342 mem:: replace ( self , Some ( value) )
13401343 }
13411344
@@ -1440,8 +1443,14 @@ impl<T: Copy> Option<&T> {
14401443 /// assert_eq!(copied, Some(12));
14411444 /// ```
14421445 #[ 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+ }
14451454 }
14461455}
14471456
0 commit comments