Skip to content

Commit 5ba61ed

Browse files
committed
Disable unreachable patterns error entirely
1 parent 44a70f0 commit 5ba61ed

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

src/librustc_const_eval/check_match.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc::session::Session;
2626
use rustc::traits::Reveal;
2727
use rustc::ty::{self, Ty, TyCtxt};
2828
use rustc::lint;
29-
use rustc_errors::DiagnosticBuilder;
29+
use rustc_errors::{Diagnostic, Level, DiagnosticBuilder};
3030

3131
use rustc::hir::def::*;
3232
use rustc::hir::intravisit::{self, Visitor, FnKind, NestedVisitorMap};
@@ -313,19 +313,16 @@ fn check_arms<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
313313
},
314314

315315
hir::MatchSource::Normal => {
316-
// if we had a catchall pattern, raise an error.
317-
// Otherwise an unreachable pattern raises a warning.
316+
let mut diagnostic = Diagnostic::new(Level::Warning,
317+
"unreachable pattern");
318+
diagnostic.set_span(pat.span);
319+
// if we had a catchall pattern, hint at that
318320
if let Some(catchall) = catchall {
319-
let mut err = struct_span_err!(cx.tcx.sess, pat.span, E0001,
320-
"unreachable pattern");
321-
err.span_label(pat.span, &"this is an unreachable pattern");
322-
err.span_note(catchall, "this pattern matches any value");
323-
err.emit();
324-
} else {
325-
cx.tcx.sess.add_lint(lint::builtin::UNREACHABLE_PATTERNS,
326-
hir_pat.id, pat.span,
327-
String::from("unreachable pattern"));
321+
diagnostic.span_label(pat.span, &"this is an unreachable pattern");
322+
diagnostic.span_note(catchall, "this pattern matches any value");
328323
}
324+
cx.tcx.sess.add_lint_diagnostic(lint::builtin::UNREACHABLE_PATTERNS,
325+
hir_pat.id, diagnostic);
329326
},
330327

331328
hir::MatchSource::TryDesugar => {

src/test/compile-fail/issue-14221.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![deny(unreachable_patterns)]
12+
#![allow(unused_variables)]
13+
#![allow(non_snake_case)]
14+
1115
pub enum E {
1216
A,
1317
B,

src/test/compile-fail/issue-30302.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![allow(dead_code)]
12+
#![allow(unused_variables)]
13+
#![allow(non_snake_case)]
14+
#![deny(unreachable_patterns)]
15+
1116
enum Stack<T> {
1217
Nil,
1318
Cons(T, Box<Stack<T>>)

src/test/compile-fail/issue-31221.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,15 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![allow(dead_code)]
12+
#![allow(unused_variables)]
13+
#![allow(non_snake_case)]
1114
#![deny(unreachable_patterns)]
15+
//~^ NOTE lint level defined here
16+
//~^^ NOTE lint level defined here
17+
//~^^^ NOTE lint level defined here
1218

19+
#[derive(Clone, Copy)]
1320
enum Enum {
1421
Var1,
1522
Var2,

0 commit comments

Comments
 (0)