Use utils::opt_def_id() instead of def_id() to prevent ICE
This commit is contained in:
parent
9f8624e5bf
commit
b2fb01f23b
2 changed files with 17 additions and 3 deletions
|
@ -2,7 +2,7 @@ use rustc::lint::*;
|
||||||
use rustc::hir;
|
use rustc::hir;
|
||||||
use rustc::ty;
|
use rustc::ty;
|
||||||
use syntax_pos::Span;
|
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};
|
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()`
|
/// **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_chain! {
|
||||||
if let ExprCall(ref func_expr, _) = expr.node;
|
if let ExprCall(ref func_expr, _) = expr.node;
|
||||||
if let ExprPath(QPath::Resolved(_, ref path)) = func_expr.node;
|
if let ExprPath(QPath::Resolved(_, ref path)) = func_expr.node;
|
||||||
if match_def_path(self.tcx, path.def.def_id(), &BEGIN_PANIC) ||
|
if let Some(path_def_id) = opt_def_id(path.def);
|
||||||
match_def_path(self.tcx, path.def.def_id(), &BEGIN_PANIC_FMT);
|
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();
|
if is_expn_of(expr.span, "unreachable").is_none();
|
||||||
then {
|
then {
|
||||||
self.result.push(expr.span);
|
self.result.push(expr.span);
|
||||||
|
|
13
tests/run-pass/ice-2865.rs
Normal file
13
tests/run-pass/ice-2865.rs
Normal 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() {}
|
Loading…
Add table
Reference in a new issue