rust/compiler
Yuki Okushi 5936ecc24f
Rollup merge of #85608 - scottmcm:stabilize-control-flow-enum-basics, r=m-ou-se
Stabilize `ops::ControlFlow` (just the type)

Tracking issue: https://github.com/rust-lang/rust/issues/75744 (which also tracks items *not* closed by this PR).

With the new `?` desugar implemented, [it's no longer possible to mix `Result` and `ControlFlow`](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=13feec97f5c96a9d791d97f7de2d49a6).  (At the time of making this PR, godbolt was still on the 2021-05-01 nightly, where you can see that [the mixing example compiled](https://rust.godbolt.org/z/13Ke54j16).)  That resolves the only blocker I know of, so I'd like to propose that `ControlFlow` be considered for stabilization.

Its basic existence was part of https://github.com/rust-lang/rfcs/pull/3058, where it got a bunch of positive comments (examples [1](https://github.com/rust-lang/rfcs/pull/3058#issuecomment-758277325) [2](https://github.com/rust-lang/rfcs/pull/3058#pullrequestreview-592106494) [3](https://github.com/rust-lang/rfcs/pull/3058#issuecomment-784444155) [4](https://github.com/rust-lang/rfcs/pull/3058#issuecomment-797031584)).  Its use in the compiler has been well received (https://github.com/rust-lang/rust/pull/78182#issuecomment-713695594), and there are ecosystem updates interested in using it (https://github.com/rust-itertools/itertools/issues/469#issuecomment-677729589, https://github.com/jonhoo/rust-imap/issues/194).

As this will need an FCP, picking a libs member manually:
r? `@m-ou-se`

## Stabilized APIs

```rust
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum ControlFlow<B, C = ()> {
    /// Exit the operation without running subsequent phases.
    Break(B),
    /// Move on to the next phase of the operation as normal.
    Continue(C),
}
```

As well as using `?` on a `ControlFlow<B, _>` in a function returning `ControlFlow<B, _>`.  (Note, in particular, that there's no `From::from`-conversion on the `Break` value, the way there is for `Err`s.)

## Existing APIs *not* stabilized here

All the associated methods and constants: `break_value`, `is_continue`, `map_break`, [`CONTINUE`](https://doc.rust-lang.org/nightly/std/ops/enum.ControlFlow.html#associatedconstant.CONTINUE), etc.

Some of the existing methods in nightly seem reasonable, some seem like they should be removed, and some need more discussion to decide.  But none of them are *essential*, so [as in the RFC](https://rust-lang.github.io/rfcs/3058-try-trait-v2.html#methods-on-controlflow), they're all omitted from this PR.

They can be considered separately later, as further usage demonstrates which are important.
2021-06-15 17:40:08 +09:00
..
rustc use jemallocator in rustc/rustdoc 2021-04-04 14:10:26 -07:00
rustc_apfloat remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
rustc_arena Remove (lots of) dead code 2021-03-27 22:16:33 -04:00
rustc_ast Add support for using qualified paths with structs in expression and pattern 2021-06-10 13:18:41 +02:00
rustc_ast_lowering Rollup merge of #85608 - scottmcm:stabilize-control-flow-enum-basics, r=m-ou-se 2021-06-15 17:40:08 +09:00
rustc_ast_passes simplify validate_generic_param_order 2021-06-13 01:39:57 +03:00
rustc_ast_pretty Add support for using qualified paths with structs in expression and pattern 2021-06-10 13:18:41 +02:00
rustc_attr remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
rustc_builtin_macros Auto merge of #84863 - ABouttefeux:libtest, r=m-ou-se 2021-06-06 09:13:59 +00:00
rustc_codegen_cranelift Auto merge of #85910 - cjgillot:no-meta-version, r=Aaron1011 2021-06-10 00:39:25 +00:00
rustc_codegen_llvm Auto merge of #86020 - nagisa:nagisa/outliner, r=pnkfelix 2021-06-10 15:11:01 +00:00
rustc_codegen_ssa Auto merge of #86204 - alexcrichton:wasm-simd-stable, r=Amanieu 2021-06-11 05:02:41 +00:00
rustc_data_structures Auto merge of #85885 - bjorn3:remove_box_region, r=cjgillot 2021-06-11 16:11:20 +00:00
rustc_driver Rustfmt 2021-06-04 13:20:05 +02:00
rustc_error_codes Fix typo with custom a custom -> with a custom 2021-06-13 21:21:45 +02:00
rustc_errors Auto merge of #85903 - bjorn3:rustc_serialize_cleanup, r=varkor 2021-06-07 14:40:26 +00:00
rustc_expand Add support for using qualified paths with structs in expression and pattern 2021-06-10 13:18:41 +02:00
rustc_feature Add support for using qualified paths with structs in expression and pattern 2021-06-10 13:18:41 +02:00
rustc_fs_util Optimize away a fs::metadata call. 2021-01-06 08:33:15 -08:00
rustc_graphviz Remove (lots of) dead code 2021-03-27 22:16:33 -04:00
rustc_hir Hash DefId in rustc_span. 2021-06-11 12:25:02 +02:00
rustc_hir_pretty remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
rustc_incremental Do not require the DefPathTable to construct the on-disk cache. 2021-06-08 22:23:03 +02:00
rustc_index Remove unused feature gates 2021-05-31 13:55:43 +02:00
rustc_infer Suggest a trailing comma if a 1-tuple is expected 2021-06-07 23:16:03 +02:00
rustc_interface Auto merge of #85885 - bjorn3:remove_box_region, r=cjgillot 2021-06-11 16:11:20 +00:00
rustc_lexer Fix outdated crate names in compiler docs 2021-04-08 11:12:14 -05:00
rustc_lint Add support for using qualified paths with structs in expression and pattern 2021-06-10 13:18:41 +02:00
rustc_lint_defs Fix deny(invalid_doc_attributes) 2021-06-04 15:20:26 -04:00
rustc_llvm Auto merge of #84171 - ricobbe:raw-dylib-via-llvm, r=petrochenkov 2021-06-06 03:59:17 +00:00
rustc_macros Remove unused functions and arguments from rustc_serialize 2021-06-01 19:29:11 +02:00
rustc_metadata Auto merge of #85885 - bjorn3:remove_box_region, r=cjgillot 2021-06-11 16:11:20 +00:00
rustc_middle Improve documentation on UndefinedBehaviorInfo::ValidationFailure 2021-06-14 18:57:06 +02:00
rustc_mir Adjust throw_validation_failure macro to shorten the use of with_no_trimmed_paths 2021-06-14 18:57:53 +02:00
rustc_mir_build Rollup merge of #85850 - bjorn3:less_feature_gates, r=jyn514 2021-06-04 13:42:54 +09:00
rustc_parse Add support for using qualified paths with structs in expression and pattern 2021-06-10 13:18:41 +02:00
rustc_parse_format remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
rustc_passes Rollup merge of #86047 - jyn514:doc-attrs, r=petrochenkov 2021-06-06 19:11:24 +09:00
rustc_plugin_impl Use () for plugin_registrar_fn. 2021-05-12 13:58:43 +02:00
rustc_privacy Add more tests + visit_ty in some places 2021-06-09 19:28:41 +01:00
rustc_query_impl Rollup merge of #85850 - bjorn3:less_feature_gates, r=jyn514 2021-06-04 13:42:54 +09:00
rustc_query_system Auto merge of #85903 - bjorn3:rustc_serialize_cleanup, r=varkor 2021-06-07 14:40:26 +00:00
rustc_resolve Rollup merge of #85608 - scottmcm:stabilize-control-flow-enum-basics, r=m-ou-se 2021-06-15 17:40:08 +09:00
rustc_save_analysis Revert "Merge CrateDisambiguator into StableCrateId" 2021-06-07 10:37:45 +02:00
rustc_serialize Auto merge of #85903 - bjorn3:rustc_serialize_cleanup, r=varkor 2021-06-07 14:40:26 +00:00
rustc_session Auto merge of #86117 - ehuss:force-warns-underscore, r=rylev 2021-06-14 17:21:28 +00:00
rustc_span Rollup merge of #85608 - scottmcm:stabilize-control-flow-enum-basics, r=m-ou-se 2021-06-15 17:40:08 +09:00
rustc_symbol_mangling Revert "Merge CrateDisambiguator into StableCrateId" 2021-06-07 10:37:45 +02:00
rustc_target Use try_into instead of asserting manually 2021-06-07 01:27:40 +02:00
rustc_trait_selection Auto merge of #86130 - BoxyUwU:abstract_const_as_cast, r=oli-obk 2021-06-12 08:50:22 +00:00
rustc_traits Stabilize ops::ControlFlow (just the type) 2021-05-23 13:20:05 -07:00
rustc_ty_utils Revert "Merge CrateDisambiguator into StableCrateId" 2021-06-07 10:37:45 +02:00
rustc_type_ir Remove unused feature gates 2021-05-31 13:55:43 +02:00
rustc_typeck Suggest a FnPtr type if a FnDef type is found 2021-06-11 23:05:17 +02:00