From afdec886f38dfbfaa9084580e109c4b5188fd0fe Mon Sep 17 00:00:00 2001 From: mbartlett21 <29034492+mbartlett21@users.noreply.github.com> Date: Wed, 10 Nov 2021 08:41:01 +1000 Subject: [PATCH 1/4] Make `Option::cloned` const fn. --- library/core/src/option.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/library/core/src/option.rs b/library/core/src/option.rs index baf9948857bbe..da3c5f9f5aa0a 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -1497,8 +1497,12 @@ impl 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 { - self.map(|t| t.clone()) + #[rustc_const_unstable(feature = "option_const_cloned", issue = "none")] + pub const fn cloned(self) -> Option where T: ~const Clone { + match self { + Some(t) => Some(t.clone()), + None => None, + } } } @@ -1515,9 +1519,14 @@ impl 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 { - self.map(|t| t.clone()) + #[rustc_const_unstable(feature = "option_const_cloned", issue = "none")] + pub const fn cloned(self) -> Option where T: ~const Clone { + match self { + Some(t) => Some(t.clone()), + None => None, + } } } From 9de2745c95e4855e1f696b5aa40869b93bd35ad9 Mon Sep 17 00:00:00 2001 From: mbartlett21 <29034492+mbartlett21@users.noreply.github.com> Date: Wed, 10 Nov 2021 08:46:35 +1000 Subject: [PATCH 2/4] Rename `Option::cloned` gate --- library/core/src/option.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/core/src/option.rs b/library/core/src/option.rs index da3c5f9f5aa0a..261ff4403c94b 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -1497,7 +1497,7 @@ impl Option<&T> { /// ``` #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "option_const_cloned", issue = "none")] + #[rustc_const_unstable(feature = "const_option_cloned", issue = "none")] pub const fn cloned(self) -> Option where T: ~const Clone { match self { Some(t) => Some(t.clone()), @@ -1521,7 +1521,7 @@ impl Option<&mut T> { /// ``` #[must_use = "`self` will be dropped if the result is not used"] #[stable(since = "1.26.0", feature = "option_ref_mut_cloned")] - #[rustc_const_unstable(feature = "option_const_cloned", issue = "none")] + #[rustc_const_unstable(feature = "const_option_cloned", issue = "none")] pub const fn cloned(self) -> Option where T: ~const Clone { match self { Some(t) => Some(t.clone()), From 8b81937f9a98e413518829ca7793f341e22c2be1 Mon Sep 17 00:00:00 2001 From: mbartlett21 <29034492+mbartlett21@users.noreply.github.com> Date: Wed, 10 Nov 2021 09:05:15 +1000 Subject: [PATCH 3/4] Format --- library/core/src/option.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/library/core/src/option.rs b/library/core/src/option.rs index 261ff4403c94b..dd36e95323e2b 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -1498,7 +1498,10 @@ impl Option<&T> { #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_option_cloned", issue = "none")] - pub const fn cloned(self) -> Option where T: ~const Clone { + pub const fn cloned(self) -> Option + where + T: ~const Clone, + { match self { Some(t) => Some(t.clone()), None => None, @@ -1522,7 +1525,10 @@ impl Option<&mut T> { #[must_use = "`self` will be dropped if the result is not used"] #[stable(since = "1.26.0", feature = "option_ref_mut_cloned")] #[rustc_const_unstable(feature = "const_option_cloned", issue = "none")] - pub const fn cloned(self) -> Option where T: ~const Clone { + pub const fn cloned(self) -> Option + where + T: ~const Clone, + { match self { Some(t) => Some(t.clone()), None => None, From 9eb7c34f9b4fe388abfb2370ffbdff4e11df3136 Mon Sep 17 00:00:00 2001 From: mbartlett21 <29034492+mbartlett21@users.noreply.github.com> Date: Mon, 6 Dec 2021 15:26:32 +1000 Subject: [PATCH 4/4] Add tracking issue number --- library/core/src/option.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/core/src/option.rs b/library/core/src/option.rs index dd36e95323e2b..3530bf3672198 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -1497,7 +1497,7 @@ impl Option<&T> { /// ``` #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_unstable(feature = "const_option_cloned", issue = "none")] + #[rustc_const_unstable(feature = "const_option_cloned", issue = "91582")] pub const fn cloned(self) -> Option where T: ~const Clone, @@ -1524,7 +1524,7 @@ impl Option<&mut T> { /// ``` #[must_use = "`self` will be dropped if the result is not used"] #[stable(since = "1.26.0", feature = "option_ref_mut_cloned")] - #[rustc_const_unstable(feature = "const_option_cloned", issue = "none")] + #[rustc_const_unstable(feature = "const_option_cloned", issue = "91582")] pub const fn cloned(self) -> Option where T: ~const Clone,