From 5ba61edbd038edebb9e3f61a14cd4777ecc399be Mon Sep 17 00:00:00 2001 From: Andrew Cann Date: Mon, 12 Dec 2016 00:01:12 +0800 Subject: [PATCH] Disable unreachable patterns error entirely --- src/librustc_const_eval/check_match.rs | 21 +++++++++------------ src/test/compile-fail/issue-14221.rs | 4 ++++ src/test/compile-fail/issue-30302.rs | 5 +++++ 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 c3a033f4aa79..4b79cd7695ed 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 e79be99a346f..d11fe99c07f6 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 26508a472242..01150ff13740 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 { Nil, Cons(T, Box>) diff --git a/src/test/compile-fail/issue-31221.rs b/src/test/compile-fail/issue-31221.rs index 8cf6725cec45..e2b80215caf6 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,