mirror of https://github.com/rust-lang/rust.git
Merge pull request #2324 from killercup/feature/2319-suggest-empty-println
Add auto-fixable `println!()` suggestion
This commit is contained in:
commit
29c6093ef0
|
@ -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(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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`
|
||||
|
||||
|
|
Loading…
Reference in New Issue