Skip to content

Commit 29c6093

Browse files
authored
Merge pull request #2324 from killercup/feature/2319-suggest-empty-println
Add auto-fixable `println!()` suggestion
2 parents ca3d6dd + 82d91c5 commit 29c6093

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

clippy_lints/src/print.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc::lint::*;
55
use syntax::ast::LitKind;
66
use syntax::symbol::InternedString;
77
use syntax_pos::Span;
8-
use utils::{is_expn_of, match_def_path, match_path, resolve_node, span_lint};
8+
use utils::{is_expn_of, match_def_path, match_path, resolve_node, span_lint, span_lint_and_sugg};
99
use utils::{opt_def_id, paths};
1010

1111
/// **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
182182
if let Ok(snippet) = cx.sess().codemap().span_to_snippet(span);
183183
if snippet.contains("\"\"");
184184
then {
185-
span_lint(cx, PRINT_WITH_NEWLINE, span,
186-
"using `println!(\"\")`, consider using `println!()` instead");
185+
span_lint_and_sugg(
186+
cx,
187+
PRINT_WITH_NEWLINE,
188+
span,
189+
"using `println!(\"\")`",
190+
"replace it with",
191+
"println!()".to_string(),
192+
);
187193
}
188194
}
189195
}

tests/ui/println_empty_string.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: using `println!("")`, consider using `println!()` instead
1+
error: using `println!("")`
22
--> $DIR/println_empty_string.rs:3:5
33
|
44
3 | println!("");
5-
| ^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^ help: replace it with: `println!()`
66
|
77
= note: `-D print-with-newline` implied by `-D warnings`
88

0 commit comments

Comments
 (0)