]> git.lizzy.rs Git - rust.git/commitdiff
lowering: move scope & capture_clause stuff -> expr.rs
authorMazdak Farrokhzad <twingoow@gmail.com>
Sat, 10 Aug 2019 18:21:15 +0000 (20:21 +0200)
committerMazdak Farrokhzad <twingoow@gmail.com>
Sat, 10 Aug 2019 18:24:43 +0000 (20:24 +0200)
src/librustc/hir/lowering.rs
src/librustc/hir/lowering/expr.rs

index 9a4cf4c36cc7f4867f19c740994e94110094f76c..78941a6545f27a010491b780bfbc0bd08b0742f2 100644 (file)
@@ -971,64 +971,6 @@ fn add_in_band_defs<F, T>(
         (lowered_generics, res)
     }
 
-    fn with_catch_scope<T, F>(&mut self, catch_id: NodeId, f: F) -> T
-    where
-        F: FnOnce(&mut LoweringContext<'_>) -> T,
-    {
-        let len = self.catch_scopes.len();
-        self.catch_scopes.push(catch_id);
-
-        let result = f(self);
-        assert_eq!(
-            len + 1,
-            self.catch_scopes.len(),
-            "catch scopes should be added and removed in stack order"
-        );
-
-        self.catch_scopes.pop().unwrap();
-
-        result
-    }
-
-    fn with_loop_scope<T, F>(&mut self, loop_id: NodeId, f: F) -> T
-    where
-        F: FnOnce(&mut LoweringContext<'_>) -> T,
-    {
-        // We're no longer in the base loop's condition; we're in another loop.
-        let was_in_loop_condition = self.is_in_loop_condition;
-        self.is_in_loop_condition = false;
-
-        let len = self.loop_scopes.len();
-        self.loop_scopes.push(loop_id);
-
-        let result = f(self);
-        assert_eq!(
-            len + 1,
-            self.loop_scopes.len(),
-            "loop scopes should be added and removed in stack order"
-        );
-
-        self.loop_scopes.pop().unwrap();
-
-        self.is_in_loop_condition = was_in_loop_condition;
-
-        result
-    }
-
-    fn with_loop_condition_scope<T, F>(&mut self, f: F) -> T
-    where
-        F: FnOnce(&mut LoweringContext<'_>) -> T,
-    {
-        let was_in_loop_condition = self.is_in_loop_condition;
-        self.is_in_loop_condition = true;
-
-        let result = f(self);
-
-        self.is_in_loop_condition = was_in_loop_condition;
-
-        result
-    }
-
     fn with_dyn_type_scope<T, F>(&mut self, in_scope: bool, f: F) -> T
     where
         F: FnOnce(&mut LoweringContext<'_>) -> T,
@@ -3005,13 +2947,6 @@ fn lower_anon_const(&mut self, c: &AnonConst) -> hir::AnonConst {
         }]
     }
 
-    fn lower_capture_clause(&mut self, c: CaptureBy) -> hir::CaptureClause {
-        match c {
-            CaptureBy::Value => hir::CaptureByValue,
-            CaptureBy::Ref => hir::CaptureByRef,
-        }
-    }
-
     fn lower_block_check_mode(&mut self, b: &BlockCheckMode) -> hir::BlockCheckMode {
         match *b {
             BlockCheckMode::Default => hir::DefaultBlock,
index 96887ed85ae4cad1ad8277e9ca63651e37c2554f..d273006fbe07eddb21cfea12a94e7e80bd365995 100644 (file)
@@ -700,9 +700,16 @@ fn lower_expr_closure(
         })
     }
 
+    fn lower_capture_clause(&mut self, c: CaptureBy) -> hir::CaptureClause {
+        match c {
+            CaptureBy::Value => hir::CaptureByValue,
+            CaptureBy::Ref => hir::CaptureByRef,
+        }
+    }
+
     fn generator_movability_for_fn(
         &mut self,
-        decl: &ast::FnDecl,
+        decl: &FnDecl,
         fn_decl_span: Span,
         generator_kind: Option<hir::GeneratorKind>,
         movability: Movability,
@@ -898,6 +905,64 @@ fn lower_jump_destination(&mut self, id: NodeId, opt_label: Option<Label>) -> hi
         }
     }
 
+    fn with_catch_scope<T, F>(&mut self, catch_id: NodeId, f: F) -> T
+    where
+        F: FnOnce(&mut LoweringContext<'_>) -> T,
+    {
+        let len = self.catch_scopes.len();
+        self.catch_scopes.push(catch_id);
+
+        let result = f(self);
+        assert_eq!(
+            len + 1,
+            self.catch_scopes.len(),
+            "catch scopes should be added and removed in stack order"
+        );
+
+        self.catch_scopes.pop().unwrap();
+
+        result
+    }
+
+    fn with_loop_scope<T, F>(&mut self, loop_id: NodeId, f: F) -> T
+    where
+        F: FnOnce(&mut LoweringContext<'_>) -> T,
+    {
+        // We're no longer in the base loop's condition; we're in another loop.
+        let was_in_loop_condition = self.is_in_loop_condition;
+        self.is_in_loop_condition = false;
+
+        let len = self.loop_scopes.len();
+        self.loop_scopes.push(loop_id);
+
+        let result = f(self);
+        assert_eq!(
+            len + 1,
+            self.loop_scopes.len(),
+            "loop scopes should be added and removed in stack order"
+        );
+
+        self.loop_scopes.pop().unwrap();
+
+        self.is_in_loop_condition = was_in_loop_condition;
+
+        result
+    }
+
+    fn with_loop_condition_scope<T, F>(&mut self, f: F) -> T
+    where
+        F: FnOnce(&mut LoweringContext<'_>) -> T,
+    {
+        let was_in_loop_condition = self.is_in_loop_condition;
+        self.is_in_loop_condition = true;
+
+        let result = f(self);
+
+        self.is_in_loop_condition = was_in_loop_condition;
+
+        result
+    }
+
     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(),