about summary refs log tree commit diff
path: root/clippy_lints/src/strings.rs
diff options
context:
space:
mode:
authorxFrednet <xFrednet@gmail.com>2024-07-22 20:32:27 +0200
committerxFrednet <xFrednet@gmail.com>2024-07-27 13:45:00 +0200
commit7de9c2014596c1cda2c9bcf04252545d42d53334 (patch)
tree034318ab9330347b407f66a8f7f9c4a7a3f2df40 /clippy_lints/src/strings.rs
parent1ec502569e5b085e91f4df9509e4c6199f50e89e (diff)
Make restriction lint's use `span_lint_and_then` (q -> s)
Diffstat (limited to 'clippy_lints/src/strings.rs')
-rw-r--r--clippy_lints/src/strings.rs23
1 files changed, 12 insertions, 11 deletions
diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs
index 7da661485ab..cfc387886dc 100644
--- a/clippy_lints/src/strings.rs
+++ b/clippy_lints/src/strings.rs
@@ -1,4 +1,4 @@
-use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_sugg};
+use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_then};
 use clippy_utils::source::{snippet, snippet_with_applicability};
 use clippy_utils::ty::is_type_lang_item;
 use clippy_utils::{
@@ -399,17 +399,16 @@ impl<'tcx> LateLintPass<'tcx> for StrToString {
             && let ty::Ref(_, ty, ..) = ty.kind()
             && ty.is_str()
         {
-            let mut applicability = Applicability::MachineApplicable;
-            let snippet = snippet_with_applicability(cx, self_arg.span, "..", &mut applicability);
-
-            span_lint_and_sugg(
+            span_lint_and_then(
                 cx,
                 STR_TO_STRING,
                 expr.span,
                 "`to_string()` called on a `&str`",
-                "try",
-                format!("{snippet}.to_owned()"),
-                applicability,
+                |diag| {
+                    let mut applicability = Applicability::MachineApplicable;
+                    let snippet = snippet_with_applicability(cx, self_arg.span, "..", &mut applicability);
+                    diag.span_suggestion(expr.span, "try", format!("{snippet}.to_owned()"), applicability);
+                },
             );
         }
     }
@@ -455,13 +454,15 @@ impl<'tcx> LateLintPass<'tcx> for StringToString {
             && let ty = cx.typeck_results().expr_ty(self_arg)
             && is_type_lang_item(cx, ty, LangItem::String)
         {
-            span_lint_and_help(
+            #[expect(clippy::collapsible_span_lint_calls, reason = "rust-clippy#7797")]
+            span_lint_and_then(
                 cx,
                 STRING_TO_STRING,
                 expr.span,
                 "`to_string()` called on a `String`",
-                None,
-                "consider using `.clone()`",
+                |diag| {
+                    diag.help("consider using `.clone()`");
+                },
             );
         }
     }