]> git.lizzy.rs Git - rust.git/commitdiff
Add auto-fixable `println!()` suggestion
authorPascal Hertleif <killercup@gmail.com>
Thu, 4 Jan 2018 11:37:47 +0000 (12:37 +0100)
committerPascal Hertleif <killercup@gmail.com>
Thu, 4 Jan 2018 11:46:26 +0000 (12:46 +0100)
Fixes #2319

clippy_lints/src/print.rs
tests/ui/println_empty_string.stderr

index 61ed8d5ac2503c0e8725d10f1182758a68408ffb..451b27033ea326664b306f66e800af2e26df72f6 100644 (file)
@@ -5,7 +5,7 @@
 use syntax::ast::LitKind;
 use syntax::symbol::InternedString;
 use syntax_pos::Span;
-use utils::{is_expn_of, match_def_path, match_path, resolve_node, span_lint};
+use utils::{is_expn_of, match_def_path, match_path, resolve_node, span_lint, span_lint_and_sugg};
 use utils::{opt_def_id, paths};
 
 /// **What it does:** This lint warns when you using `println!("")` to
@@ -182,8 +182,14 @@ fn check_println<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, span: Span, fmtstr: Inter
         if let Ok(snippet) = cx.sess().codemap().span_to_snippet(span);
         if snippet.contains("\"\"");
         then {
-            span_lint(cx, PRINT_WITH_NEWLINE, span,
-                      "using `println!(\"\")`, consider using `println!()` instead");
+            span_lint_and_sugg(
+                cx,
+                PRINT_WITH_NEWLINE,
+                span,
+                "using `println!(\"\")`",
+                "replace it with",
+                "println!()".to_string(),
+            );
          }
     }
 }
index 8beca8b88cb314d9852a471ad21735c17daa8e62..2036d7d976bff26198c9b8b857d7928a66a8bb15 100644 (file)
@@ -1,8 +1,8 @@
-error: using `println!("")`, consider using `println!()` instead
+error: using `println!("")`
  --> $DIR/println_empty_string.rs:3:5
   |
 3 |     println!("");
-  |     ^^^^^^^^^^^^^
+  |     ^^^^^^^^^^^^^ help: replace it with: `println!()`
   |
   = note: `-D print-with-newline` implied by `-D warnings`