This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -1497,8 +1497,12 @@ impl<T: Clone> Option<&T> {
14971497 /// ```
14981498 #[ must_use = "`self` will be dropped if the result is not used" ]
14991499 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1500- pub fn cloned ( self ) -> Option < T > {
1501- self . map ( |t| t. clone ( ) )
1500+ #[ rustc_const_unstable( feature = "option_const_cloned" , issue = "none" ) ]
1501+ pub const fn cloned ( self ) -> Option < T > where T : ~const Clone {
1502+ match self {
1503+ Some ( t) => Some ( t. clone ( ) ) ,
1504+ None => None ,
1505+ }
15021506 }
15031507}
15041508
@@ -1515,9 +1519,14 @@ impl<T: Clone> Option<&mut T> {
15151519 /// let cloned = opt_x.cloned();
15161520 /// assert_eq!(cloned, Some(12));
15171521 /// ```
1522+ #[ must_use = "`self` will be dropped if the result is not used" ]
15181523 #[ stable( since = "1.26.0" , feature = "option_ref_mut_cloned" ) ]
1519- pub fn cloned ( self ) -> Option < T > {
1520- self . map ( |t| t. clone ( ) )
1524+ #[ rustc_const_unstable( feature = "option_const_cloned" , issue = "none" ) ]
1525+ pub const fn cloned ( self ) -> Option < T > where T : ~const Clone {
1526+ match self {
1527+ Some ( t) => Some ( t. clone ( ) ) ,
1528+ None => None ,
1529+ }
15211530 }
15221531}
15231532
You can’t perform that action at this time.
0 commit comments