@@ -25,8 +25,10 @@ use rustc::middle::expr_use_visitor::{LoanCause, MutateMode};
25
25
use rustc:: middle:: expr_use_visitor as euv;
26
26
use rustc:: middle:: mem_categorization:: { cmt} ;
27
27
use rustc:: hir:: pat_util:: * ;
28
+ use rustc:: session:: Session ;
28
29
use rustc:: traits:: Reveal ;
29
30
use rustc:: ty:: { self , Ty , TyCtxt } ;
31
+ use rustc_errors:: DiagnosticBuilder ;
30
32
use std:: cmp:: Ordering ;
31
33
use std:: fmt;
32
34
use std:: iter:: { FromIterator , IntoIterator , repeat} ;
@@ -163,6 +165,10 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
163
165
tcx. sess . abort_if_errors ( ) ;
164
166
}
165
167
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
+
166
172
fn check_expr ( cx : & mut MatchCheckCtxt , ex : & hir:: Expr ) {
167
173
intravisit:: walk_expr ( cx, ex) ;
168
174
match ex. node {
@@ -215,9 +221,10 @@ fn check_expr(cx: &mut MatchCheckCtxt, ex: &hir::Expr) {
215
221
if inlined_arms. is_empty ( ) {
216
222
if !pat_ty. is_uninhabited ( cx. tcx ) {
217
223
// 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) ) ;
221
228
span_help ! ( & mut err, ex. span,
222
229
"Please ensure that all possible cases are being handled; \
223
230
possibly adding wildcards or more match arms.") ;
@@ -438,10 +445,11 @@ fn check_exhaustive<'a, 'tcx>(cx: &MatchCheckCtxt<'a, 'tcx>,
438
445
1 => format ! ( "pattern {} not covered" , joined_patterns) ,
439
446
_ => format ! ( "patterns {} not covered" , joined_patterns)
440
447
} ;
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 ( ) ;
445
453
} ,
446
454
}
447
455
}
0 commit comments