Skip to content

Commit

Permalink
Add auto-fixable println!() suggestion
Browse files Browse the repository at this point in the history
Fixes #2319
  • Loading branch information
killercup committed Jan 4, 2018
1 parent ca3d6dd commit 82d91c5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 9 additions & 3 deletions clippy_lints/src/print.rs
Expand Up @@ -5,7 +5,7 @@ use rustc::lint::*;
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
Expand Down Expand Up @@ -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(),
);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/println_empty_string.stderr
@@ -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`

0 comments on commit 82d91c5

Please sign in to comment.