diff options
| author | Jacher <jwc2002@outlook.com> | 2024-05-30 17:02:23 +0000 |
|---|---|---|
| committer | Jacher <jwc2002@outlook.com> | 2024-06-01 09:05:27 +0000 |
| commit | 5d0fcfbf56bb53fa70783c3d0d0251a3700b4bd5 (patch) | |
| tree | 80d69ccd74426b4d82fced153049e86270619df8 /clippy_lints/src/strings.rs | |
| parent | e7efe4381af5ae065105f6fa8c30ae86e01d3d9a (diff) | |
modify str_to_string to be machine-applicable
Diffstat (limited to 'clippy_lints/src/strings.rs')
| -rw-r--r-- | clippy_lints/src/strings.rs | 10 |
1 files changed, 7 insertions, 3 deletions
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, ); } } |
