From 852bd86d175e018ef310cfccf13406f79db630c3 Mon Sep 17 00:00:00 2001 From: nxsaken Date: Thu, 30 Oct 2025 13:59:39 +0400 Subject: [PATCH 1/2] Constify `ControlFlow` methods (unstable bounds) --- library/core/src/ops/control_flow.rs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/library/core/src/ops/control_flow.rs b/library/core/src/ops/control_flow.rs index b760a7c4e21eb..8eff1633c3b40 100644 --- a/library/core/src/ops/control_flow.rs +++ b/library/core/src/ops/control_flow.rs @@ -1,3 +1,4 @@ +use crate::marker::Destruct; use crate::{convert, ops}; /// Used to tell an operation whether it should exit early or go on as usual. @@ -183,7 +184,11 @@ impl ControlFlow { /// ``` #[inline] #[stable(feature = "control_flow_enum", since = "1.83.0")] - pub fn break_value(self) -> Option { + #[rustc_const_unstable(feature = "const_control_flow", issue = "none")] + pub const fn break_value(self) -> Option + where + Self: [const] Destruct, + { match self { ControlFlow::Continue(..) => None, ControlFlow::Break(x) => Some(x), @@ -268,7 +273,11 @@ impl ControlFlow { /// to the break value in case it exists. #[inline] #[stable(feature = "control_flow_enum", since = "1.83.0")] - pub fn map_break(self, f: impl FnOnce(B) -> T) -> ControlFlow { + #[rustc_const_unstable(feature = "const_control_flow", issue = "none")] + pub const fn map_break(self, f: F) -> ControlFlow + where + F: [const] FnOnce(B) -> T + [const] Destruct, + { match self { ControlFlow::Continue(x) => ControlFlow::Continue(x), ControlFlow::Break(x) => ControlFlow::Break(f(x)), @@ -288,7 +297,11 @@ impl ControlFlow { /// ``` #[inline] #[stable(feature = "control_flow_enum", since = "1.83.0")] - pub fn continue_value(self) -> Option { + #[rustc_const_unstable(feature = "const_control_flow", issue = "none")] + pub const fn continue_value(self) -> Option + where + Self: [const] Destruct, + { match self { ControlFlow::Continue(x) => Some(x), ControlFlow::Break(..) => None, @@ -372,7 +385,11 @@ impl ControlFlow { /// to the continue value in case it exists. #[inline] #[stable(feature = "control_flow_enum", since = "1.83.0")] - pub fn map_continue(self, f: impl FnOnce(C) -> T) -> ControlFlow { + #[rustc_const_unstable(feature = "const_control_flow", issue = "none")] + pub const fn map_continue(self, f: F) -> ControlFlow + where + F: [const] FnOnce(C) -> T + [const] Destruct, + { match self { ControlFlow::Continue(x) => ControlFlow::Continue(f(x)), ControlFlow::Break(x) => ControlFlow::Break(x), From 3175799208fb595aae960cbbc7250d10f614d6eb Mon Sep 17 00:00:00 2001 From: nxsaken Date: Sun, 9 Nov 2025 13:33:47 +0400 Subject: [PATCH 2/2] Add tracking issue number --- library/core/src/ops/control_flow.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/core/src/ops/control_flow.rs b/library/core/src/ops/control_flow.rs index 8eff1633c3b40..bc497db352021 100644 --- a/library/core/src/ops/control_flow.rs +++ b/library/core/src/ops/control_flow.rs @@ -184,7 +184,7 @@ impl ControlFlow { /// ``` #[inline] #[stable(feature = "control_flow_enum", since = "1.83.0")] - #[rustc_const_unstable(feature = "const_control_flow", issue = "none")] + #[rustc_const_unstable(feature = "const_control_flow", issue = "148739")] pub const fn break_value(self) -> Option where Self: [const] Destruct, @@ -273,7 +273,7 @@ impl ControlFlow { /// to the break value in case it exists. #[inline] #[stable(feature = "control_flow_enum", since = "1.83.0")] - #[rustc_const_unstable(feature = "const_control_flow", issue = "none")] + #[rustc_const_unstable(feature = "const_control_flow", issue = "148739")] pub const fn map_break(self, f: F) -> ControlFlow where F: [const] FnOnce(B) -> T + [const] Destruct, @@ -297,7 +297,7 @@ impl ControlFlow { /// ``` #[inline] #[stable(feature = "control_flow_enum", since = "1.83.0")] - #[rustc_const_unstable(feature = "const_control_flow", issue = "none")] + #[rustc_const_unstable(feature = "const_control_flow", issue = "148739")] pub const fn continue_value(self) -> Option where Self: [const] Destruct, @@ -385,7 +385,7 @@ impl ControlFlow { /// to the continue value in case it exists. #[inline] #[stable(feature = "control_flow_enum", since = "1.83.0")] - #[rustc_const_unstable(feature = "const_control_flow", issue = "none")] + #[rustc_const_unstable(feature = "const_control_flow", issue = "148739")] pub const fn map_continue(self, f: F) -> ControlFlow where F: [const] FnOnce(C) -> T + [const] Destruct,