diff options
| author | bors <bors@rust-lang.org> | 2023-12-26 04:25:53 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-12-26 04:25:53 +0000 |
| commit | 1ab783112ab4e4807304dbd249b39771246013ef (patch) | |
| tree | 827d6051e0e3ffcaadd0d6c7369b71547319a525 /compiler/rustc_mir_transform/src | |
| parent | 2271c26e4a8e062bb00d709d0ccb5846e0c341b9 (diff) | |
| parent | ba912855cc1aff5f2b403411c8d890d3978abf9a (diff) | |
| download | rust-1ab783112ab4e4807304dbd249b39771246013ef.tar.gz rust-1ab783112ab4e4807304dbd249b39771246013ef.zip | |
Auto merge of #119258 - compiler-errors:closure-kind, r=eholk
Make closures carry their own ClosureKind Right now, we use the "`movability`" field of `hir::Closure` to distinguish a closure and a coroutine. This is paired together with the `CoroutineKind`, which is located not in the `hir::Closure`, but the `hir::Body`. This is strange and redundant. This PR introduces `ClosureKind` with two variants -- `Closure` and `Coroutine`, which is put into `hir::Closure`. The `CoroutineKind` is thus removed from `hir::Body`, and `Option<Movability>` no longer needs to be a stand-in for "is this a closure or a coroutine". r? eholk
Diffstat (limited to 'compiler/rustc_mir_transform/src')
| -rw-r--r-- | compiler/rustc_mir_transform/src/coroutine.rs | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/compiler/rustc_mir_transform/src/coroutine.rs b/compiler/rustc_mir_transform/src/coroutine.rs index d1d5b72af70..05d8d842b58 100644 --- a/compiler/rustc_mir_transform/src/coroutine.rs +++ b/compiler/rustc_mir_transform/src/coroutine.rs @@ -257,7 +257,7 @@ impl<'tcx> TransformVisitor<'tcx> { CoroutineKind::Desugared(CoroutineDesugaring::Async, _) => { span_bug!(body.span, "`Future`s are not fused inherently") } - CoroutineKind::Coroutine => span_bug!(body.span, "`Coroutine`s cannot be fused"), + CoroutineKind::Coroutine(_) => span_bug!(body.span, "`Coroutine`s cannot be fused"), // `gen` continues return `None` CoroutineKind::Desugared(CoroutineDesugaring::Gen, _) => { let option_def_id = self.tcx.require_lang_item(LangItem::Option, None); @@ -396,7 +396,7 @@ impl<'tcx> TransformVisitor<'tcx> { Rvalue::Use(val) } } - CoroutineKind::Coroutine => { + CoroutineKind::Coroutine(_) => { let coroutine_state_def_id = self.tcx.require_lang_item(LangItem::CoroutineState, None); let args = self.tcx.mk_args(&[self.old_yield_ty.into(), self.old_ret_ty.into()]); @@ -1428,7 +1428,8 @@ fn create_coroutine_resume_function<'tcx>( if can_return { let block = match coroutine_kind { - CoroutineKind::Desugared(CoroutineDesugaring::Async, _) | CoroutineKind::Coroutine => { + CoroutineKind::Desugared(CoroutineDesugaring::Async, _) + | CoroutineKind::Coroutine(_) => { insert_panic_block(tcx, body, ResumedAfterReturn(coroutine_kind)) } CoroutineKind::Desugared(CoroutineDesugaring::AsyncGen, _) @@ -1643,7 +1644,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform { // The yield ty is already `Poll<Option<yield_ty>>` old_yield_ty } - CoroutineKind::Coroutine => { + CoroutineKind::Coroutine(_) => { // Compute CoroutineState<yield_ty, return_ty> let state_did = tcx.require_lang_item(LangItem::CoroutineState, None); let state_adt_ref = tcx.adt_def(state_did); |
