]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/swap.rs
Use span_suggestion_with_applicability instead of span_suggestion
[rust.git] / clippy_lints / src / swap.rs
index c6668288a556ee307f46e3350af9f6c668c2e955..8859d545194697d4a75e70e490d07ffc0738ee41 100644 (file)
@@ -6,6 +6,7 @@
 use crate::rustc::ty;
 use crate::utils::{differing_macro_contexts, match_type, paths, snippet, span_lint_and_then, walk_ptrs_ty, SpanlessEq};
 use crate::utils::sugg::Sugg;
+use crate::rustc_errors::Applicability;
 
 /// **What it does:** Checks for manual swapping.
 ///
@@ -125,7 +126,7 @@ fn check_for_slice<'a>(
                     (true, format!(" `{}` and `{}`", first, second),
                         format!("std::mem::swap({}, {})", first.mut_addr(), second.mut_addr()))
                 } else {
-                    (true, "".to_owned(), "".to_owned())
+                    (true, String::new(), String::new())
                 };
 
                 let span = w[0].span.to(second.span);
@@ -136,7 +137,12 @@ fn check_for_slice<'a>(
                                    &format!("this looks like you are swapping{} manually", what),
                                    |db| {
                                        if !sugg.is_empty() {
-                                           db.span_suggestion(span, "try", sugg);
+                                           db.span_suggestion_with_applicability(
+                                                        span,
+                                                        "try",
+                                                        sugg,
+                                                        Applicability::Unspecified,
+                                                        );
 
                                            if replace {
                                                db.note("or maybe you should use `std::mem::replace`?");
@@ -180,8 +186,14 @@ fn check_suspicious_swap(cx: &LateContext<'_, '_>, block: &Block) {
                                    &format!("this looks like you are trying to swap{}", what),
                                    |db| {
                                        if !what.is_empty() {
-                                           db.span_suggestion(span, "try",
-                                                              format!("std::mem::swap({}, {})", lhs, rhs));
+                                           db.span_suggestion_with_applicability(
+                                                              span,
+                                                              "try",
+                                                              format!("std::mem::swap({}, {})",
+                                                                    lhs,
+                                                                    rhs),
+                                                              Applicability::Unspecified,
+                                                              );
                                            db.note("or maybe you should use `std::mem::replace`?");
                                        }
                                    });