File tree 1 file changed +19
-4
lines changed
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> {
1523
1523
/// ```
1524
1524
#[ must_use = "`self` will be dropped if the result is not used" ]
1525
1525
#[ 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
+ }
1528
1535
}
1529
1536
}
1530
1537
@@ -1541,9 +1548,17 @@ impl<T: Clone> Option<&mut T> {
1541
1548
/// let cloned = opt_x.cloned();
1542
1549
/// assert_eq!(cloned, Some(12));
1543
1550
/// ```
1551
+ #[ must_use = "`self` will be dropped if the result is not used" ]
1544
1552
#[ 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
+ }
1547
1562
}
1548
1563
}
1549
1564
You can’t perform that action at this time.
0 commit comments