about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2016-10-02 15:45:06 +0200
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2016-10-02 15:45:06 +0200
commitcb22364f3225293bd3e3f7d398cb81f3d1c5e1d7 (patch)
tree866fe631829052fe1ae56f5082d8bb958e54f804
parentfe36876ce144e6f30fa6d0d5647e54ade812b169 (diff)
downloadrust-cb22364f3225293bd3e3f7d398cb81f3d1c5e1d7.tar.gz
rust-cb22364f3225293bd3e3f7d398cb81f3d1c5e1d7.zip
Merge E0002 into E0004
-rw-r--r--src/librustc_const_eval/check_match.rs22
-rw-r--r--src/test/compile-fail/E0004-2.rs (renamed from src/test/compile-fail/E0002.rs)2
2 files changed, 16 insertions, 8 deletions
diff --git a/src/librustc_const_eval/check_match.rs b/src/librustc_const_eval/check_match.rs
index 5178ef65cf6..dd1f313f9af 100644
--- a/src/librustc_const_eval/check_match.rs
+++ b/src/librustc_const_eval/check_match.rs
@@ -25,8 +25,10 @@ use rustc::middle::expr_use_visitor::{LoanCause, MutateMode};
 use rustc::middle::expr_use_visitor as euv;
 use rustc::middle::mem_categorization::{cmt};
 use rustc::hir::pat_util::*;
+use rustc::session::Session;
 use rustc::traits::Reveal;
 use rustc::ty::{self, Ty, TyCtxt};
+use rustc_errors::DiagnosticBuilder;
 use std::cmp::Ordering;
 use std::fmt;
 use std::iter::{FromIterator, IntoIterator, repeat};
@@ -163,6 +165,10 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
     tcx.sess.abort_if_errors();
 }
 
+fn create_e0004<'a>(sess: &'a Session, sp: Span, error_message: String) -> DiagnosticBuilder<'a> {
+    struct_span_err!(sess, sp, E0004, "{}", &error_message)
+}
+
 fn check_expr(cx: &mut MatchCheckCtxt, ex: &hir::Expr) {
     intravisit::walk_expr(cx, ex);
     match ex.node {
@@ -215,9 +221,10 @@ fn check_expr(cx: &mut MatchCheckCtxt, ex: &hir::Expr) {
             if inlined_arms.is_empty() {
                 if !pat_ty.is_uninhabited(cx.tcx) {
                     // We know the type is inhabited, so this must be wrong
-                    let mut err = struct_span_err!(cx.tcx.sess, ex.span, E0002,
-                                                   "non-exhaustive patterns: type {} is non-empty",
-                                                   pat_ty);
+                    let mut err = create_e0004(cx.tcx.sess, ex.span,
+                                               format!("non-exhaustive patterns: type {} \
+                                                        is non-empty",
+                                                       pat_ty));
                     span_help!(&mut err, ex.span,
                         "Please ensure that all possible cases are being handled; \
                          possibly adding wildcards or more match arms.");
@@ -438,10 +445,11 @@ fn check_exhaustive<'a, 'tcx>(cx: &MatchCheckCtxt<'a, 'tcx>,
                         1 => format!("pattern {} not covered", joined_patterns),
                         _ => format!("patterns {} not covered", joined_patterns)
                     };
-                    struct_span_err!(cx.tcx.sess, sp, E0004,
-                        "non-exhaustive patterns: {} not covered",
-                        joined_patterns
-                    ).span_label(sp, &label_text).emit();
+                    create_e0004(cx.tcx.sess, sp,
+                                 format!("non-exhaustive patterns: {} not covered",
+                                         joined_patterns))
+                        .span_label(sp, &label_text)
+                        .emit();
                 },
             }
         }
diff --git a/src/test/compile-fail/E0002.rs b/src/test/compile-fail/E0004-2.rs
index 0e94c9595d8..824b86cfa83 100644
--- a/src/test/compile-fail/E0002.rs
+++ b/src/test/compile-fail/E0004-2.rs
@@ -11,5 +11,5 @@
 fn main() {
     let x = Some(1);
 
-    match x { } //~ ERROR E0002
+    match x { } //~ ERROR E0004
 }