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>,
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;
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);
}
_ => (),
}
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);
}
}
// 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> {
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;
}
}
-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) {
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)