diff options
| author | Andrew Cann <shum@canndrew.org> | 2016-12-12 00:01:12 +0800 |
|---|---|---|
| committer | Andrew Cann <shum@canndrew.org> | 2017-01-03 15:48:29 +0800 |
| commit | 5ba61edbd038edebb9e3f61a14cd4777ecc399be (patch) | |
| tree | de2d12c6652a587704f0d3791932f2a4faf8837f | |
| parent | 44a70f0221819f3db2c845baf555835d9532f29f (diff) | |
Disable unreachable patterns error entirely
| -rw-r--r-- | src/librustc_const_eval/check_match.rs | 21 | ||||
| -rw-r--r-- | src/test/compile-fail/issue-14221.rs | 4 | ||||
| -rw-r--r-- | src/test/compile-fail/issue-30302.rs | 5 | ||||
| -rw-r--r-- | src/test/compile-fail/issue-31221.rs | 7 |
4 files changed, 25 insertions, 12 deletions
diff --git a/src/librustc_const_eval/check_match.rs b/src/librustc_const_eval/check_match.rs index c3a033f4aa7..4b79cd7695e 100644 --- a/src/librustc_const_eval/check_match.rs +++ b/src/librustc_const_eval/check_match.rs @@ -26,7 +26,7 @@ use rustc::session::Session; use rustc::traits::Reveal; use rustc::ty::{self, Ty, TyCtxt}; use rustc::lint; -use rustc_errors::DiagnosticBuilder; +use rustc_errors::{Diagnostic, Level, DiagnosticBuilder}; use rustc::hir::def::*; use rustc::hir::intravisit::{self, Visitor, FnKind, NestedVisitorMap}; @@ -313,19 +313,16 @@ fn check_arms<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>, }, hir::MatchSource::Normal => { - // if we had a catchall pattern, raise an error. - // Otherwise an unreachable pattern raises a warning. + let mut diagnostic = Diagnostic::new(Level::Warning, + "unreachable pattern"); + diagnostic.set_span(pat.span); + // if we had a catchall pattern, hint at that if let Some(catchall) = catchall { - let mut err = struct_span_err!(cx.tcx.sess, pat.span, E0001, - "unreachable pattern"); - err.span_label(pat.span, &"this is an unreachable pattern"); - err.span_note(catchall, "this pattern matches any value"); - err.emit(); - } else { - cx.tcx.sess.add_lint(lint::builtin::UNREACHABLE_PATTERNS, - hir_pat.id, pat.span, - String::from("unreachable pattern")); + diagnostic.span_label(pat.span, &"this is an unreachable pattern"); + diagnostic.span_note(catchall, "this pattern matches any value"); } + cx.tcx.sess.add_lint_diagnostic(lint::builtin::UNREACHABLE_PATTERNS, + hir_pat.id, diagnostic); }, hir::MatchSource::TryDesugar => { diff --git a/src/test/compile-fail/issue-14221.rs b/src/test/compile-fail/issue-14221.rs index e79be99a346..d11fe99c07f 100644 --- a/src/test/compile-fail/issue-14221.rs +++ b/src/test/compile-fail/issue-14221.rs @@ -8,6 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![deny(unreachable_patterns)] +#![allow(unused_variables)] +#![allow(non_snake_case)] + pub enum E { A, B, diff --git a/src/test/compile-fail/issue-30302.rs b/src/test/compile-fail/issue-30302.rs index 26508a47224..01150ff1374 100644 --- a/src/test/compile-fail/issue-30302.rs +++ b/src/test/compile-fail/issue-30302.rs @@ -8,6 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![allow(dead_code)] +#![allow(unused_variables)] +#![allow(non_snake_case)] +#![deny(unreachable_patterns)] + enum Stack<T> { Nil, Cons(T, Box<Stack<T>>) diff --git a/src/test/compile-fail/issue-31221.rs b/src/test/compile-fail/issue-31221.rs index 8cf6725cec4..e2b80215caf 100644 --- a/src/test/compile-fail/issue-31221.rs +++ b/src/test/compile-fail/issue-31221.rs @@ -8,8 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![allow(dead_code)] +#![allow(unused_variables)] +#![allow(non_snake_case)] #![deny(unreachable_patterns)] +//~^ NOTE lint level defined here +//~^^ NOTE lint level defined here +//~^^^ NOTE lint level defined here +#[derive(Clone, Copy)] enum Enum { Var1, Var2, |
