Skip to content

Commit cb22364

Browse files
Merge E0002 into E0004
1 parent fe36876 commit cb22364

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/librustc_const_eval/check_match.rs

+15-7
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ use rustc::middle::expr_use_visitor::{LoanCause, MutateMode};
2525
use rustc::middle::expr_use_visitor as euv;
2626
use rustc::middle::mem_categorization::{cmt};
2727
use rustc::hir::pat_util::*;
28+
use rustc::session::Session;
2829
use rustc::traits::Reveal;
2930
use rustc::ty::{self, Ty, TyCtxt};
31+
use rustc_errors::DiagnosticBuilder;
3032
use std::cmp::Ordering;
3133
use std::fmt;
3234
use 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+
166172
fn 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
}

src/test/compile-fail/E0002.rs src/test/compile-fail/E0004-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
fn main() {
1212
let x = Some(1);
1313

14-
match x { } //~ ERROR E0002
14+
match x { } //~ ERROR E0004
1515
}

0 commit comments

Comments
 (0)