From b2fb01f23b96a6d5a0204a66998cf005edef5403 Mon Sep 17 00:00:00 2001 From: flip1995 <9744647+flip1995@users.noreply.github.com> Date: Fri, 22 Jun 2018 16:20:26 +0200 Subject: [PATCH] Use utils::opt_def_id() instead of def_id() to prevent ICE --- clippy_lints/src/fallible_impl_from.rs | 7 ++++--- tests/run-pass/ice-2865.rs | 13 +++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 tests/run-pass/ice-2865.rs diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs index 33611a90c4d..7e05712aa1a 100644 --- a/clippy_lints/src/fallible_impl_from.rs +++ b/clippy_lints/src/fallible_impl_from.rs @@ -2,7 +2,7 @@ use rustc::lint::*; 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 lint_impl_body<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, impl_span: Span, impl_it 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); diff --git a/tests/run-pass/ice-2865.rs b/tests/run-pass/ice-2865.rs new file mode 100644 index 00000000000..430de25a29d --- /dev/null +++ b/tests/run-pass/ice-2865.rs @@ -0,0 +1,13 @@ +#[allow(dead_code)] +struct Ice { + size: String +} + +impl<'a> From for Ice { + fn from(_: String) -> Self { + let text = || "iceberg".to_string(); + Self { size: text() } + } +} + +fn main() {}