Skip to content

Commit 5a8fcab

Browse files
Rollup merge of #130518 - scottmcm:stabilize-controlflow-extra, r=dtolnay
Stabilize the `map`/`value` methods on `ControlFlow` And fix the stability attribute on the `pub use` in `core::ops`. libs-api in #75744 (comment) seemed reasonably happy with naming for these, so let's try for an FCP. Summary: ```rust impl<B, C> ControlFlow<B, C> { pub fn break_value(self) -> Option<B>; pub fn map_break<T>(self, f: impl FnOnce(B) -> T) -> ControlFlow<T, C>; pub fn continue_value(self) -> Option<C>; pub fn map_continue<T>(self, f: impl FnOnce(C) -> T) -> ControlFlow<B, T>; } ``` Resolves #75744 ``@rustbot`` label +needs-fcp +t-libs-api -t-libs --- Aside, in case it keeps someone else from going down the same dead end: I looked at the `{break,continue}_value` methods and tried to make them `const` as part of this, but that's disallowed because of not having `const Drop`, so put it back to not even unstably-const.
2 parents b88f56f + ddfd0c7 commit 5a8fcab

File tree

32 files changed

+15
-53
lines changed

32 files changed

+15
-53
lines changed

compiler/rustc_borrowck/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#![doc(rust_logo)]
66
#![feature(assert_matches)]
77
#![feature(box_patterns)]
8-
#![feature(control_flow_enum)]
98
#![feature(file_buffered)]
109
#![feature(let_chains)]
1110
#![feature(never_type)]

compiler/rustc_hir_analysis/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ This API is completely unstable and subject to change.
6262
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
6363
#![doc(rust_logo)]
6464
#![feature(assert_matches)]
65-
#![feature(control_flow_enum)]
6665
#![feature(if_let_guard)]
6766
#![feature(iter_intersperse)]
6867
#![feature(let_chains)]

compiler/rustc_hir_typeck/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#![allow(rustc::untranslatable_diagnostic)]
44
#![feature(array_windows)]
55
#![feature(box_patterns)]
6-
#![feature(control_flow_enum)]
76
#![feature(if_let_guard)]
87
#![feature(let_chains)]
98
#![feature(never_type)]

compiler/rustc_infer/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#![doc(rust_logo)]
2121
#![feature(assert_matches)]
2222
#![feature(box_patterns)]
23-
#![feature(control_flow_enum)]
2423
#![feature(extend_one)]
2524
#![feature(if_let_guard)]
2625
#![feature(iter_intersperse)]

compiler/rustc_lint/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#![feature(array_windows)]
3333
#![feature(assert_matches)]
3434
#![feature(box_patterns)]
35-
#![feature(control_flow_enum)]
3635
#![feature(extract_if)]
3736
#![feature(if_let_guard)]
3837
#![feature(iter_order_by)]

compiler/rustc_metadata/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#![allow(internal_features)]
33
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
44
#![doc(rust_logo)]
5-
#![feature(control_flow_enum)]
65
#![feature(coroutines)]
76
#![feature(decl_macro)]
87
#![feature(error_iter)]

compiler/rustc_trait_selection/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#![feature(associated_type_defaults)]
2121
#![feature(box_patterns)]
2222
#![feature(cfg_version)]
23-
#![feature(control_flow_enum)]
2423
#![feature(extract_if)]
2524
#![feature(if_let_guard)]
2625
#![feature(iter_intersperse)]

library/core/src/ops/control_flow.rs

+6-14
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,13 @@ impl<B, C> ControlFlow<B, C> {
171171
/// # Examples
172172
///
173173
/// ```
174-
/// #![feature(control_flow_enum)]
175174
/// use std::ops::ControlFlow;
176175
///
177176
/// assert_eq!(ControlFlow::<i32, String>::Break(3).break_value(), Some(3));
178177
/// assert_eq!(ControlFlow::<String, i32>::Continue(3).break_value(), None);
179178
/// ```
180179
#[inline]
181-
#[unstable(feature = "control_flow_enum", reason = "new API", issue = "75744")]
180+
#[stable(feature = "control_flow_enum", since = "CURRENT_RUSTC_VERSION")]
182181
pub fn break_value(self) -> Option<B> {
183182
match self {
184183
ControlFlow::Continue(..) => None,
@@ -189,11 +188,8 @@ impl<B, C> ControlFlow<B, C> {
189188
/// Maps `ControlFlow<B, C>` to `ControlFlow<T, C>` by applying a function
190189
/// to the break value in case it exists.
191190
#[inline]
192-
#[unstable(feature = "control_flow_enum", reason = "new API", issue = "75744")]
193-
pub fn map_break<T, F>(self, f: F) -> ControlFlow<T, C>
194-
where
195-
F: FnOnce(B) -> T,
196-
{
191+
#[stable(feature = "control_flow_enum", since = "CURRENT_RUSTC_VERSION")]
192+
pub fn map_break<T>(self, f: impl FnOnce(B) -> T) -> ControlFlow<T, C> {
197193
match self {
198194
ControlFlow::Continue(x) => ControlFlow::Continue(x),
199195
ControlFlow::Break(x) => ControlFlow::Break(f(x)),
@@ -206,14 +202,13 @@ impl<B, C> ControlFlow<B, C> {
206202
/// # Examples
207203
///
208204
/// ```
209-
/// #![feature(control_flow_enum)]
210205
/// use std::ops::ControlFlow;
211206
///
212207
/// assert_eq!(ControlFlow::<i32, String>::Break(3).continue_value(), None);
213208
/// assert_eq!(ControlFlow::<String, i32>::Continue(3).continue_value(), Some(3));
214209
/// ```
215210
#[inline]
216-
#[unstable(feature = "control_flow_enum", reason = "new API", issue = "75744")]
211+
#[stable(feature = "control_flow_enum", since = "CURRENT_RUSTC_VERSION")]
217212
pub fn continue_value(self) -> Option<C> {
218213
match self {
219214
ControlFlow::Continue(x) => Some(x),
@@ -224,11 +219,8 @@ impl<B, C> ControlFlow<B, C> {
224219
/// Maps `ControlFlow<B, C>` to `ControlFlow<B, T>` by applying a function
225220
/// to the continue value in case it exists.
226221
#[inline]
227-
#[unstable(feature = "control_flow_enum", reason = "new API", issue = "75744")]
228-
pub fn map_continue<T, F>(self, f: F) -> ControlFlow<B, T>
229-
where
230-
F: FnOnce(C) -> T,
231-
{
222+
#[stable(feature = "control_flow_enum", since = "CURRENT_RUSTC_VERSION")]
223+
pub fn map_continue<T>(self, f: impl FnOnce(C) -> T) -> ControlFlow<B, T> {
232224
match self {
233225
ControlFlow::Continue(x) => ControlFlow::Continue(f(x)),
234226
ControlFlow::Break(x) => ControlFlow::Break(x),

library/core/src/ops/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ pub use self::async_function::{AsyncFn, AsyncFnMut, AsyncFnOnce};
162162
pub use self::bit::{BitAnd, BitOr, BitXor, Not, Shl, Shr};
163163
#[stable(feature = "op_assign_traits", since = "1.8.0")]
164164
pub use self::bit::{BitAndAssign, BitOrAssign, BitXorAssign, ShlAssign, ShrAssign};
165-
#[unstable(feature = "control_flow_enum", reason = "new API", issue = "75744")]
165+
#[stable(feature = "control_flow_enum_type", since = "1.55.0")]
166166
pub use self::control_flow::ControlFlow;
167167
#[unstable(feature = "coroutine_trait", issue = "43122")]
168168
pub use self::coroutine::{Coroutine, CoroutineState};

src/tools/clippy/clippy_lints/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#![feature(array_windows)]
22
#![feature(binary_heap_into_iter_sorted)]
33
#![feature(box_patterns)]
4-
#![feature(control_flow_enum)]
54
#![feature(f128)]
65
#![feature(f16)]
76
#![feature(if_let_guard)]

src/tools/clippy/clippy_utils/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![feature(array_chunks)]
22
#![feature(box_patterns)]
3-
#![feature(control_flow_enum)]
43
#![feature(f128)]
54
#![feature(f16)]
65
#![feature(if_let_guard)]

tests/mir-opt/jump_threading.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//@ compile-flags: -Zmir-enable-passes=+Inline
33
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
44

5-
#![feature(control_flow_enum)]
65
#![feature(try_trait_v2)]
76
#![feature(custom_mir, core_intrinsics, rustc_attrs)]
87

tests/mir-opt/separate_const_switch.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// skip-filecheck
2-
#![feature(control_flow_enum)]
32
#![feature(try_trait_v2)]
43

54
//@ compile-flags: -Zunsound-mir-opts

tests/ui-fulldeps/stable-mir/check_abi.rs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#![feature(rustc_private)]
1010
#![feature(assert_matches)]
11-
#![feature(control_flow_enum)]
1211
#![feature(ascii_char, ascii_char_variants)]
1312

1413
extern crate rustc_hir;

tests/ui-fulldeps/stable-mir/check_allocation.rs

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#![feature(rustc_private)]
1212
#![feature(assert_matches)]
13-
#![feature(control_flow_enum)]
1413
#![feature(ascii_char, ascii_char_variants)]
1514

1615
extern crate rustc_hir;

tests/ui-fulldeps/stable-mir/check_attribute.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//@ ignore-windows-gnu mingw has troubles with linking https://github.com/rust-lang/rust/pull/116837
88

99
#![feature(rustc_private)]
10-
#![feature(control_flow_enum)]
1110

1211
extern crate rustc_hir;
1312
#[macro_use]

tests/ui-fulldeps/stable-mir/check_def_ty.rs

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#![feature(rustc_private)]
1212
#![feature(assert_matches)]
13-
#![feature(control_flow_enum)]
1413

1514
#[macro_use]
1615
extern crate rustc_smir;

tests/ui-fulldeps/stable-mir/check_defs.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#![feature(rustc_private)]
1111
#![feature(assert_matches)]
12-
#![feature(control_flow_enum)]
1312

1413
#[macro_use]
1514
extern crate rustc_smir;

tests/ui-fulldeps/stable-mir/check_foreign.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#![feature(rustc_private)]
1111
#![feature(assert_matches)]
12-
#![feature(control_flow_enum)]
1312

1413
extern crate rustc_middle;
1514
#[macro_use]

tests/ui-fulldeps/stable-mir/check_instance.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#![feature(rustc_private)]
1111
#![feature(assert_matches)]
12-
#![feature(control_flow_enum)]
1312

1413
#[macro_use]
1514
extern crate rustc_smir;

tests/ui-fulldeps/stable-mir/check_item_kind.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#![feature(rustc_private)]
1111
#![feature(assert_matches)]
12-
#![feature(control_flow_enum)]
1312

1413
#[macro_use]
1514
extern crate rustc_smir;

tests/ui-fulldeps/stable-mir/check_trait_queries.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#![feature(rustc_private)]
1111
#![feature(assert_matches)]
12-
#![feature(control_flow_enum)]
1312

1413
#[macro_use]
1514
extern crate rustc_smir;

tests/ui-fulldeps/stable-mir/check_transform.rs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#![feature(rustc_private)]
1010
#![feature(assert_matches)]
11-
#![feature(control_flow_enum)]
1211
#![feature(ascii_char, ascii_char_variants)]
1312

1413
extern crate rustc_hir;

tests/ui-fulldeps/stable-mir/check_ty_fold.rs

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#![feature(rustc_private)]
1212
#![feature(assert_matches)]
13-
#![feature(control_flow_enum)]
1413

1514
#[macro_use]
1615
extern crate rustc_smir;

tests/ui-fulldeps/stable-mir/crate-info.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#![feature(rustc_private)]
1111
#![feature(assert_matches)]
12-
#![feature(control_flow_enum)]
1312

1413
extern crate rustc_hir;
1514
#[macro_use]

tests/ui-fulldeps/stable-mir/projections.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#![feature(rustc_private)]
1111
#![feature(assert_matches)]
12-
#![feature(control_flow_enum)]
1312

1413
extern crate rustc_hir;
1514
#[macro_use]

tests/ui-fulldeps/stable-mir/smir_internal.rs

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#![feature(rustc_private)]
1212
#![feature(assert_matches)]
13-
#![feature(control_flow_enum)]
1413

1514
#[macro_use]
1615
extern crate rustc_smir;

tests/ui-fulldeps/stable-mir/smir_serde.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#![feature(rustc_private)]
1111
#![feature(assert_matches)]
12-
#![feature(control_flow_enum)]
1312

1413
#[macro_use]
1514
extern crate rustc_smir;

tests/ui-fulldeps/stable-mir/smir_visitor.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#![feature(rustc_private)]
1111
#![feature(assert_matches)]
12-
#![feature(control_flow_enum)]
1312

1413
#[macro_use]
1514
extern crate rustc_smir;

tests/ui/try-trait/bad-interconversion.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(control_flow_enum)]
2-
31
use std::ops::ControlFlow;
42

53
fn result_to_result() -> Result<u64, u8> {

tests/ui/try-trait/bad-interconversion.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0277]: `?` couldn't convert the error to `u8`
2-
--> $DIR/bad-interconversion.rs:6:20
2+
--> $DIR/bad-interconversion.rs:4:20
33
|
44
LL | fn result_to_result() -> Result<u64, u8> {
55
| --------------- expected `u8` because of this
@@ -15,7 +15,7 @@ LL | Ok(Err(123_i32)?)
1515
= note: required for `Result<u64, u8>` to implement `FromResidual<Result<Infallible, i32>>`
1616

1717
error[E0277]: the `?` operator can only be used on `Result`s, not `Option`s, in a function that returns `Result`
18-
--> $DIR/bad-interconversion.rs:11:12
18+
--> $DIR/bad-interconversion.rs:9:12
1919
|
2020
LL | fn option_to_result() -> Result<u64, String> {
2121
| -------------------------------------------- this function returns a `Result`
@@ -26,7 +26,7 @@ LL | Some(3)?;
2626
= help: the trait `FromResidual<Result<Infallible, E>>` is implemented for `Result<T, F>`
2727

2828
error[E0277]: the `?` operator can only be used on `Result`s in a function that returns `Result`
29-
--> $DIR/bad-interconversion.rs:17:31
29+
--> $DIR/bad-interconversion.rs:15:31
3030
|
3131
LL | fn control_flow_to_result() -> Result<u64, String> {
3232
| -------------------------------------------------- this function returns a `Result`
@@ -37,7 +37,7 @@ LL | Ok(ControlFlow::Break(123)?)
3737
= help: the trait `FromResidual<Result<Infallible, E>>` is implemented for `Result<T, F>`
3838

3939
error[E0277]: the `?` operator can only be used on `Option`s, not `Result`s, in a function that returns `Option`
40-
--> $DIR/bad-interconversion.rs:22:22
40+
--> $DIR/bad-interconversion.rs:20:22
4141
|
4242
LL | fn result_to_option() -> Option<u16> {
4343
| ------------------------------------ this function returns an `Option`
@@ -48,7 +48,7 @@ LL | Some(Err("hello")?)
4848
= help: the trait `FromResidual<Option<Infallible>>` is implemented for `Option<T>`
4949

5050
error[E0277]: the `?` operator can only be used on `Option`s in a function that returns `Option`
51-
--> $DIR/bad-interconversion.rs:27:33
51+
--> $DIR/bad-interconversion.rs:25:33
5252
|
5353
LL | fn control_flow_to_option() -> Option<u64> {
5454
| ------------------------------------------ this function returns an `Option`
@@ -59,7 +59,7 @@ LL | Some(ControlFlow::Break(123)?)
5959
= help: the trait `FromResidual<Option<Infallible>>` is implemented for `Option<T>`
6060

6161
error[E0277]: the `?` operator can only be used on `ControlFlow`s in a function that returns `ControlFlow`
62-
--> $DIR/bad-interconversion.rs:32:39
62+
--> $DIR/bad-interconversion.rs:30:39
6363
|
6464
LL | fn result_to_control_flow() -> ControlFlow<String> {
6565
| -------------------------------------------------- this function returns a `ControlFlow`
@@ -71,7 +71,7 @@ LL | ControlFlow::Continue(Err("hello")?)
7171
= help: for that trait implementation, expected `ControlFlow<String, Infallible>`, found `Result<Infallible, &str>`
7272

7373
error[E0277]: the `?` operator can only be used on `ControlFlow`s in a function that returns `ControlFlow`
74-
--> $DIR/bad-interconversion.rs:37:12
74+
--> $DIR/bad-interconversion.rs:35:12
7575
|
7676
LL | fn option_to_control_flow() -> ControlFlow<u64> {
7777
| ----------------------------------------------- this function returns a `ControlFlow`
@@ -83,7 +83,7 @@ LL | Some(3)?;
8383
= help: for that trait implementation, expected `ControlFlow<u64, Infallible>`, found `Option<Infallible>`
8484

8585
error[E0277]: the `?` operator in a function that returns `ControlFlow<B, _>` can only be used on other `ControlFlow<B, _>`s (with the same Break type)
86-
--> $DIR/bad-interconversion.rs:43:29
86+
--> $DIR/bad-interconversion.rs:41:29
8787
|
8888
LL | fn control_flow_to_control_flow() -> ControlFlow<i64> {
8989
| ----------------------------------------------------- this function returns a `ControlFlow`

tests/ui/try-trait/try-operator-custom.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//@ run-pass
22

3-
#![feature(control_flow_enum)]
43
#![feature(try_trait_v2)]
54

65
use std::ops::{ControlFlow, FromResidual, Try};

0 commit comments

Comments
 (0)