diff options
| author | Shotaro Yamada <sinkuu@sinkuu.xyz> | 2017-11-16 21:11:28 +0900 |
|---|---|---|
| committer | Shotaro Yamada <sinkuu@sinkuu.xyz> | 2017-11-24 13:00:56 +0900 |
| commit | 1473101123ddc919794a56b49d6366570d01bedc (patch) | |
| tree | cedaf47bc8339325511c83102d5b52ee93646d84 | |
| parent | d602c2efffafeda612f6192db1a44e113186db3e (diff) | |
| download | rust-1473101123ddc919794a56b49d6366570d01bedc.tar.gz rust-1473101123ddc919794a56b49d6366570d01bedc.zip | |
Do match-check before const MIR generation
| -rw-r--r-- | src/librustc/ich/impls_ty.rs | 3 | ||||
| -rw-r--r-- | src/librustc/middle/const_val.rs | 9 | ||||
| -rw-r--r-- | src/librustc/ty/structural_impls.rs | 1 | ||||
| -rw-r--r-- | src/librustc_const_eval/eval.rs | 14 |
4 files changed, 22 insertions, 5 deletions
diff --git a/src/librustc/ich/impls_ty.rs b/src/librustc/ich/impls_ty.rs index 45e80b58a4f..9ff4d53e09a 100644 --- a/src/librustc/ich/impls_ty.rs +++ b/src/librustc/ich/impls_ty.rs @@ -371,7 +371,8 @@ for ::middle::const_val::ErrKind<'gcx> { MiscBinaryOp | MiscCatchAll | IndexOpFeatureGated | - TypeckError => { + TypeckError | + MatchCheckError => { // nothing to do } UnimplementedConstVal(s) => { diff --git a/src/librustc/middle/const_val.rs b/src/librustc/middle/const_val.rs index 7b239980467..f7870bd8e24 100644 --- a/src/librustc/middle/const_val.rs +++ b/src/librustc/middle/const_val.rs @@ -106,7 +106,8 @@ pub enum ErrKind<'tcx> { ErroneousReferencedConstant(Box<ConstEvalErr<'tcx>>), - TypeckError + TypeckError, + MatchCheckError, } 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"), + MatchCheckError => 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::MatchCheckError => return, + _ => {} } self.struct_error(tcx, primary_span, primary_kind).emit(); } diff --git a/src/librustc/ty/structural_impls.rs b/src/librustc/ty/structural_impls.rs index 83207fbe3c3..0e3870c58e5 100644 --- a/src/librustc/ty/structural_impls.rs +++ b/src/librustc/ty/structural_impls.rs @@ -477,6 +477,7 @@ impl<'a, 'tcx> Lift<'tcx> for const_val::ErrKind<'a> { } TypeckError => TypeckError, + MatchCheckError => MatchCheckError, }) } } diff --git a/src/librustc_const_eval/eval.rs b/src/librustc_const_eval/eval.rs index a548c1df16e..a987995e6e5 100644 --- a/src/librustc_const_eval/eval.rs +++ b/src/librustc_const_eval/eval.rs @@ -705,8 +705,20 @@ fn const_eval<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let tables = tcx.typeck_tables_of(def_id); let body = if let Some(id) = tcx.hir.as_local_node_id(def_id) { + 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, + } + })?; + tcx.mir_const_qualif(def_id); - tcx.hir.body(tcx.hir.body_owned_by(id)) + tcx.hir.body(body_id) } else { tcx.extern_const_body(def_id).body }; |
