@@ -25,8 +25,10 @@ use rustc::middle::expr_use_visitor::{LoanCause, MutateMode};
2525use rustc:: middle:: expr_use_visitor as euv;
2626use rustc:: middle:: mem_categorization:: { cmt} ;
2727use rustc:: hir:: pat_util:: * ;
28+ use rustc:: session:: Session ;
2829use rustc:: traits:: Reveal ;
2930use rustc:: ty:: { self , Ty , TyCtxt } ;
31+ use rustc_errors:: DiagnosticBuilder ;
3032use std:: cmp:: Ordering ;
3133use std:: fmt;
3234use std:: iter:: { FromIterator , IntoIterator , repeat} ;
@@ -163,6 +165,10 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
163165 tcx. sess . abort_if_errors ( ) ;
164166}
165167
168+ fn create_e0004 < ' a > ( sess : & ' a Session , sp : Span , error_message : String ) -> DiagnosticBuilder < ' a > {
169+ struct_span_err ! ( sess, sp, E0004 , "{}" , & error_message)
170+ }
171+
166172fn check_expr ( cx : & mut MatchCheckCtxt , ex : & hir:: Expr ) {
167173 intravisit:: walk_expr ( cx, ex) ;
168174 match ex. node {
@@ -215,9 +221,10 @@ fn check_expr(cx: &mut MatchCheckCtxt, ex: &hir::Expr) {
215221 if inlined_arms. is_empty ( ) {
216222 if !pat_ty. is_uninhabited ( cx. tcx ) {
217223 // We know the type is inhabited, so this must be wrong
218- let mut err = struct_span_err ! ( cx. tcx. sess, ex. span, E0002 ,
219- "non-exhaustive patterns: type {} is non-empty" ,
220- pat_ty) ;
224+ let mut err = create_e0004 ( cx. tcx . sess , ex. span ,
225+ format ! ( "non-exhaustive patterns: type {} \
226+ is non-empty",
227+ pat_ty) ) ;
221228 span_help ! ( & mut err, ex. span,
222229 "Please ensure that all possible cases are being handled; \
223230 possibly adding wildcards or more match arms.") ;
@@ -438,10 +445,11 @@ fn check_exhaustive<'a, 'tcx>(cx: &MatchCheckCtxt<'a, 'tcx>,
438445 1 => format ! ( "pattern {} not covered" , joined_patterns) ,
439446 _ => format ! ( "patterns {} not covered" , joined_patterns)
440447 } ;
441- struct_span_err ! ( cx. tcx. sess, sp, E0004 ,
442- "non-exhaustive patterns: {} not covered" ,
443- joined_patterns
444- ) . span_label ( sp, & label_text) . emit ( ) ;
448+ create_e0004 ( cx. tcx . sess , sp,
449+ format ! ( "non-exhaustive patterns: {} not covered" ,
450+ joined_patterns) )
451+ . span_label ( sp, & label_text)
452+ . emit ( ) ;
445453 } ,
446454 }
447455 }
0 commit comments