@@ -17,6 +17,7 @@ use rustc::middle::const_val::ConstVal;
1717use :: { eval_const_expr, eval_const_expr_partial, compare_const_vals} ;
1818use :: { const_expr_to_pat, lookup_const_by_id} ;
1919use :: EvalHint :: ExprTypeChecked ;
20+ use eval:: report_const_eval_err;
2021use rustc:: hir:: def:: * ;
2122use rustc:: hir:: def_id:: { DefId } ;
2223use rustc:: middle:: expr_use_visitor:: { ConsumeMode , Delegate , ExprUseVisitor } ;
@@ -42,6 +43,7 @@ use syntax_pos::{Span, DUMMY_SP};
4243use rustc:: hir:: fold:: { Folder , noop_fold_pat} ;
4344use rustc:: hir:: print:: pat_to_string;
4445use syntax:: ptr:: P ;
46+ use rustc:: util:: common:: ErrorReported ;
4547use rustc:: util:: nodemap:: FnvHashMap ;
4648
4749pub const DUMMY_WILD_PAT : & ' static Pat = & Pat {
@@ -279,13 +281,7 @@ fn check_for_static_nan(cx: &MatchCheckCtxt, pat: &Pat) {
279281 Ok ( _) => { }
280282
281283 Err ( err) => {
282- let mut diag = struct_span_err ! ( cx. tcx. sess, err. span, E0471 ,
283- "constant evaluation error: {}" ,
284- err. description( ) ) ;
285- if !p. span . contains ( err. span ) {
286- diag. span_note ( p. span , "in pattern here" ) ;
287- }
288- diag. emit ( ) ;
284+ report_const_eval_err ( cx. tcx , & err, p. span , "pattern" ) . emit ( ) ;
289285 }
290286 }
291287 }
@@ -838,22 +834,19 @@ pub fn constructor_arity(_cx: &MatchCheckCtxt, ctor: &Constructor, ty: Ty) -> us
838834 }
839835}
840836
841- fn range_covered_by_constructor ( ctor : & Constructor ,
842- from : & ConstVal , to : & ConstVal ) -> Option < bool > {
837+ fn range_covered_by_constructor ( tcx : TyCtxt , span : Span ,
838+ ctor : & Constructor ,
839+ from : & ConstVal , to : & ConstVal )
840+ -> Result < bool , ErrorReported > {
843841 let ( c_from, c_to) = match * ctor {
844842 ConstantValue ( ref value) => ( value, value) ,
845843 ConstantRange ( ref from, ref to) => ( from, to) ,
846- Single => return Some ( true ) ,
844+ Single => return Ok ( true ) ,
847845 _ => bug ! ( )
848846 } ;
849- let cmp_from = compare_const_vals ( c_from, from) ;
850- let cmp_to = compare_const_vals ( c_to, to) ;
851- match ( cmp_from, cmp_to) {
852- ( Some ( cmp_from) , Some ( cmp_to) ) => {
853- Some ( cmp_from != Ordering :: Less && cmp_to != Ordering :: Greater )
854- }
855- _ => None
856- }
847+ let cmp_from = compare_const_vals ( tcx, span, c_from, from) ?;
848+ let cmp_to = compare_const_vals ( tcx, span, c_to, to) ?;
849+ Ok ( cmp_from != Ordering :: Less && cmp_to != Ordering :: Greater )
857850}
858851
859852fn wrap_pat < ' a , ' b , ' tcx > ( cx : & MatchCheckCtxt < ' b , ' tcx > ,
@@ -965,27 +958,25 @@ pub fn specialize<'a, 'b, 'tcx>(
965958 Some ( vec ! [ ( pat, Some ( mt. ty) ) ] )
966959 } else {
967960 let expr_value = eval_const_expr ( cx. tcx , & expr) ;
968- match range_covered_by_constructor ( constructor, & expr_value, & expr_value) {
969- Some ( true ) => Some ( vec ! [ ] ) ,
970- Some ( false ) => None ,
971- None => {
972- span_err ! ( cx. tcx. sess, pat_span, E0298 , "mismatched types between arms" ) ;
973- None
974- }
961+ match range_covered_by_constructor (
962+ cx. tcx , expr. span , constructor, & expr_value, & expr_value
963+ ) {
964+ Ok ( true ) => Some ( vec ! [ ] ) ,
965+ Ok ( false ) => None ,
966+ Err ( ErrorReported ) => None ,
975967 }
976968 }
977969 }
978970
979971 PatKind :: Range ( ref from, ref to) => {
980972 let from_value = eval_const_expr ( cx. tcx , & from) ;
981973 let to_value = eval_const_expr ( cx. tcx , & to) ;
982- match range_covered_by_constructor ( constructor, & from_value, & to_value) {
983- Some ( true ) => Some ( vec ! [ ] ) ,
984- Some ( false ) => None ,
985- None => {
986- span_err ! ( cx. tcx. sess, pat_span, E0299 , "mismatched types between arms" ) ;
987- None
988- }
974+ match range_covered_by_constructor (
975+ cx. tcx , pat_span, constructor, & from_value, & to_value
976+ ) {
977+ Ok ( true ) => Some ( vec ! [ ] ) ,
978+ Ok ( false ) => None ,
979+ Err ( ErrorReported ) => None ,
989980 }
990981 }
991982
0 commit comments