Merge pull request #2324 from killercup/feature/2319-suggest-empty-println

Add auto-fixable `println!()` suggestion
This commit is contained in:
Manish Goregaokar 2018-01-04 12:08:54 +00:00 committed by GitHub
commit 29c6093ef0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View File

@ -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
@ -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(),
);
}
}
}

View 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`