From 5d0fcfbf56bb53fa70783c3d0d0251a3700b4bd5 Mon Sep 17 00:00:00 2001 From: Jacher Date: Thu, 30 May 2024 17:02:23 +0000 Subject: modify str_to_string to be machine-applicable --- clippy_lints/src/strings.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'clippy_lints/src') diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs index f8d36d6b92f..7da661485ab 100644 --- a/clippy_lints/src/strings.rs +++ b/clippy_lints/src/strings.rs @@ -399,13 +399,17 @@ impl<'tcx> LateLintPass<'tcx> for StrToString { && let ty::Ref(_, ty, ..) = ty.kind() && ty.is_str() { - span_lint_and_help( + let mut applicability = Applicability::MachineApplicable; + let snippet = snippet_with_applicability(cx, self_arg.span, "..", &mut applicability); + + span_lint_and_sugg( cx, STR_TO_STRING, expr.span, "`to_string()` called on a `&str`", - None, - "consider using `.to_owned()`", + "try", + format!("{snippet}.to_owned()"), + applicability, ); } } -- cgit 1.4.1-3-g733a5