]> 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 7fd72cbea326732fd89ded4a9d9ab4ec5480114a..8859d545194697d4a75e70e490d07ffc0738ee41 100644 (file)
@@ -1,11 +1,12 @@
 use matches::matches;
-use rustc::hir::*;
-use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
-use rustc::{declare_lint, lint_array};
+use crate::rustc::hir::*;
+use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
+use crate::rustc::{declare_tool_lint, lint_array};
 use if_chain::if_chain;
-use rustc::ty;
+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.
 ///
@@ -119,13 +120,13 @@ fn check_for_slice<'a>(
                                  snippet(cx, idx1.span, ".."),
                                  snippet(cx, idx2.span, "..")))
                     } else {
-                        (false, "".to_owned(), "".to_owned())
+                        (false, String::new(), String::new())
                     }
                 } else if let (Some(first), Some(second)) = (Sugg::hir_opt(cx, lhs1), Sugg::hir_opt(cx, rhs1)) {
                     (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`?");
@@ -169,7 +175,7 @@ fn check_suspicious_swap(cx: &LateContext<'_, '_>, block: &Block) {
                         second.mut_addr().to_string(),
                     )
                 } else {
-                    ("".to_owned(), "".to_owned(), "".to_owned())
+                    (String::new(), String::new(), String::new())
                 };
 
                 let span = first.span.to(second.span);
@@ -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`?");
                                        }
                                    });