diff options
Diffstat (limited to 'compiler/rustc_ast_lowering/src')
| -rw-r--r-- | compiler/rustc_ast_lowering/src/expr.rs | 25 | ||||
| -rw-r--r-- | compiler/rustc_ast_lowering/src/item.rs | 23 | ||||
| -rw-r--r-- | compiler/rustc_ast_lowering/src/lib.rs | 18 |
3 files changed, 23 insertions, 43 deletions
diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 5846f17c539..3556ee02bd7 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -202,8 +202,10 @@ impl<'hir> LoweringContext<'_, 'hir> { fn_decl_span, fn_arg_span, }) => match coro_kind { - CoroutineKind::Async { closure_id, .. } - | CoroutineKind::Gen { closure_id, .. } => self.lower_expr_async_closure( + Some( + CoroutineKind::Async { closure_id, .. } + | CoroutineKind::Gen { closure_id, .. }, + ) => self.lower_expr_async_closure( binder, *capture_clause, e.id, @@ -214,7 +216,7 @@ impl<'hir> LoweringContext<'_, 'hir> { *fn_decl_span, *fn_arg_span, ), - CoroutineKind::None => self.lower_expr_closure( + None => self.lower_expr_closure( binder, *capture_clause, e.id, @@ -933,13 +935,7 @@ impl<'hir> LoweringContext<'_, 'hir> { let bound_generic_params = self.lower_lifetime_binder(closure_id, generic_params); // Lower outside new scope to preserve `is_in_loop_condition`. - let fn_decl = self.lower_fn_decl( - decl, - closure_id, - fn_decl_span, - FnDeclKind::Closure, - CoroutineKind::None, - ); + let fn_decl = self.lower_fn_decl(decl, closure_id, fn_decl_span, FnDeclKind::Closure, None); let c = self.arena.alloc(hir::Closure { def_id: self.local_def_id(closure_id), @@ -1054,13 +1050,8 @@ impl<'hir> LoweringContext<'_, 'hir> { // We need to lower the declaration outside the new scope, because we // have to conserve the state of being inside a loop condition for the // closure argument types. - let fn_decl = self.lower_fn_decl( - &outer_decl, - closure_id, - fn_decl_span, - FnDeclKind::Closure, - CoroutineKind::None, - ); + let fn_decl = + self.lower_fn_decl(&outer_decl, closure_id, fn_decl_span, FnDeclKind::Closure, None); let c = self.arena.alloc(hir::Closure { def_id: self.local_def_id(closure_id), diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index 5d32e1a78f1..a23a77f45be 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -602,7 +602,7 @@ impl<'hir> LoweringContext<'_, 'hir> { i.id, sig.span, FnDeclKind::ExternFn, - CoroutineKind::None, + None, ), this.lower_fn_params_to_names(fdec), ) @@ -841,7 +841,6 @@ impl<'hir> LoweringContext<'_, 'hir> { }, ), AssocItemKind::Fn(box Fn { sig, generics, body, .. }) => { - self.current_item = Some(i.span); let body_id = self.lower_maybe_coroutine_body( i.span, hir_id, @@ -1025,15 +1024,16 @@ impl<'hir> LoweringContext<'_, 'hir> { span: Span, fn_id: hir::HirId, decl: &FnDecl, - coro_kind: CoroutineKind, + coro_kind: Option<CoroutineKind>, body: Option<&Block>, ) -> hir::BodyId { - let (closure_id, body) = match (coro_kind, body) { - ( - CoroutineKind::Async { closure_id, .. } | CoroutineKind::Gen { closure_id, .. }, - Some(body), - ) => (closure_id, body), - _ => return self.lower_fn_body_block(span, decl, body), + let (Some(coro_kind), Some(body)) = (coro_kind, body) else { + return self.lower_fn_body_block(span, decl, body); + }; + let closure_id = match coro_kind { + CoroutineKind::Async { closure_id, .. } | CoroutineKind::Gen { closure_id, .. } => { + closure_id + } }; self.lower_body(|this| { @@ -1218,7 +1218,6 @@ impl<'hir> LoweringContext<'_, 'hir> { hir::CoroutineSource::Fn, mkbody, ), - CoroutineKind::None => unreachable!("we must have either an async fn or a gen fn"), }; let hir_id = this.lower_node_id(closure_id); @@ -1235,7 +1234,7 @@ impl<'hir> LoweringContext<'_, 'hir> { sig: &FnSig, id: NodeId, kind: FnDeclKind, - coro_kind: CoroutineKind, + coro_kind: Option<CoroutineKind>, ) -> (&'hir hir::Generics<'hir>, hir::FnSig<'hir>) { let header = self.lower_fn_header(sig.header); let itctx = ImplTraitContext::Universal; @@ -1247,7 +1246,7 @@ impl<'hir> LoweringContext<'_, 'hir> { } fn lower_fn_header(&mut self, h: FnHeader) -> hir::FnHeader { - let asyncness = if let CoroutineKind::Async { span, .. } = h.coro_kind { + let asyncness = if let Some(CoroutineKind::Async { span, .. }) = h.coro_kind { hir::IsAsync::Async(span) } else { hir::IsAsync::NotAsync diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 92650f0c47e..a35b1513e14 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -1359,13 +1359,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { generic_params, unsafety: self.lower_unsafety(f.unsafety), abi: self.lower_extern(f.ext), - decl: self.lower_fn_decl( - &f.decl, - t.id, - t.span, - FnDeclKind::Pointer, - CoroutineKind::None, - ), + decl: self.lower_fn_decl(&f.decl, t.id, t.span, FnDeclKind::Pointer, None), param_names: self.lower_fn_params_to_names(&f.decl), })) } @@ -1800,7 +1794,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { fn_node_id: NodeId, fn_span: Span, kind: FnDeclKind, - coro: CoroutineKind, + coro: Option<CoroutineKind>, ) -> &'hir hir::FnDecl<'hir> { let c_variadic = decl.c_variadic(); @@ -1830,11 +1824,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { })); let output = match coro { - CoroutineKind::Async { .. } | CoroutineKind::Gen { .. } => { + Some(coro) => { let fn_def_id = self.local_def_id(fn_node_id); self.lower_coroutine_fn_ret_ty(&decl.output, fn_def_id, coro, kind, fn_span) } - CoroutineKind::None => match &decl.output { + None => match &decl.output { FnRetTy::Ty(ty) => { let context = if kind.return_impl_trait_allowed() { let fn_def_id = self.local_def_id(fn_node_id); @@ -1911,9 +1905,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { let opaque_ty_node_id = match coro { CoroutineKind::Async { return_impl_trait_id, .. } | CoroutineKind::Gen { return_impl_trait_id, .. } => return_impl_trait_id, - CoroutineKind::None => { - unreachable!("lower_coroutine_fn_ret_ty must be called with either Async or Gen") - } }; let captured_lifetimes: Vec<_> = self @@ -1971,7 +1962,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { let (symbol, lang_item) = match coro { CoroutineKind::Async { .. } => (hir::FN_OUTPUT_NAME, hir::LangItem::Future), CoroutineKind::Gen { .. } => (hir::ITERATOR_ITEM_NAME, hir::LangItem::Iterator), - CoroutineKind::None => panic!("attemping to lower output type of non-coroutine fn"), }; let future_args = self.arena.alloc(hir::GenericArgs { |
