Skip to content

Commit 852bd86

Browse files
committed
Constify ControlFlow methods (unstable bounds)
1 parent acda5e9 commit 852bd86

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.
@@ -183,7 +184,11 @@ impl<B, C> ControlFlow<B, C> {
183184
/// ```
184185
#[inline]
185186
#[stable(feature = "control_flow_enum", since = "1.83.0")]
186-
pub fn break_value(self) -> Option<B> {
187+
#[rustc_const_unstable(feature = "const_control_flow", issue = "none")]
188+
pub const fn break_value(self) -> Option<B>
189+
where
190+
Self: [const] Destruct,
191+
{
187192
match self {
188193
ControlFlow::Continue(..) => None,
189194
ControlFlow::Break(x) => Some(x),
@@ -268,7 +273,11 @@ impl<B, C> ControlFlow<B, C> {
268273
/// to the break value in case it exists.
269274
#[inline]
270275
#[stable(feature = "control_flow_enum", since = "1.83.0")]
271-
pub fn map_break<T>(self, f: impl FnOnce(B) -> T) -> ControlFlow<T, C> {
276+
#[rustc_const_unstable(feature = "const_control_flow", issue = "none")]
277+
pub const fn map_break<T, F>(self, f: F) -> ControlFlow<T, C>
278+
where
279+
F: [const] FnOnce(B) -> T + [const] Destruct,
280+
{
272281
match self {
273282
ControlFlow::Continue(x) => ControlFlow::Continue(x),
274283
ControlFlow::Break(x) => ControlFlow::Break(f(x)),
@@ -288,7 +297,11 @@ impl<B, C> ControlFlow<B, C> {
288297
/// ```
289298
#[inline]
290299
#[stable(feature = "control_flow_enum", since = "1.83.0")]
291-
pub fn continue_value(self) -> Option<C> {
300+
#[rustc_const_unstable(feature = "const_control_flow", issue = "none")]
301+
pub const fn continue_value(self) -> Option<C>
302+
where
303+
Self: [const] Destruct,
304+
{
292305
match self {
293306
ControlFlow::Continue(x) => Some(x),
294307
ControlFlow::Break(..) => None,
@@ -372,7 +385,11 @@ impl<B, C> ControlFlow<B, C> {
372385
/// to the continue value in case it exists.
373386
#[inline]
374387
#[stable(feature = "control_flow_enum", since = "1.83.0")]
375-
pub fn map_continue<T>(self, f: impl FnOnce(C) -> T) -> ControlFlow<B, T> {
388+
#[rustc_const_unstable(feature = "const_control_flow", issue = "none")]
389+
pub const fn map_continue<T, F>(self, f: F) -> ControlFlow<B, T>
390+
where
391+
F: [const] FnOnce(C) -> T + [const] Destruct,
392+
{
376393
match self {
377394
ControlFlow::Continue(x) => ControlFlow::Continue(f(x)),
378395
ControlFlow::Break(x) => ControlFlow::Break(x),

0 commit comments

Comments
 (0)