]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/fallible_impl_from.rs
Rustup
[rust.git] / clippy_lints / src / fallible_impl_from.rs
index 33611a90c4d453e56c08ef8e2e846571352a4892..64cdc05b44de33fc9e978fb597885878f49de23d 100644 (file)
@@ -2,7 +2,7 @@
 use rustc::hir;
 use rustc::ty;
 use syntax_pos::Span;
-use crate::utils::{match_def_path, method_chain_args, span_lint_and_then, walk_ptrs_ty, is_expn_of};
+use crate::utils::{match_def_path, method_chain_args, span_lint_and_then, walk_ptrs_ty, is_expn_of, opt_def_id};
 use crate::utils::paths::{BEGIN_PANIC, BEGIN_PANIC_FMT, FROM_TRAIT, OPTION, RESULT};
 
 /// **What it does:** Checks for impls of `From<..>` that contain `panic!()` or `unwrap()`
@@ -65,8 +65,9 @@ fn visit_expr(&mut self, expr: &'tcx Expr) {
             if_chain! {
                 if let ExprCall(ref func_expr, _) = expr.node;
                 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 let Some(path_def_id) = opt_def_id(path.def);
+                if match_def_path(self.tcx, path_def_id, &BEGIN_PANIC) ||
+                    match_def_path(self.tcx, path_def_id, &BEGIN_PANIC_FMT);
                 if is_expn_of(expr.span, "unreachable").is_none();
                 then {
                     self.result.push(expr.span);
@@ -92,7 +93,7 @@ fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
 
     for impl_item in impl_items {
         if_chain! {
-            if impl_item.name == "from";
+            if impl_item.ident.name == "from";
             if let ImplItemKind::Method(_, body_id) =
                 cx.tcx.hir.impl_item(impl_item.id).node;
             then {