From 273ddafac59869d35dc654be79e89b0c33b33569 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Wed, 29 Nov 2017 17:20:00 +0100 Subject: [PATCH] Fix #2188 --- clippy_lints/src/fallible_impl_from.rs | 3 ++- tests/ui/fallible_impl_from.rs | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs index 0c91d0cd97c..5b9830ad0ab 100644 --- a/clippy_lints/src/fallible_impl_from.rs +++ b/clippy_lints/src/fallible_impl_from.rs @@ -2,7 +2,7 @@ use rustc::hir; use rustc::ty; use syntax_pos::Span; -use utils::{match_def_path, method_chain_args, span_lint_and_then, walk_ptrs_ty}; +use utils::{match_def_path, method_chain_args, span_lint_and_then, walk_ptrs_ty, is_expn_of}; use utils::paths::{BEGIN_PANIC, BEGIN_PANIC_FMT, FROM_TRAIT, OPTION, RESULT}; /// **What it does:** Checks for impls of `From<..>` that contain `panic!()` or `unwrap()` @@ -66,6 +66,7 @@ fn visit_expr(&mut self, expr: &'tcx Expr) { if let ExprPath(QPath::Resolved(_, ref path)) = func_expr.node; if match_def_path(self.tcx, path.def.def_id(), &BEGIN_PANIC) || match_def_path(self.tcx, path.def.def_id(), &BEGIN_PANIC_FMT); + if is_expn_of(expr.span, "unreachable").is_none(); then { self.result.push(expr.span); } diff --git a/tests/ui/fallible_impl_from.rs b/tests/ui/fallible_impl_from.rs index eb1cd4c5e9a..db118919071 100644 --- a/tests/ui/fallible_impl_from.rs +++ b/tests/ui/fallible_impl_from.rs @@ -61,4 +61,18 @@ fn from(s: &'a mut as ProjStrTrait>::ProjString) -> Invalid { } } +struct Unreachable; + +impl From for Unreachable { + fn from(s: String) -> Unreachable { + if s.is_empty() { + return Unreachable; + } + match s.chars().next() { + Some(_) => Unreachable, + None => unreachable!(), // do not lint the unreachable macro + } + } +} + fn main() {} -- 2.44.0