Skip to content

Commit 548e309

Browse files
committed
lowering: extract lower_expr_closure
1 parent ca19e32 commit 548e309

File tree

1 file changed

+39
-36
lines changed

1 file changed

+39
-36
lines changed

src/librustc/hir/lowering/expr.rs

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -266,42 +266,10 @@ impl LoweringContext<'_> {
266266
ExprKind::Await(ref expr) => self.lower_await(e.span, expr),
267267
ExprKind::Closure(
268268
capture_clause, asyncness, movability, ref decl, ref body, fn_decl_span
269-
) => {
270-
if let IsAsync::Async { closure_id, .. } = asyncness {
271-
self.lower_expr_async_closure(
272-
capture_clause,
273-
closure_id,
274-
decl,
275-
body,
276-
fn_decl_span,
277-
)
278-
} else {
279-
// Lower outside new scope to preserve `is_in_loop_condition`.
280-
let fn_decl = self.lower_fn_decl(decl, None, false, None);
281-
282-
self.with_new_scopes(|this| {
283-
this.current_item = Some(fn_decl_span);
284-
let mut generator_kind = None;
285-
let body_id = this.lower_fn_body(decl, |this| {
286-
let e = this.lower_expr(body);
287-
generator_kind = this.generator_kind;
288-
e
289-
});
290-
let generator_option = this.generator_movability_for_fn(
291-
&decl,
292-
fn_decl_span,
293-
generator_kind,
294-
movability,
295-
);
296-
hir::ExprKind::Closure(
297-
this.lower_capture_clause(capture_clause),
298-
fn_decl,
299-
body_id,
300-
fn_decl_span,
301-
generator_option,
302-
)
303-
})
304-
}
269+
) => if let IsAsync::Async { closure_id, .. } = asyncness {
270+
self.lower_expr_async_closure(capture_clause, closure_id, decl, body, fn_decl_span)
271+
} else {
272+
self.lower_expr_closure(capture_clause, movability, decl, body, fn_decl_span)
305273
}
306274
ExprKind::Block(ref blk, opt_label) => {
307275
hir::ExprKind::Block(self.lower_block(blk,
@@ -407,6 +375,41 @@ impl LoweringContext<'_> {
407375
}
408376
}
409377

378+
fn lower_expr_closure(
379+
&mut self,
380+
capture_clause: CaptureBy,
381+
movability: Movability,
382+
decl: &FnDecl,
383+
body: &Expr,
384+
fn_decl_span: Span,
385+
) -> hir::ExprKind {
386+
// Lower outside new scope to preserve `is_in_loop_condition`.
387+
let fn_decl = self.lower_fn_decl(decl, None, false, None);
388+
389+
self.with_new_scopes(|this| {
390+
this.current_item = Some(fn_decl_span);
391+
let mut generator_kind = None;
392+
let body_id = this.lower_fn_body(decl, |this| {
393+
let e = this.lower_expr(body);
394+
generator_kind = this.generator_kind;
395+
e
396+
});
397+
let generator_option = this.generator_movability_for_fn(
398+
&decl,
399+
fn_decl_span,
400+
generator_kind,
401+
movability,
402+
);
403+
hir::ExprKind::Closure(
404+
this.lower_capture_clause(capture_clause),
405+
fn_decl,
406+
body_id,
407+
fn_decl_span,
408+
generator_option,
409+
)
410+
})
411+
}
412+
410413
fn lower_expr_async_closure(
411414
&mut self,
412415
capture_clause: CaptureBy,

0 commit comments

Comments
 (0)