Auto merge of #46033 - sinkuu:const-enum-match-check, r=arielb1

Do match-check for consts

Fixes #43195 (ICE caused by building MIR that contains non-exausitive match)
This commit is contained in:
bors 2017-11-26 04:26:19 +00:00
commit 2f84fb5cc1
10 changed files with 109 additions and 29 deletions

View file

@ -516,6 +516,7 @@ define_dep_nodes!( <'tcx>
[] UsedTraitImports(DefId),
[] HasTypeckTables(DefId),
[] ConstEval { param_env: ParamEnvAnd<'tcx, (DefId, &'tcx Substs<'tcx>)> },
[] CheckMatch(DefId),
[] SymbolName(DefId),
[] InstanceSymbolName { instance: Instance<'tcx> },
[] SpecializationGraph(DefId),

View file

@ -371,7 +371,8 @@ for ::middle::const_val::ErrKind<'gcx> {
MiscBinaryOp |
MiscCatchAll |
IndexOpFeatureGated |
TypeckError => {
TypeckError |
CheckMatchError => {
// nothing to do
}
UnimplementedConstVal(s) => {

View file

@ -106,7 +106,8 @@ pub enum ErrKind<'tcx> {
ErroneousReferencedConstant(Box<ConstEvalErr<'tcx>>),
TypeckError
TypeckError,
CheckMatchError,
}
impl<'tcx> From<ConstMathErr> for ErrKind<'tcx> {
@ -168,6 +169,7 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> {
ErroneousReferencedConstant(_) => simple!("could not evaluate referenced constant"),
TypeckError => simple!("type-checking failed"),
CheckMatchError => simple!("match-checking failed"),
}
}
@ -212,8 +214,9 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> {
primary_span: Span,
primary_kind: &str)
{
if let ErrKind::TypeckError = self.kind {
return;
match self.kind {
ErrKind::TypeckError | ErrKind::CheckMatchError => return,
_ => {}
}
self.struct_error(tcx, primary_span, primary_kind).emit();
}

View file

@ -37,7 +37,7 @@ use ty::{self, CrateInherentImpls, Ty, TyCtxt};
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;
@ -205,6 +205,9 @@ define_maps! { <'tcx>
[] 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>,

View file

@ -800,6 +800,7 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
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!()); }

View file

@ -477,6 +477,7 @@ impl<'a, 'tcx> Lift<'tcx> for const_val::ErrKind<'a> {
}
TypeckError => TypeckError,
CheckMatchError => CheckMatchError,
})
}
}