@@ -1672,7 +1672,7 @@ impl<T, U> Option<(T, U)> {
1672
1672
}
1673
1673
}
1674
1674
1675
- impl < T : Copy > Option < & T > {
1675
+ impl < T > Option < & T > {
1676
1676
/// Maps an `Option<&T>` to an `Option<T>` by copying the contents of the
1677
1677
/// option.
1678
1678
///
@@ -1688,41 +1688,18 @@ impl<T: Copy> Option<&T> {
1688
1688
#[ must_use = "`self` will be dropped if the result is not used" ]
1689
1689
#[ stable( feature = "copied" , since = "1.35.0" ) ]
1690
1690
#[ rustc_const_unstable( feature = "const_option" , issue = "67441" ) ]
1691
- pub const fn copied ( self ) -> Option < T > {
1691
+ pub const fn copied ( self ) -> Option < T >
1692
+ where
1693
+ T : Copy ,
1694
+ {
1692
1695
// FIXME: this implementation, which sidesteps using `Option::map` since it's not const
1693
1696
// ready yet, should be reverted when possible to avoid code repetition
1694
1697
match self {
1695
1698
Some ( & v) => Some ( v) ,
1696
1699
None => None ,
1697
1700
}
1698
1701
}
1699
- }
1700
-
1701
- impl < T : Copy > Option < & mut T > {
1702
- /// Maps an `Option<&mut T>` to an `Option<T>` by copying the contents of the
1703
- /// option.
1704
- ///
1705
- /// # Examples
1706
- ///
1707
- /// ```
1708
- /// let mut x = 12;
1709
- /// let opt_x = Some(&mut x);
1710
- /// assert_eq!(opt_x, Some(&mut 12));
1711
- /// let copied = opt_x.copied();
1712
- /// assert_eq!(copied, Some(12));
1713
- /// ```
1714
- #[ must_use = "`self` will be dropped if the result is not used" ]
1715
- #[ stable( feature = "copied" , since = "1.35.0" ) ]
1716
- #[ rustc_const_unstable( feature = "const_option_ext" , issue = "91930" ) ]
1717
- pub const fn copied ( self ) -> Option < T > {
1718
- match self {
1719
- Some ( & mut t) => Some ( t) ,
1720
- None => None ,
1721
- }
1722
- }
1723
- }
1724
1702
1725
- impl < T : Clone > Option < & T > {
1726
1703
/// Maps an `Option<&T>` to an `Option<T>` by cloning the contents of the
1727
1704
/// option.
1728
1705
///
@@ -1749,6 +1726,30 @@ impl<T: Clone> Option<&T> {
1749
1726
}
1750
1727
}
1751
1728
1729
+ impl < T : Copy > Option < & mut T > {
1730
+ /// Maps an `Option<&mut T>` to an `Option<T>` by copying the contents of the
1731
+ /// option.
1732
+ ///
1733
+ /// # Examples
1734
+ ///
1735
+ /// ```
1736
+ /// let mut x = 12;
1737
+ /// let opt_x = Some(&mut x);
1738
+ /// assert_eq!(opt_x, Some(&mut 12));
1739
+ /// let copied = opt_x.copied();
1740
+ /// assert_eq!(copied, Some(12));
1741
+ /// ```
1742
+ #[ must_use = "`self` will be dropped if the result is not used" ]
1743
+ #[ stable( feature = "copied" , since = "1.35.0" ) ]
1744
+ #[ rustc_const_unstable( feature = "const_option_ext" , issue = "91930" ) ]
1745
+ pub const fn copied ( self ) -> Option < T > {
1746
+ match self {
1747
+ Some ( & mut t) => Some ( t) ,
1748
+ None => None ,
1749
+ }
1750
+ }
1751
+ }
1752
+
1752
1753
impl < T : Clone > Option < & mut T > {
1753
1754
/// Maps an `Option<&mut T>` to an `Option<T>` by cloning the contents of the
1754
1755
/// option.
0 commit comments