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> {
1497
1497
/// ```
1498
1498
#[ must_use = "`self` will be dropped if the result is not used" ]
1499
1499
#[ 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
+ }
1502
1506
}
1503
1507
}
1504
1508
@@ -1515,9 +1519,14 @@ impl<T: Clone> Option<&mut T> {
1515
1519
/// let cloned = opt_x.cloned();
1516
1520
/// assert_eq!(cloned, Some(12));
1517
1521
/// ```
1522
+ #[ must_use = "`self` will be dropped if the result is not used" ]
1518
1523
#[ 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
+ }
1521
1530
}
1522
1531
}
1523
1532
You can’t perform that action at this time.
0 commit comments