Skip to content

Commit 1473101

Browse files
committed
Do match-check before const MIR generation
1 parent d602c2e commit 1473101

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

src/librustc/ich/impls_ty.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,8 @@ for ::middle::const_val::ErrKind<'gcx> {
371371
MiscBinaryOp |
372372
MiscCatchAll |
373373
IndexOpFeatureGated |
374-
TypeckError => {
374+
TypeckError |
375+
MatchCheckError => {
375376
// nothing to do
376377
}
377378
UnimplementedConstVal(s) => {

src/librustc/middle/const_val.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ pub enum ErrKind<'tcx> {
106106

107107
ErroneousReferencedConstant(Box<ConstEvalErr<'tcx>>),
108108

109-
TypeckError
109+
TypeckError,
110+
MatchCheckError,
110111
}
111112

112113
impl<'tcx> From<ConstMathErr> for ErrKind<'tcx> {
@@ -168,6 +169,7 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> {
168169
ErroneousReferencedConstant(_) => simple!("could not evaluate referenced constant"),
169170

170171
TypeckError => simple!("type-checking failed"),
172+
MatchCheckError => simple!("match-checking failed"),
171173
}
172174
}
173175

@@ -212,8 +214,9 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> {
212214
primary_span: Span,
213215
primary_kind: &str)
214216
{
215-
if let ErrKind::TypeckError = self.kind {
216-
return;
217+
match self.kind {
218+
ErrKind::TypeckError | ErrKind::MatchCheckError => return,
219+
_ => {}
217220
}
218221
self.struct_error(tcx, primary_span, primary_kind).emit();
219222
}

src/librustc/ty/structural_impls.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ impl<'a, 'tcx> Lift<'tcx> for const_val::ErrKind<'a> {
477477
}
478478

479479
TypeckError => TypeckError,
480+
MatchCheckError => MatchCheckError,
480481
})
481482
}
482483
}

src/librustc_const_eval/eval.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,8 +705,20 @@ fn const_eval<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
705705

706706
let tables = tcx.typeck_tables_of(def_id);
707707
let body = if let Some(id) = tcx.hir.as_local_node_id(def_id) {
708+
let body_id = tcx.hir.body_owned_by(id);
709+
710+
// 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+
})?;
719+
708720
tcx.mir_const_qualif(def_id);
709-
tcx.hir.body(tcx.hir.body_owned_by(id))
721+
tcx.hir.body(body_id)
710722
} else {
711723
tcx.extern_const_body(def_id).body
712724
};

0 commit comments

Comments
 (0)