Skip to content

Commit 82091d4

Browse files
committed
Deduplicate IsAsync::Async match
1 parent acf50b7 commit 82091d4

File tree

1 file changed

+24
-28
lines changed

1 file changed

+24
-28
lines changed

src/librustc/hir/lowering.rs

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2520,6 +2520,28 @@ impl<'a> LoweringContext<'a> {
25202520
})
25212521
}
25222522

2523+
fn lower_async_body(
2524+
&mut self,
2525+
decl: &FnDecl,
2526+
asyncness: IsAsync,
2527+
body: &Block,
2528+
) -> hir::BodyId {
2529+
self.lower_body(Some(decl), |this| {
2530+
if let IsAsync::Async(async_node_id) = asyncness {
2531+
let async_expr = this.make_async_expr(
2532+
CaptureBy::Value, async_node_id, None,
2533+
|this| {
2534+
let body = this.lower_block(body, false);
2535+
this.expr_block(body, ThinVec::new())
2536+
});
2537+
this.expr(body.span, async_expr, ThinVec::new())
2538+
} else {
2539+
let body = this.lower_block(body, false);
2540+
this.expr_block(body, ThinVec::new())
2541+
}
2542+
})
2543+
}
2544+
25232545
fn lower_item_kind(
25242546
&mut self,
25252547
id: NodeId,
@@ -2559,20 +2581,7 @@ impl<'a> LoweringContext<'a> {
25592581
// `impl Future<Output = T>` here because lower_body
25602582
// only cares about the input argument patterns in the function
25612583
// declaration (decl), not the return types.
2562-
let body_id = this.lower_body(Some(decl), |this| {
2563-
if let IsAsync::Async { closure_id, .. } = header.asyncness {
2564-
let async_expr = this.make_async_expr(
2565-
CaptureBy::Value, closure_id, None,
2566-
|this| {
2567-
let body = this.lower_block(body, false);
2568-
this.expr_block(body, ThinVec::new())
2569-
});
2570-
this.expr(body.span, async_expr, ThinVec::new())
2571-
} else {
2572-
let body = this.lower_block(body, false);
2573-
this.expr_block(body, ThinVec::new())
2574-
}
2575-
});
2584+
let body_id = this.lower_async_body(decl, header.asyncness, body);
25762585

25772586
let (generics, fn_decl) = this.add_in_band_defs(
25782587
generics,
@@ -2990,20 +2999,7 @@ impl<'a> LoweringContext<'a> {
29902999
)
29913000
}
29923001
ImplItemKind::Method(ref sig, ref body) => {
2993-
let body_id = self.lower_body(Some(&sig.decl), |this| {
2994-
if let IsAsync::Async { closure_id, .. } = sig.header.asyncness {
2995-
let async_expr = this.make_async_expr(
2996-
CaptureBy::Value, closure_id, None,
2997-
|this| {
2998-
let body = this.lower_block(body, false);
2999-
this.expr_block(body, ThinVec::new())
3000-
});
3001-
this.expr(body.span, async_expr, ThinVec::new())
3002-
} else {
3003-
let body = this.lower_block(body, false);
3004-
this.expr_block(body, ThinVec::new())
3005-
}
3006-
});
3002+
let body_id = self.lower_async_body(&sig.decl, sig.header.asyncness, body);
30073003
let impl_trait_return_allow = !self.is_in_trait_impl;
30083004

30093005
self.add_in_band_defs(

0 commit comments

Comments
 (0)