mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-15 09:27:25 +00:00
commit
486dc5c070
6 changed files with 26 additions and 12 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -28,5 +28,6 @@ util/gh-pages/lints.json
|
|||
*.rs.bk
|
||||
|
||||
helper.txt
|
||||
|
||||
*.iml
|
||||
.vscode
|
||||
.idea
|
||||
|
|
|
@ -12,7 +12,7 @@ use url::Url;
|
|||
///
|
||||
/// **Why is this bad?** *Rustdoc* supports markdown formatting, `_`, `::` and
|
||||
/// camel-case probably indicates some code which should be included between
|
||||
/// ticks. `_` can also be used for empasis in markdown, this lint tries to
|
||||
/// ticks. `_` can also be used for emphasis in markdown, this lint tries to
|
||||
/// consider that.
|
||||
///
|
||||
/// **Known problems:** Lots of bad docs won’t be fixed, what the lint checks
|
||||
|
|
|
@ -230,11 +230,11 @@ fn check_write_variants<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr,
|
|||
"using `write!()` with a format string that ends in a \
|
||||
newline, consider using `writeln!()` instead");
|
||||
},
|
||||
"writeln" => if has_empty_arg(cx, span, fmtstr, fmtlen) {
|
||||
"writeln" => if let Some(final_span) = has_empty_arg(cx, span, fmtstr, fmtlen) {
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
WRITE_WITH_NEWLINE,
|
||||
span,
|
||||
final_span,
|
||||
"using `writeln!(v, \"\")`",
|
||||
"replace it with",
|
||||
"writeln!(v)".to_string(),
|
||||
|
@ -295,11 +295,11 @@ fn check_print_variants<'a, 'tcx>(
|
|||
newline, consider using `println!()` instead");
|
||||
},
|
||||
"println" =>
|
||||
if has_empty_arg(cx, span, fmtstr, fmtlen) {
|
||||
if let Some(final_span) = has_empty_arg(cx, span, fmtstr, fmtlen) {
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
PRINT_WITH_NEWLINE,
|
||||
span,
|
||||
final_span,
|
||||
"using `println!(\"\")`",
|
||||
"replace it with",
|
||||
"println!()".to_string(),
|
||||
|
@ -390,7 +390,7 @@ fn has_newline_end(args: &HirVec<Expr>, fmtstr: InternedString, fmtlen: usize) -
|
|||
}
|
||||
|
||||
/// Check for writeln!(v, "") / println!("")
|
||||
fn has_empty_arg<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, span: Span, fmtstr: InternedString, fmtlen: usize) -> bool {
|
||||
fn has_empty_arg<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, span: Span, fmtstr: InternedString, fmtlen: usize) -> Option<Span> {
|
||||
if_chain! {
|
||||
// check that the string is empty
|
||||
if fmtlen == 1;
|
||||
|
@ -400,10 +400,13 @@ fn has_empty_arg<'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 {
|
||||
return true
|
||||
if snippet.ends_with(';') {
|
||||
return Some(cx.sess().codemap().span_until_char(span, ';'));
|
||||
}
|
||||
return Some(span)
|
||||
}
|
||||
}
|
||||
false
|
||||
None
|
||||
}
|
||||
|
||||
/// Returns the slice of format string parts in an `Arguments::new_v1` call.
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
fn main() {
|
||||
println!();
|
||||
println!("");
|
||||
|
||||
match "a" {
|
||||
_ => println!(""),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,9 +2,15 @@ error: using `println!("")`
|
|||
--> $DIR/println_empty_string.rs:3:5
|
||||
|
|
||||
3 | println!("");
|
||||
| ^^^^^^^^^^^^^ help: replace it with: `println!()`
|
||||
| ^^^^^^^^^^^^ help: replace it with: `println!()`
|
||||
|
|
||||
= note: `-D print-with-newline` implied by `-D warnings`
|
||||
|
||||
error: aborting due to previous error
|
||||
error: using `println!("")`
|
||||
--> $DIR/println_empty_string.rs:6:14
|
||||
|
|
||||
6 | _ => println!(""),
|
||||
| ^^^^^^^^^^^^ help: replace it with: `println!()`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ error: using `writeln!(v, "")`
|
|||
--> $DIR/writeln_empty_string.rs:9:5
|
||||
|
|
||||
9 | writeln!(&mut v, "");
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `writeln!(v)`
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: replace it with: `writeln!(v)`
|
||||
|
|
||||
= note: `-D write-with-newline` implied by `-D warnings`
|
||||
|
||||
|
|
Loading…
Reference in a new issue