Skip to content

Commit e5976f1

Browse files
committed
Use utils::opt_def_id() instead of def_id() to prevent ICE
1 parent 25510cf commit e5976f1

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

clippy_lints/src/fallible_impl_from.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc::lint::*;
22
use rustc::hir;
33
use rustc::ty;
44
use syntax_pos::Span;
5-
use crate::utils::{match_def_path, method_chain_args, span_lint_and_then, walk_ptrs_ty, is_expn_of};
5+
use crate::utils::{match_def_path, method_chain_args, span_lint_and_then, walk_ptrs_ty, is_expn_of, opt_def_id};
66
use crate::utils::paths::{BEGIN_PANIC, BEGIN_PANIC_FMT, FROM_TRAIT, OPTION, RESULT};
77

88
/// **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
6565
if_chain! {
6666
if let ExprCall(ref func_expr, _) = expr.node;
6767
if let ExprPath(QPath::Resolved(_, ref path)) = func_expr.node;
68-
if match_def_path(self.tcx, path.def.def_id(), &BEGIN_PANIC) ||
69-
match_def_path(self.tcx, path.def.def_id(), &BEGIN_PANIC_FMT);
68+
if let Some(path_def_id) = opt_def_id(path.def);
69+
if match_def_path(self.tcx, path_def_id, &BEGIN_PANIC) ||
70+
match_def_path(self.tcx, path_def_id, &BEGIN_PANIC_FMT);
7071
if is_expn_of(expr.span, "unreachable").is_none();
7172
then {
7273
self.result.push(expr.span);

tests/run-pass/ice-2865.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#[allow(dead_code)]
2+
struct Ice {
3+
size: String
4+
}
5+
6+
impl<'a> From<String> for Ice {
7+
fn from(_: String) -> Self {
8+
let text = || "iceberg".to_string();
9+
Self { size: text() }
10+
}
11+
}
12+
13+
fn main() {}

0 commit comments

Comments
 (0)