X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=clippy_lints%2Fsrc%2Fto_string_in_display.rs;h=4fb297ac6c6990771cc9ef935f76b2225901ed60;hb=5491c802c2f6b71070268310644577dd00726fa9;hp=c53727ba160046861e6d446e428482f5b0986837;hpb=9009f8f0319fb0f1a9ef712e6f379c2bfda2d101;p=rust.git diff --git a/clippy_lints/src/to_string_in_display.rs b/clippy_lints/src/to_string_in_display.rs index c53727ba160..4fb297ac6c6 100644 --- a/clippy_lints/src/to_string_in_display.rs +++ b/clippy_lints/src/to_string_in_display.rs @@ -1,9 +1,10 @@ -use crate::utils::{match_def_path, match_trait_method, paths, qpath_res, span_lint}; +use clippy_utils::diagnostics::span_lint; +use clippy_utils::{is_diag_trait_item, match_def_path, path_to_local_id, paths}; use if_chain::if_chain; -use rustc_hir::def::Res; use rustc_hir::{Expr, ExprKind, HirId, Impl, ImplItem, ImplItemKind, Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; +use rustc_span::symbol::sym; declare_clippy_lint! { /// **What it does:** Checks for uses of `to_string()` in `Display` traits. @@ -89,14 +90,13 @@ fn check_impl_item(&mut self, cx: &LateContext<'_>, impl_item: &ImplItem<'_>) { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { if_chain! { - if let ExprKind::MethodCall(ref path, _, args, _) = expr.kind; - if path.ident.name == sym!(to_string); - if match_trait_method(cx, expr, &paths::TO_STRING); if self.in_display_impl; - if let ExprKind::Path(ref qpath) = args[0].kind; - if let Res::Local(hir_id) = qpath_res(cx, qpath, args[0].hir_id); if let Some(self_hir_id) = self.self_hir_id; - if hir_id == self_hir_id; + if let ExprKind::MethodCall(path, _, args, _) = expr.kind; + if path.ident.name == sym!(to_string); + if let Some(expr_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id); + if is_diag_trait_item(cx, expr_def_id, sym::ToString); + if path_to_local_id(&args[0], self_hir_id); then { span_lint( cx,