]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/collapsible_if.rs
Merge commit '4911ab124c481430672a3833b37075e6435ec34d' into clippyup
[rust.git] / clippy_lints / src / collapsible_if.rs
index aaaa3eb1f6e42e4745c5814a85e53c20c60e3fdf..42bff564de03d471b49264bee9da3daaa691cb19 100644 (file)
@@ -13,9 +13,9 @@
 //! This lint is **warn** by default
 
 use if_chain::if_chain;
-use rustc::lint::{EarlyContext, EarlyLintPass};
+use rustc_ast::ast;
+use rustc_lint::{EarlyContext, EarlyLintPass};
 use rustc_session::{declare_lint_pass, declare_tool_lint};
-use syntax::ast;
 
 use crate::utils::sugg::Sugg;
 use crate::utils::{snippet_block, snippet_block_with_applicability, span_lint_and_sugg, span_lint_and_then};
@@ -95,7 +95,7 @@ fn check_if(cx: &EarlyContext<'_>, expr: &ast::Expr) {
 
 fn block_starts_with_comment(cx: &EarlyContext<'_>, expr: &ast::Block) -> bool {
     // We trim all opening braces and whitespaces and then check if the next string is a comment.
-    let trimmed_block_text = snippet_block(cx, expr.span, "..")
+    let trimmed_block_text = snippet_block(cx, expr.span, "..", None)
         .trim_start_matches(|c: char| c.is_whitespace() || c == '{')
         .to_owned();
     trimmed_block_text.starts_with("//") || trimmed_block_text.starts_with("/*")
@@ -115,8 +115,8 @@ fn check_collapsible_maybe_if_let(cx: &EarlyContext<'_>, else_: &ast::Expr) {
                 COLLAPSIBLE_IF,
                 block.span,
                 "this `else { if .. }` block can be collapsed",
-                "try",
-                snippet_block_with_applicability(cx, else_.span, "..", &mut applicability).into_owned(),
+                "collapse nested if block",
+                snippet_block_with_applicability(cx, else_.span, "..", Some(block.span), &mut applicability).into_owned(),
                 applicability,
             );
         }
@@ -137,16 +137,16 @@ fn check_collapsible_no_if_let(cx: &EarlyContext<'_>, expr: &ast::Expr, check: &
             if expr.span.ctxt() != inner.span.ctxt() {
                 return;
             }
-            span_lint_and_then(cx, COLLAPSIBLE_IF, expr.span, "this `if` statement can be collapsed", |db| {
+            span_lint_and_then(cx, COLLAPSIBLE_IF, expr.span, "this `if` statement can be collapsed", |diag| {
                 let lhs = Sugg::ast(cx, check, "..");
                 let rhs = Sugg::ast(cx, check_inner, "..");
-                db.span_suggestion(
+                diag.span_suggestion(
                     expr.span,
-                    "try",
+                    "collapse nested if block",
                     format!(
                         "if {} {}",
                         lhs.and(&rhs),
-                        snippet_block(cx, content.span, ".."),
+                        snippet_block(cx, content.span, "..", Some(expr.span)),
                     ),
                     Applicability::MachineApplicable, // snippet
                 );