]> git.lizzy.rs Git - rust.git/commitdiff
Fix #2188
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Wed, 29 Nov 2017 16:20:00 +0000 (17:20 +0100)
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Wed, 29 Nov 2017 16:20:00 +0000 (17:20 +0100)
clippy_lints/src/fallible_impl_from.rs
tests/ui/fallible_impl_from.rs

index 0c91d0cd97c92b104146b15a6c28f18414f88995..5b9830ad0ab8b0e76ad753d238fa7490e17854cf 100644 (file)
@@ -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);
                 }
index eb1cd4c5e9ada59413ed5b4302c0df870d585802..db11891907130fa01c980e1b2f1629e781b84116 100644 (file)
@@ -61,4 +61,18 @@ fn from(s: &'a mut <Box<u32> as ProjStrTrait>::ProjString) -> Invalid {
     }
 }
 
+struct Unreachable;
+
+impl From<String> 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() {}