Skip to content

Commit 5591d7e

Browse files
authored
Rollup merge of #148285 - nxsaken:const_control_flow_1, r=Mark-Simulacrum
Constify `ControlFlow` methods with unstable bounds Feature: `const_control_flow` Tracking issue: #148739 This PR constifies the methods on `ControlFlow` with a dependency on #143874.
2 parents 5598d53 + 3175799 commit 5591d7e

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

library/core/src/ops/control_flow.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::marker::Destruct;
12
use crate::{convert, ops};
23

34
/// Used to tell an operation whether it should exit early or go on as usual.
@@ -185,7 +186,11 @@ impl<B, C> ControlFlow<B, C> {
185186
/// ```
186187
#[inline]
187188
#[stable(feature = "control_flow_enum", since = "1.83.0")]
188-
pub fn break_value(self) -> Option<B> {
189+
#[rustc_const_unstable(feature = "const_control_flow", issue = "148739")]
190+
pub const fn break_value(self) -> Option<B>
191+
where
192+
Self: [const] Destruct,
193+
{
189194
match self {
190195
ControlFlow::Continue(..) => None,
191196
ControlFlow::Break(x) => Some(x),
@@ -271,7 +276,11 @@ impl<B, C> ControlFlow<B, C> {
271276
/// to the break value in case it exists.
272277
#[inline]
273278
#[stable(feature = "control_flow_enum", since = "1.83.0")]
274-
pub fn map_break<T>(self, f: impl FnOnce(B) -> T) -> ControlFlow<T, C> {
279+
#[rustc_const_unstable(feature = "const_control_flow", issue = "148739")]
280+
pub const fn map_break<T, F>(self, f: F) -> ControlFlow<T, C>
281+
where
282+
F: [const] FnOnce(B) -> T + [const] Destruct,
283+
{
275284
match self {
276285
ControlFlow::Continue(x) => ControlFlow::Continue(x),
277286
ControlFlow::Break(x) => ControlFlow::Break(f(x)),
@@ -291,7 +300,11 @@ impl<B, C> ControlFlow<B, C> {
291300
/// ```
292301
#[inline]
293302
#[stable(feature = "control_flow_enum", since = "1.83.0")]
294-
pub fn continue_value(self) -> Option<C> {
303+
#[rustc_const_unstable(feature = "const_control_flow", issue = "148739")]
304+
pub const fn continue_value(self) -> Option<C>
305+
where
306+
Self: [const] Destruct,
307+
{
295308
match self {
296309
ControlFlow::Continue(x) => Some(x),
297310
ControlFlow::Break(..) => None,
@@ -376,7 +389,11 @@ impl<B, C> ControlFlow<B, C> {
376389
/// to the continue value in case it exists.
377390
#[inline]
378391
#[stable(feature = "control_flow_enum", since = "1.83.0")]
379-
pub fn map_continue<T>(self, f: impl FnOnce(C) -> T) -> ControlFlow<B, T> {
392+
#[rustc_const_unstable(feature = "const_control_flow", issue = "148739")]
393+
pub const fn map_continue<T, F>(self, f: F) -> ControlFlow<B, T>
394+
where
395+
F: [const] FnOnce(C) -> T + [const] Destruct,
396+
{
380397
match self {
381398
ControlFlow::Continue(x) => ControlFlow::Continue(f(x)),
382399
ControlFlow::Break(x) => ControlFlow::Break(x),

0 commit comments

Comments
 (0)