Skip to content

Commit

Permalink
Merge pull request #2867 from flip1995/ice-2865
Browse files Browse the repository at this point in the history
Use utils::opt_def_id() instead of def_id() to prevent ICE
  • Loading branch information
flip1995 authored Jun 25, 2018
2 parents 9f8624e + b2fb01f commit 3626d86
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
7 changes: 4 additions & 3 deletions clippy_lints/src/fallible_impl_from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()`
Expand Down Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions tests/run-pass/ice-2865.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#[allow(dead_code)]
struct Ice {
size: String
}

impl<'a> From<String> for Ice {
fn from(_: String) -> Self {
let text = || "iceberg".to_string();
Self { size: text() }
}
}

fn main() {}

0 comments on commit 3626d86

Please sign in to comment.