]> git.lizzy.rs Git - rust.git/commitdiff
Querify
authorShotaro Yamada <sinkuu@sinkuu.xyz>
Sat, 18 Nov 2017 15:20:41 +0000 (00:20 +0900)
committerShotaro Yamada <sinkuu@sinkuu.xyz>
Fri, 24 Nov 2017 06:36:41 +0000 (15:36 +0900)
src/librustc/dep_graph/dep_node.rs
src/librustc/ty/maps/mod.rs
src/librustc/ty/maps/plumbing.rs
src/librustc_const_eval/check_match.rs
src/librustc_const_eval/eval.rs
src/librustc_const_eval/lib.rs

index db3aa9a1efa4b6fa1ff99f1e30978cf7b2729ff5..d44fdd5d9b978d66730b85bfbd32ff33d644c599 100644 (file)
@@ -516,6 +516,7 @@ pub fn fingerprint_needed_for_crate_hash(self) -> bool {
     [] UsedTraitImports(DefId),
     [] HasTypeckTables(DefId),
     [] ConstEval { param_env: ParamEnvAnd<'tcx, (DefId, &'tcx Substs<'tcx>)> },
+    [] CheckMatch(DefId),
     [] SymbolName(DefId),
     [] InstanceSymbolName { instance: Instance<'tcx> },
     [] SpecializationGraph(DefId),
index a477e779af9a6c2a5af0fbc5543a3e9134e13de2..18c60394a8ed5fdc13788eeec7f21fbdb428ee3a 100644 (file)
@@ -37,7 +37,7 @@
 use ty::steal::Steal;
 use ty::subst::Substs;
 use util::nodemap::{DefIdSet, DefIdMap, ItemLocalSet};
-use util::common::{profq_msg, ProfileQueriesMsg};
+use util::common::{profq_msg, ErrorReported, ProfileQueriesMsg};
 
 use rustc_data_structures::indexed_set::IdxSetBuf;
 use rustc_back::PanicStrategy;
     [] fn const_eval: const_eval_dep_node(ty::ParamEnvAnd<'tcx, (DefId, &'tcx Substs<'tcx>)>)
         -> const_val::EvalResult<'tcx>,
 
+    [] fn check_match: CheckMatch(DefId)
+        -> Result<(), ErrorReported>,
+
     /// Performs the privacy check and computes "access levels".
     [] fn privacy_access_levels: PrivacyAccessLevels(CrateNum) -> Rc<AccessLevels>,
 
index 739537c7c3a71520dfc23541a8dd71fd02378f55..e63365aa4a8b251f20bad5980a7378c323d59426 100644 (file)
@@ -800,6 +800,7 @@ macro_rules! force {
         DepKind::SpecializationGraph => { force!(specialization_graph_of, def_id!()); }
         DepKind::ObjectSafety => { force!(is_object_safe, def_id!()); }
         DepKind::TraitImpls => { force!(trait_impls_of, def_id!()); }
+        DepKind::CheckMatch => { force!(check_match, def_id!()); }
 
         DepKind::ParamEnv => { force!(param_env, def_id!()); }
         DepKind::DescribeDef => { force!(describe_def, def_id!()); }
index bae3cf4db017fd97e59511717ac806aa13ac7e6e..c76da589a1b79bd91a2eee8c359aff82613eafd4 100644 (file)
@@ -24,6 +24,7 @@
 use rustc::ty::subst::Substs;
 use rustc::lint;
 use rustc_errors::DiagnosticBuilder;
+use rustc::util::common::ErrorReported;
 
 use rustc::hir::def::*;
 use rustc::hir::def_id::DefId;
@@ -47,17 +48,14 @@ 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);
 
-        let def_id = self.tcx.hir.local_def_id(id);
-
-        check_body(self.tcx, def_id, b);
+        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) => {
-                let def_id = self.tcx.hir.local_def_id(item.id);
-                check_body(self.tcx, def_id, body_id);
+                check_body(self.tcx, body_id);
             }
             _ => (),
         }
@@ -66,16 +64,14 @@ fn visit_item(&mut self, item: &'tcx hir::Item) {
     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 {
-            let def_id = self.tcx.hir.local_def_id(ii.id);
-            check_body(self.tcx, def_id, body_id);
+            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 {
-            let def_id = self.tcx.hir.local_def_id(ti.id);
-            check_body(self.tcx, def_id, body_id);
+            check_body(self.tcx, body_id);
         }
     }
 
@@ -83,23 +79,38 @@ fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem) {
     // 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>) {
     tcx.hir.krate().visit_all_item_likes(&mut OuterVisitor { tcx: tcx }.as_deep_visitor());
     tcx.sess.abort_if_errors();
 }
 
-pub(crate) fn check_body<'a, 'tcx>(
+pub(crate) fn check_match<'a, 'tcx>(
     tcx: TyCtxt<'a, 'tcx, 'tcx>,
     def_id: DefId,
-    body_id: hir::BodyId,
-) {
-    MatchVisitor {
-        tcx,
-        tables: tcx.body_tables(body_id),
-        region_scope_tree: &tcx.region_scope_tree(def_id),
-        param_env: tcx.param_env(def_id),
-        identity_substs: Substs::identity_for_item(tcx, def_id),
-    }.visit_body(tcx.hir.body(body_id));
+) -> Result<(), ErrorReported> {
+    let body_id = if let Some(id) = tcx.hir.as_local_node_id(def_id) {
+        tcx.hir.body_owned_by(id)
+    } else {
+        return Ok(());
+    };
+
+    tcx.sess.track_errors(|| {
+        MatchVisitor {
+            tcx,
+            tables: tcx.body_tables(body_id),
+            region_scope_tree: &tcx.region_scope_tree(def_id),
+            param_env: tcx.param_env(def_id),
+            identity_substs: Substs::identity_for_item(tcx, def_id),
+        }.visit_body(tcx.hir.body(body_id));
+    })
 }
 
 fn create_e0004<'a>(sess: &'a Session, sp: Span, error_message: String) -> DiagnosticBuilder<'a> {
index a987995e6e57e1ba80fae93ceed5a0642531230c..b4b12e994c8f9822387da0035dc6e8c47541799c 100644 (file)
@@ -18,7 +18,6 @@
 use rustc::hir::def_id::DefId;
 use rustc::ty::{self, Ty, TyCtxt};
 use rustc::ty::layout::LayoutOf;
-use rustc::ty::maps::Providers;
 use rustc::ty::util::IntTypeExt;
 use rustc::ty::subst::{Substs, Subst};
 use rustc::util::common::ErrorReported;
@@ -684,14 +683,7 @@ pub fn compare_lit_exprs(&self,
     }
 }
 
-pub fn provide(providers: &mut Providers) {
-    *providers = Providers {
-        const_eval,
-        ..*providers
-    };
-}
-
-fn const_eval<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
+pub(crate) fn const_eval<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
                         key: ty::ParamEnvAnd<'tcx, (DefId, &'tcx Substs<'tcx>)>)
                         -> EvalResult<'tcx> {
     let (def_id, substs) = if let Some(resolved) = lookup_const_by_id(tcx, key) {
@@ -708,14 +700,12 @@ fn const_eval<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
         let body_id = tcx.hir.body_owned_by(id);
 
         // Do match-check before building MIR
-        tcx.sess
-            .track_errors(|| super::check_match::check_body(tcx, def_id, body_id))
-            .map_err(|_| {
-                ConstEvalErr {
-                    span: tcx.def_span(key.value.0),
-                    kind: MatchCheckError,
-                }
-            })?;
+        if tcx.check_match(def_id).is_err() {
+            return Err(ConstEvalErr {
+                span: tcx.def_span(key.value.0),
+                kind: MatchCheckError,
+            });
+        }
 
         tcx.mir_const_qualif(def_id);
         tcx.hir.body(body_id)
index 7b1c33cb2710cf7fb0a63621e23e5b8749b872c2..714cead4befda35bd8d4af015e3c89c8e89275ce 100644 (file)
 
 pub use eval::*;
 
+use rustc::ty::maps::Providers;
+
+pub fn provide(providers: &mut Providers) {
+    *providers = Providers {
+        const_eval: eval::const_eval,
+        check_match: check_match::check_match,
+        ..*providers
+    };
+}
+
 // Build the diagnostics array at the end so that the metadata includes error use sites.
 __build_diagnostic_array! { librustc_const_eval, DIAGNOSTICS }