Make Option::cloned const fn.

This commit is contained in:
mbartlett21 2021-11-10 08:41:01 +10:00 committed by GitHub
parent d6082292a6
commit afdec886f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1497,8 +1497,12 @@ impl<T: Clone> Option<&T> {
/// ```
#[must_use = "`self` will be dropped if the result is not used"]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn cloned(self) -> Option<T> {
self.map(|t| t.clone())
#[rustc_const_unstable(feature = "option_const_cloned", issue = "none")]
pub const fn cloned(self) -> Option<T> where T: ~const Clone {
match self {
Some(t) => Some(t.clone()),
None => None,
}
}
}
@ -1515,9 +1519,14 @@ impl<T: Clone> Option<&mut T> {
/// let cloned = opt_x.cloned();
/// assert_eq!(cloned, Some(12));
/// ```
#[must_use = "`self` will be dropped if the result is not used"]
#[stable(since = "1.26.0", feature = "option_ref_mut_cloned")]
pub fn cloned(self) -> Option<T> {
self.map(|t| t.clone())
#[rustc_const_unstable(feature = "option_const_cloned", issue = "none")]
pub const fn cloned(self) -> Option<T> where T: ~const Clone {
match self {
Some(t) => Some(t.clone()),
None => None,
}
}
}