Skip to content

Commit 0af387c

Browse files
committed
Querify
1 parent efa7b12 commit 0af387c

File tree

6 files changed

+53
-37
lines changed

6 files changed

+53
-37
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ define_dep_nodes!( <'tcx>
516516
[] UsedTraitImports(DefId),
517517
[] HasTypeckTables(DefId),
518518
[] ConstEval { param_env: ParamEnvAnd<'tcx, (DefId, &'tcx Substs<'tcx>)> },
519+
[] CheckMatch(DefId),
519520
[] SymbolName(DefId),
520521
[] InstanceSymbolName { instance: Instance<'tcx> },
521522
[] SpecializationGraph(DefId),

src/librustc/ty/maps/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use ty::{self, CrateInherentImpls, Ty, TyCtxt};
3737
use ty::steal::Steal;
3838
use ty::subst::Substs;
3939
use util::nodemap::{DefIdSet, DefIdMap, ItemLocalSet};
40-
use util::common::{profq_msg, ProfileQueriesMsg};
40+
use util::common::{profq_msg, ErrorReported, ProfileQueriesMsg};
4141

4242
use rustc_data_structures::indexed_set::IdxSetBuf;
4343
use rustc_back::PanicStrategy;
@@ -205,6 +205,9 @@ define_maps! { <'tcx>
205205
[] fn const_eval: const_eval_dep_node(ty::ParamEnvAnd<'tcx, (DefId, &'tcx Substs<'tcx>)>)
206206
-> const_val::EvalResult<'tcx>,
207207

208+
[] fn check_match: CheckMatch(DefId)
209+
-> Result<(), ErrorReported>,
210+
208211
/// Performs the privacy check and computes "access levels".
209212
[] fn privacy_access_levels: PrivacyAccessLevels(CrateNum) -> Rc<AccessLevels>,
210213

src/librustc/ty/maps/plumbing.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,7 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
800800
DepKind::SpecializationGraph => { force!(specialization_graph_of, def_id!()); }
801801
DepKind::ObjectSafety => { force!(is_object_safe, def_id!()); }
802802
DepKind::TraitImpls => { force!(trait_impls_of, def_id!()); }
803+
DepKind::CheckMatch => { force!(check_match, def_id!()); }
803804

804805
DepKind::ParamEnv => { force!(param_env, def_id!()); }
805806
DepKind::DescribeDef => { force!(describe_def, def_id!()); }

src/librustc_const_eval/check_match.rs

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use rustc::ty::{self, Ty, TyCtxt};
2424
use rustc::ty::subst::Substs;
2525
use rustc::lint;
2626
use rustc_errors::DiagnosticBuilder;
27+
use rustc::util::common::ErrorReported;
2728

2829
use rustc::hir::def::*;
2930
use rustc::hir::def_id::DefId;
@@ -47,17 +48,14 @@ impl<'a, 'tcx> Visitor<'tcx> for OuterVisitor<'a, 'tcx> {
4748
b: hir::BodyId, s: Span, id: ast::NodeId) {
4849
intravisit::walk_fn(self, fk, fd, b, s, id);
4950

50-
let def_id = self.tcx.hir.local_def_id(id);
51-
52-
check_body(self.tcx, def_id, b);
51+
check_body(self.tcx, b);
5352
}
5453

5554
fn visit_item(&mut self, item: &'tcx hir::Item) {
5655
intravisit::walk_item(self, item);
5756
match item.node {
5857
hir::ItemStatic(.., body_id) | hir::ItemConst(.., body_id) => {
59-
let def_id = self.tcx.hir.local_def_id(item.id);
60-
check_body(self.tcx, def_id, body_id);
58+
check_body(self.tcx, body_id);
6159
}
6260
_ => (),
6361
}
@@ -66,40 +64,53 @@ impl<'a, 'tcx> Visitor<'tcx> for OuterVisitor<'a, 'tcx> {
6664
fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem) {
6765
intravisit::walk_impl_item(self, ii);
6866
if let hir::ImplItemKind::Const(_, body_id) = ii.node {
69-
let def_id = self.tcx.hir.local_def_id(ii.id);
70-
check_body(self.tcx, def_id, body_id);
67+
check_body(self.tcx, body_id);
7168
}
7269
}
7370

7471
fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem) {
7572
intravisit::walk_trait_item(self, ti);
7673
if let hir::TraitItemKind::Const(_, Some(body_id)) = ti.node {
77-
let def_id = self.tcx.hir.local_def_id(ti.id);
78-
check_body(self.tcx, def_id, body_id);
74+
check_body(self.tcx, body_id);
7975
}
8076
}
8177

8278
// Enum variants and types (e.g. `[T; { .. }]`) may have bodies too,
8379
// but they are const-evaluated during typeck.
8480
}
8581

82+
fn check_body<'a, 'tcx>(
83+
tcx: TyCtxt<'a, 'tcx, 'tcx>,
84+
body_id: hir::BodyId,
85+
) {
86+
let def_id = tcx.hir.body_owner_def_id(body_id);
87+
let _ = tcx.check_match(def_id);
88+
}
89+
8690
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
8791
tcx.hir.krate().visit_all_item_likes(&mut OuterVisitor { tcx: tcx }.as_deep_visitor());
8892
tcx.sess.abort_if_errors();
8993
}
9094

91-
pub(crate) fn check_body<'a, 'tcx>(
95+
pub(crate) fn check_match<'a, 'tcx>(
9296
tcx: TyCtxt<'a, 'tcx, 'tcx>,
9397
def_id: DefId,
94-
body_id: hir::BodyId,
95-
) {
96-
MatchVisitor {
97-
tcx,
98-
tables: tcx.body_tables(body_id),
99-
region_scope_tree: &tcx.region_scope_tree(def_id),
100-
param_env: tcx.param_env(def_id),
101-
identity_substs: Substs::identity_for_item(tcx, def_id),
102-
}.visit_body(tcx.hir.body(body_id));
98+
) -> Result<(), ErrorReported> {
99+
let body_id = if let Some(id) = tcx.hir.as_local_node_id(def_id) {
100+
tcx.hir.body_owned_by(id)
101+
} else {
102+
return Ok(());
103+
};
104+
105+
tcx.sess.track_errors(|| {
106+
MatchVisitor {
107+
tcx,
108+
tables: tcx.body_tables(body_id),
109+
region_scope_tree: &tcx.region_scope_tree(def_id),
110+
param_env: tcx.param_env(def_id),
111+
identity_substs: Substs::identity_for_item(tcx, def_id),
112+
}.visit_body(tcx.hir.body(body_id));
113+
})
103114
}
104115

105116
fn create_e0004<'a>(sess: &'a Session, sp: Span, error_message: String) -> DiagnosticBuilder<'a> {

src/librustc_const_eval/eval.rs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use rustc::hir::def::{Def, CtorKind};
1818
use rustc::hir::def_id::DefId;
1919
use rustc::ty::{self, Ty, TyCtxt};
2020
use rustc::ty::layout::LayoutOf;
21-
use rustc::ty::maps::Providers;
2221
use rustc::ty::util::IntTypeExt;
2322
use rustc::ty::subst::{Substs, Subst};
2423
use rustc::util::common::ErrorReported;
@@ -684,14 +683,7 @@ impl<'a, 'tcx> ConstContext<'a, 'tcx> {
684683
}
685684
}
686685

687-
pub fn provide(providers: &mut Providers) {
688-
*providers = Providers {
689-
const_eval,
690-
..*providers
691-
};
692-
}
693-
694-
fn const_eval<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
686+
pub(crate) fn const_eval<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
695687
key: ty::ParamEnvAnd<'tcx, (DefId, &'tcx Substs<'tcx>)>)
696688
-> EvalResult<'tcx> {
697689
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>,
708700
let body_id = tcx.hir.body_owned_by(id);
709701

710702
// Do match-check before building MIR
711-
tcx.sess
712-
.track_errors(|| super::check_match::check_body(tcx, def_id, body_id))
713-
.map_err(|_| {
714-
ConstEvalErr {
715-
span: tcx.def_span(key.value.0),
716-
kind: MatchCheckError,
717-
}
718-
})?;
703+
if tcx.check_match(def_id).is_err() {
704+
return Err(ConstEvalErr {
705+
span: tcx.def_span(key.value.0),
706+
kind: MatchCheckError,
707+
});
708+
}
719709

720710
tcx.mir_const_qualif(def_id);
721711
tcx.hir.body(body_id)

src/librustc_const_eval/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,15 @@ pub mod pattern;
4848

4949
pub use eval::*;
5050

51+
use rustc::ty::maps::Providers;
52+
53+
pub fn provide(providers: &mut Providers) {
54+
*providers = Providers {
55+
const_eval: eval::const_eval,
56+
check_match: check_match::check_match,
57+
..*providers
58+
};
59+
}
60+
5161
// Build the diagnostics array at the end so that the metadata includes error use sites.
5262
__build_diagnostic_array! { librustc_const_eval, DIAGNOSTICS }

0 commit comments

Comments
 (0)