]> git.lizzy.rs Git - rust.git/commitdiff
lowering: extract lower_expr_asm
authorMazdak Farrokhzad <twingoow@gmail.com>
Sat, 10 Aug 2019 12:28:11 +0000 (14:28 +0200)
committerMazdak Farrokhzad <twingoow@gmail.com>
Sat, 10 Aug 2019 18:24:42 +0000 (20:24 +0200)
src/librustc/hir/lowering/expr.rs

index 9b4074294b372465e47a6bb1bb137d34ad2ec907..054035172b580367f67379e18596d831c0480f13 100644 (file)
@@ -451,36 +451,7 @@ pub(super) fn lower_expr(&mut self, e: &Expr) -> hir::Expr {
                 })
             }
             ExprKind::Ret(ref e) => hir::ExprKind::Ret(e.as_ref().map(|x| P(self.lower_expr(x)))),
-            ExprKind::InlineAsm(ref asm) => {
-                let hir_asm = hir::InlineAsm {
-                    inputs: asm.inputs.iter().map(|&(ref c, _)| c.clone()).collect(),
-                    outputs: asm.outputs
-                        .iter()
-                        .map(|out| hir::InlineAsmOutput {
-                            constraint: out.constraint.clone(),
-                            is_rw: out.is_rw,
-                            is_indirect: out.is_indirect,
-                            span: out.expr.span,
-                        })
-                        .collect(),
-                    asm: asm.asm.clone(),
-                    asm_str_style: asm.asm_str_style,
-                    clobbers: asm.clobbers.clone().into(),
-                    volatile: asm.volatile,
-                    alignstack: asm.alignstack,
-                    dialect: asm.dialect,
-                    ctxt: asm.ctxt,
-                };
-                let outputs = asm.outputs
-                    .iter()
-                    .map(|out| self.lower_expr(&out.expr))
-                    .collect();
-                let inputs = asm.inputs
-                    .iter()
-                    .map(|&(_, ref input)| self.lower_expr(input))
-                    .collect();
-                hir::ExprKind::InlineAsm(P(hir_asm), outputs, inputs)
-            }
+            ExprKind::InlineAsm(ref asm) => self.lower_expr_asm(asm),
             ExprKind::Struct(ref path, ref fields, ref maybe_expr) => hir::ExprKind::Struct(
                 P(self.lower_qpath(
                     e.id,
@@ -526,6 +497,40 @@ pub(super) fn lower_expr(&mut self, e: &Expr) -> hir::Expr {
         }
     }
 
+    fn lower_expr_asm(&mut self, asm: &InlineAsm) -> hir::ExprKind {
+        let hir_asm = hir::InlineAsm {
+            inputs: asm.inputs.iter().map(|&(ref c, _)| c.clone()).collect(),
+            outputs: asm.outputs
+                .iter()
+                .map(|out| hir::InlineAsmOutput {
+                    constraint: out.constraint.clone(),
+                    is_rw: out.is_rw,
+                    is_indirect: out.is_indirect,
+                    span: out.expr.span,
+                })
+                .collect(),
+            asm: asm.asm.clone(),
+            asm_str_style: asm.asm_str_style,
+            clobbers: asm.clobbers.clone().into(),
+            volatile: asm.volatile,
+            alignstack: asm.alignstack,
+            dialect: asm.dialect,
+            ctxt: asm.ctxt,
+        };
+
+        let outputs = asm.outputs
+            .iter()
+            .map(|out| self.lower_expr(&out.expr))
+            .collect();
+
+        let inputs = asm.inputs
+            .iter()
+            .map(|&(_, ref input)| self.lower_expr(input))
+            .collect();
+
+        hir::ExprKind::InlineAsm(P(hir_asm), outputs, inputs)
+    }
+
     fn lower_expr_yield(&mut self, span: Span, opt_expr: Option<&Expr>) -> hir::ExprKind {
         match self.generator_kind {
             Some(hir::GeneratorKind::Gen) => {},