@@ -544,8 +544,8 @@ impl<T> Option<T> {
544544 /// ```
545545 #[ must_use = "if you intended to assert that this has a value, consider `.unwrap()` instead" ]
546546 #[ inline]
547- #[ rustc_const_stable( feature = "const_option" , since = "1.48.0" ) ]
548547 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
548+ #[ rustc_const_stable( feature = "const_option" , since = "1.48.0" ) ]
549549 pub const fn is_some ( & self ) -> bool {
550550 matches ! ( * self , Some ( _) )
551551 }
@@ -564,8 +564,8 @@ impl<T> Option<T> {
564564 #[ must_use = "if you intended to assert that this doesn't have a value, consider \
565565 `.and_then(|_| panic!(\" `Option` had a value when expected `None`\" ))` instead"]
566566 #[ inline]
567- #[ rustc_const_stable( feature = "const_option" , since = "1.48.0" ) ]
568567 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
568+ #[ rustc_const_stable( feature = "const_option" , since = "1.48.0" ) ]
569569 pub const fn is_none ( & self ) -> bool {
570570 !self . is_some ( )
571571 }
@@ -1318,8 +1318,10 @@ impl<T> Option<T> {
13181318 /// ```
13191319 #[ inline]
13201320 #[ 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 )
13231325 }
13241326
13251327 /// Replaces the actual value in the option by the value given in parameter,
@@ -1340,8 +1342,9 @@ impl<T> Option<T> {
13401342 /// assert_eq!(old, None);
13411343 /// ```
13421344 #[ inline]
1345+ #[ rustc_const_unstable( feature = "const_option" , issue = "67441" ) ]
13431346 #[ 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 > {
13451348 mem:: replace ( self , Some ( value) )
13461349 }
13471350
@@ -1446,8 +1449,14 @@ impl<T: Copy> Option<&T> {
14461449 /// assert_eq!(copied, Some(12));
14471450 /// ```
14481451 #[ 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+ }
14511460 }
14521461}
14531462
0 commit comments