about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorOliver Schneider <github35764891676564198441@oli-obk.de>2018-06-27 17:32:48 +0200
committerOliver Schneider <github35764891676564198441@oli-obk.de>2018-06-30 11:45:10 +0200
commit82091d421a06db8e37a20bbbfbc017416fea2a0c (patch)
tree6d406beb68b22b96f63e506a82a0b511a5ad2967 /src
parentacf50b79beb5909c16861cc7c91e8226b7f78272 (diff)
downloadrust-82091d421a06db8e37a20bbbfbc017416fea2a0c.tar.gz
rust-82091d421a06db8e37a20bbbfbc017416fea2a0c.zip
Deduplicate `IsAsync::Async` match
Diffstat (limited to 'src')
-rw-r--r--src/librustc/hir/lowering.rs52
1 files changed, 24 insertions, 28 deletions
diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs
index 0bd5b6b627f..c4d8100a1ca 100644
--- a/src/librustc/hir/lowering.rs
+++ b/src/librustc/hir/lowering.rs
@@ -2520,6 +2520,28 @@ impl<'a> LoweringContext<'a> {
         })
     }
 
+    fn lower_async_body(
+        &mut self,
+        decl: &FnDecl,
+        asyncness: IsAsync,
+        body: &Block,
+    ) -> hir::BodyId {
+        self.lower_body(Some(decl), |this| {
+            if let IsAsync::Async(async_node_id) = asyncness {
+                let async_expr = this.make_async_expr(
+                    CaptureBy::Value, async_node_id, None,
+                    |this| {
+                        let body = this.lower_block(body, false);
+                        this.expr_block(body, ThinVec::new())
+                    });
+                this.expr(body.span, async_expr, ThinVec::new())
+            } else {
+                let body = this.lower_block(body, false);
+                this.expr_block(body, ThinVec::new())
+            }
+        })
+    }
+
     fn lower_item_kind(
         &mut self,
         id: NodeId,
@@ -2559,20 +2581,7 @@ impl<'a> LoweringContext<'a> {
                     // `impl Future<Output = T>` here because lower_body
                     // only cares about the input argument patterns in the function
                     // declaration (decl), not the return types.
-                    let body_id = this.lower_body(Some(decl), |this| {
-                        if let IsAsync::Async { closure_id, .. } = header.asyncness {
-                            let async_expr = this.make_async_expr(
-                                CaptureBy::Value, closure_id, None,
-                                |this| {
-                                    let body = this.lower_block(body, false);
-                                    this.expr_block(body, ThinVec::new())
-                                });
-                            this.expr(body.span, async_expr, ThinVec::new())
-                        } else {
-                            let body = this.lower_block(body, false);
-                            this.expr_block(body, ThinVec::new())
-                        }
-                    });
+                    let body_id = this.lower_async_body(decl, header.asyncness, body);
 
                     let (generics, fn_decl) = this.add_in_band_defs(
                         generics,
@@ -2990,20 +2999,7 @@ impl<'a> LoweringContext<'a> {
                 )
             }
             ImplItemKind::Method(ref sig, ref body) => {
-                let body_id = self.lower_body(Some(&sig.decl), |this| {
-                    if let IsAsync::Async { closure_id, .. } = sig.header.asyncness {
-                        let async_expr = this.make_async_expr(
-                            CaptureBy::Value, closure_id, None,
-                            |this| {
-                                let body = this.lower_block(body, false);
-                                this.expr_block(body, ThinVec::new())
-                            });
-                        this.expr(body.span, async_expr, ThinVec::new())
-                    } else {
-                        let body = this.lower_block(body, false);
-                        this.expr_block(body, ThinVec::new())
-                    }
-                });
+                let body_id = self.lower_async_body(&sig.decl, sig.header.asyncness, body);
                 let impl_trait_return_allow = !self.is_in_trait_impl;
 
                 self.add_in_band_defs(