]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/utils/sugg.rs
Use span_suggestion_with_applicability instead of span_suggestion
[rust.git] / clippy_lints / src / utils / sugg.rs
index 4239b24d8172643f65c145c727c92db9a9dad84c..f7d8c1fc15122526660cdbe2b7b124d680ce630a 100644 (file)
@@ -2,19 +2,20 @@
 #![deny(clippy::missing_docs_in_private_items)]
 
 use matches::matches;
-use rustc::hir;
-use rustc::lint::{EarlyContext, LateContext, LintContext};
-use rustc_errors;
+use crate::rustc::hir;
+use crate::rustc::lint::{EarlyContext, LateContext, LintContext};
+use crate::rustc_errors;
 use std::borrow::Cow;
 use std::fmt::Display;
 use std;
-use syntax::source_map::{CharPos, Span};
-use syntax::parse::token;
-use syntax::print::pprust::token_to_string;
-use syntax::util::parser::AssocOp;
-use syntax::ast;
+use crate::syntax::source_map::{CharPos, Span};
+use crate::syntax::parse::token;
+use crate::syntax::print::pprust::token_to_string;
+use crate::syntax::util::parser::AssocOp;
+use crate::syntax::ast;
 use crate::utils::{higher, snippet, snippet_opt};
-use syntax_pos::{BytePos, Pos};
+use crate::syntax_pos::{BytePos, Pos};
+use crate::rustc_errors::Applicability;
 
 /// A helper type to build suggestion correctly handling parenthesis.
 pub enum Sugg<'a> {
@@ -86,7 +87,7 @@ pub fn hir(cx: &LateContext<'_, '_>, expr: &hir::Expr, default: &'a str) -> Self
 
     /// Prepare a suggestion from an expression.
     pub fn ast(cx: &EarlyContext<'_>, expr: &ast::Expr, default: &'a str) -> Self {
-        use syntax::ast::RangeLimits;
+        use crate::syntax::ast::RangeLimits;
 
         let snippet = snippet(cx, expr.span, default);
 
@@ -175,6 +176,7 @@ pub fn mut_addr_deref(self) -> Sugg<'static> {
 
     /// Convenience method to create the `<lhs>..<rhs>` or `<lhs>...<rhs>`
     /// suggestion.
+    #[allow(dead_code)]
     pub fn range(self, end: &Self, limit: ast::RangeLimits) -> Sugg<'static> {
         match limit {
             ast::RangeLimits::HalfOpen => make_assoc(AssocOp::DotDot, &self, end),
@@ -359,7 +361,7 @@ enum Associativity {
 /// they are considered
 /// associative.
 fn associativity(op: &AssocOp) -> Associativity {
-    use syntax::util::parser::AssocOp::*;
+    use crate::syntax::util::parser::AssocOp::*;
 
     match *op {
         ObsoleteInPlace | Assign | AssignOp(_) => Associativity::Right,
@@ -381,7 +383,7 @@ fn associativity(op: &AssocOp) -> Associativity {
 
 /// Convert a `hir::BinOp` to the corresponding assigning binary operator.
 fn hirbinop2assignop(op: hir::BinOp) -> AssocOp {
-    use syntax::parse::token::BinOpToken::*;
+    use crate::syntax::parse::token::BinOpToken::*;
 
     AssocOp::AssignOp(match op.node {
         hir::BinOpKind::Add => Plus,
@@ -409,8 +411,8 @@ fn hirbinop2assignop(op: hir::BinOp) -> AssocOp {
 
 /// Convert an `ast::BinOp` to the corresponding assigning binary operator.
 fn astbinop2assignop(op: ast::BinOp) -> AssocOp {
-    use syntax::ast::BinOpKind::*;
-    use syntax::parse::token::BinOpToken;
+    use crate::syntax::ast::BinOpKind::*;
+    use crate::syntax::parse::token::BinOpToken;
 
     AssocOp::AssignOp(match op.node {
         Add => BinOpToken::Plus,
@@ -495,7 +497,12 @@ fn suggest_item_with_attr<D: Display + ?Sized>(&mut self, cx: &T, item: Span, ms
         if let Some(indent) = indentation(cx, item) {
             let span = item.with_hi(item.lo());
 
-            self.span_suggestion(span, msg, format!("{}\n{}", attr, indent));
+            self.span_suggestion_with_applicability(
+                        span,
+                        msg,
+                        format!("{}\n{}", attr, indent),
+                        Applicability::Unspecified,
+                        );
         }
     }
 
@@ -516,7 +523,12 @@ fn suggest_prepend_item(&mut self, cx: &T, item: Span, msg: &str, new_item: &str
                 })
                 .collect::<String>();
 
-            self.span_suggestion(span, msg, format!("{}\n{}", new_item, indent));
+            self.span_suggestion_with_applicability(
+                        span,
+                        msg,
+                        format!("{}\n{}", new_item, indent),
+                        Applicability::Unspecified,
+                        );
         }
     }
 
@@ -533,6 +545,11 @@ fn suggest_remove_item(&mut self, cx: &T, item: Span, msg: &str) {
             }
         }
 
-        self.span_suggestion(remove_span, msg, String::new());
+        self.span_suggestion_with_applicability(
+                    remove_span,
+                    msg,
+                    String::new(),
+                    Applicability::Unspecified,
+                    );
     }
 }