Merge pull request #2867 from flip1995/ice-2865

Use utils::opt_def_id() instead of def_id() to prevent ICE
This commit is contained in:
Philipp Krones 2018-06-25 23:00:58 +02:00 committed by GitHub
commit 3626d86eef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 3 deletions

View File

@ -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);

View File

@ -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() {}