Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions library/core/src/ops/control_flow.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -183,7 +184,11 @@ impl<B, C> ControlFlow<B, C> {
/// ```
#[inline]
#[stable(feature = "control_flow_enum", since = "1.83.0")]
pub fn break_value(self) -> Option<B> {
#[rustc_const_unstable(feature = "const_control_flow", issue = "148739")]
pub const fn break_value(self) -> Option<B>
where
Self: [const] Destruct,
{
match self {
ControlFlow::Continue(..) => None,
ControlFlow::Break(x) => Some(x),
Expand Down Expand Up @@ -268,7 +273,11 @@ impl<B, C> ControlFlow<B, C> {
/// to the break value in case it exists.
#[inline]
#[stable(feature = "control_flow_enum", since = "1.83.0")]
pub fn map_break<T>(self, f: impl FnOnce(B) -> T) -> ControlFlow<T, C> {
#[rustc_const_unstable(feature = "const_control_flow", issue = "148739")]
pub const fn map_break<T, F>(self, f: F) -> ControlFlow<T, C>
where
F: [const] FnOnce(B) -> T + [const] Destruct,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might it be good to have something like [const] (A+B+C)?

{
match self {
ControlFlow::Continue(x) => ControlFlow::Continue(x),
ControlFlow::Break(x) => ControlFlow::Break(f(x)),
Expand All @@ -288,7 +297,11 @@ impl<B, C> ControlFlow<B, C> {
/// ```
#[inline]
#[stable(feature = "control_flow_enum", since = "1.83.0")]
pub fn continue_value(self) -> Option<C> {
#[rustc_const_unstable(feature = "const_control_flow", issue = "148739")]
pub const fn continue_value(self) -> Option<C>
where
Self: [const] Destruct,
{
match self {
ControlFlow::Continue(x) => Some(x),
ControlFlow::Break(..) => None,
Expand Down Expand Up @@ -372,7 +385,11 @@ impl<B, C> ControlFlow<B, C> {
/// to the continue value in case it exists.
#[inline]
#[stable(feature = "control_flow_enum", since = "1.83.0")]
pub fn map_continue<T>(self, f: impl FnOnce(C) -> T) -> ControlFlow<B, T> {
#[rustc_const_unstable(feature = "const_control_flow", issue = "148739")]
pub const fn map_continue<T, F>(self, f: F) -> ControlFlow<B, T>
where
F: [const] FnOnce(C) -> T + [const] Destruct,
{
match self {
ControlFlow::Continue(x) => ControlFlow::Continue(f(x)),
ControlFlow::Break(x) => ControlFlow::Break(x),
Expand Down
Loading