File tree Expand file tree Collapse file tree 1 file changed +19
-4
lines changed Expand file tree Collapse file tree 1 file changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -1523,8 +1523,15 @@ impl<T: Clone> Option<&T> {
15231523 /// ```
15241524 #[ must_use = "`self` will be dropped if the result is not used" ]
15251525 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1526- pub fn cloned ( self ) -> Option < T > {
1527- self . map ( |t| t. clone ( ) )
1526+ #[ rustc_const_unstable( feature = "const_option_cloned" , issue = "91582" ) ]
1527+ pub const fn cloned ( self ) -> Option < T >
1528+ where
1529+ T : ~const Clone ,
1530+ {
1531+ match self {
1532+ Some ( t) => Some ( t. clone ( ) ) ,
1533+ None => None ,
1534+ }
15281535 }
15291536}
15301537
@@ -1541,9 +1548,17 @@ impl<T: Clone> Option<&mut T> {
15411548 /// let cloned = opt_x.cloned();
15421549 /// assert_eq!(cloned, Some(12));
15431550 /// ```
1551+ #[ must_use = "`self` will be dropped if the result is not used" ]
15441552 #[ stable( since = "1.26.0" , feature = "option_ref_mut_cloned" ) ]
1545- pub fn cloned ( self ) -> Option < T > {
1546- self . map ( |t| t. clone ( ) )
1553+ #[ rustc_const_unstable( feature = "const_option_cloned" , issue = "91582" ) ]
1554+ pub const fn cloned ( self ) -> Option < T >
1555+ where
1556+ T : ~const Clone ,
1557+ {
1558+ match self {
1559+ Some ( t) => Some ( t. clone ( ) ) ,
1560+ None => None ,
1561+ }
15471562 }
15481563}
15491564
You can’t perform that action at this time.
0 commit comments