]> git.lizzy.rs Git - rust.git/commitdiff
Use visit_body
authorShotaro Yamada <sinkuu@sinkuu.xyz>
Fri, 24 Nov 2017 06:35:51 +0000 (15:35 +0900)
committerShotaro Yamada <sinkuu@sinkuu.xyz>
Fri, 24 Nov 2017 06:36:41 +0000 (15:36 +0900)
src/librustc_const_eval/check_match.rs

index c76da589a1b79bd91a2eee8c359aff82613eafd4..762b9787c8d35d0b48a99585e9121a0d2649bf29 100644 (file)
@@ -28,7 +28,7 @@
 
 use rustc::hir::def::*;
 use rustc::hir::def_id::DefId;
-use rustc::hir::intravisit::{self, Visitor, FnKind, NestedVisitorMap};
+use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
 use rustc::hir::{self, Pat, PatKind};
 
 use rustc_back::slice;
@@ -44,47 +44,11 @@ fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
         NestedVisitorMap::OnlyBodies(&self.tcx.hir)
     }
 
-    fn visit_fn(&mut self, fk: FnKind<'tcx>, fd: &'tcx hir::FnDecl,
-                b: hir::BodyId, s: Span, id: ast::NodeId) {
-        intravisit::walk_fn(self, fk, fd, b, s, id);
-
-        check_body(self.tcx, b);
-    }
-
-    fn visit_item(&mut self, item: &'tcx hir::Item) {
-        intravisit::walk_item(self, item);
-        match item.node {
-            hir::ItemStatic(.., body_id) | hir::ItemConst(.., body_id) => {
-                check_body(self.tcx, body_id);
-            }
-            _ => (),
-        }
-    }
-
-    fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem) {
-        intravisit::walk_impl_item(self, ii);
-        if let hir::ImplItemKind::Const(_, body_id) = ii.node {
-            check_body(self.tcx, body_id);
-        }
-    }
-
-    fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem) {
-        intravisit::walk_trait_item(self, ti);
-        if let hir::TraitItemKind::Const(_, Some(body_id)) = ti.node {
-            check_body(self.tcx, body_id);
-        }
+    fn visit_body(&mut self, body: &'tcx hir::Body) {
+        intravisit::walk_body(self, body);
+        let def_id = self.tcx.hir.body_owner_def_id(body.id());
+        let _ = self.tcx.check_match(def_id);
     }
-
-    // Enum variants and types (e.g. `[T; { .. }]`) may have bodies too,
-    // but they are const-evaluated during typeck.
-}
-
-fn check_body<'a, 'tcx>(
-    tcx: TyCtxt<'a, 'tcx, 'tcx>,
-    body_id: hir::BodyId,
-) {
-    let def_id = tcx.hir.body_owner_def_id(body_id);
-    let _ = tcx.check_match(def_id);
 }
 
 pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {