Skip to content

Commit f042011

Browse files
committed
useless_conversion: store name in a var
1 parent 81b4de6 commit f042011

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

clippy_lints/src/useless_conversion.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,12 +386,13 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
386386

387387
ExprKind::Call(path, [arg]) => {
388388
if let ExprKind::Path(ref qpath) = path.kind
389-
&& let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id()
390389
&& !is_ty_alias(qpath)
390+
&& let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id()
391+
&& let Some(name) = cx.tcx.get_diagnostic_name(def_id)
391392
{
392393
let a = cx.typeck_results().expr_ty(e);
393394
let b = cx.typeck_results().expr_ty(arg);
394-
if cx.tcx.is_diagnostic_item(sym::try_from_fn, def_id)
395+
if name == sym::try_from_fn
395396
&& is_type_diagnostic_item(cx, a, sym::Result)
396397
&& let ty::Adt(_, args) = a.kind()
397398
&& let Some(a_type) = args.types().next()
@@ -408,7 +409,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
408409
);
409410
}
410411

411-
if cx.tcx.is_diagnostic_item(sym::from_fn, def_id) && same_type_and_consts(a, b) {
412+
if name == sym::from_fn && same_type_and_consts(a, b) {
412413
let mut app = Applicability::MachineApplicable;
413414
let sugg = Sugg::hir_with_context(cx, arg, e.span.ctxt(), "<expr>", &mut app).maybe_paren();
414415
let sugg_msg = format!("consider removing `{}()`", snippet(cx, path.span, "From::from"));

0 commit comments

Comments
 (0)