diff options
| author | Ada Alakbarova <ada.alakbarova@proton.me> | 2025-08-21 23:34:48 +0200 |
|---|---|---|
| committer | Ada Alakbarova <ada.alakbarova@proton.me> | 2025-08-22 15:03:15 +0200 |
| commit | f0420110fedcbc5a34ec2ffeab6ef1238e171b88 (patch) | |
| tree | be814d3539f020e5e9f91b3888b3372f8c2f15fd | |
| parent | 81b4de649fd7795b99cdf6a77f0b5c49cfc778b3 (diff) | |
| download | rust-f0420110fedcbc5a34ec2ffeab6ef1238e171b88.tar.gz rust-f0420110fedcbc5a34ec2ffeab6ef1238e171b88.zip | |
useless_conversion: store name in a var
| -rw-r--r-- | clippy_lints/src/useless_conversion.rs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/clippy_lints/src/useless_conversion.rs b/clippy_lints/src/useless_conversion.rs index e5b20c0e0a1..df0789db559 100644 --- a/clippy_lints/src/useless_conversion.rs +++ b/clippy_lints/src/useless_conversion.rs @@ -386,12 +386,13 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { ExprKind::Call(path, [arg]) => { if let ExprKind::Path(ref qpath) = path.kind - && let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id() && !is_ty_alias(qpath) + && let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id() + && let Some(name) = cx.tcx.get_diagnostic_name(def_id) { let a = cx.typeck_results().expr_ty(e); let b = cx.typeck_results().expr_ty(arg); - if cx.tcx.is_diagnostic_item(sym::try_from_fn, def_id) + if name == sym::try_from_fn && is_type_diagnostic_item(cx, a, sym::Result) && let ty::Adt(_, args) = a.kind() && let Some(a_type) = args.types().next() @@ -408,7 +409,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion { ); } - if cx.tcx.is_diagnostic_item(sym::from_fn, def_id) && same_type_and_consts(a, b) { + if name == sym::from_fn && same_type_and_consts(a, b) { let mut app = Applicability::MachineApplicable; let sugg = Sugg::hir_with_context(cx, arg, e.span.ctxt(), "<expr>", &mut app).maybe_paren(); let sugg_msg = format!("consider removing `{}()`", snippet(cx, path.span, "From::from")); |
