Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion clippy_lints/src/write/empty_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use clippy_utils::source::expand_past_previous_comma;
use clippy_utils::sym;
use rustc_ast::{FormatArgs, FormatArgsPiece};
use rustc_errors::Applicability;
use rustc_lint::LateContext;
use rustc_lint::{LateContext, LintContext};

use super::{PRINTLN_EMPTY_STRING, WRITELN_EMPTY_STRING};

Expand All @@ -17,6 +17,12 @@ pub(super) fn check(cx: &LateContext<'_>, format_args: &FormatArgs, macro_call:

WRITELN_EMPTY_STRING
} else {
let closing_paren =
cx.sess()
.source_map()
.span_extend_to_prev_char_before(macro_call.span.shrink_to_hi(), ')', false);
span = format_args.span.with_hi(closing_paren.lo());

PRINTLN_EMPTY_STRING
};

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/crashes/ice-10148.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error: empty string literal in `println!`
--> tests/ui/crashes/ice-10148.rs:8:5
|
LL | println!(with_span!(""something ""));
| ^^^^^^^^^^^^^^^^^^^^-----------^^^^^
| ^^^^^^^^^^^^^^^^^^^^---------------^
| |
| help: remove the empty string
|
Expand Down
35 changes: 35 additions & 0 deletions tests/ui/println_empty_string.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,38 @@ fn main() {
//~^ println_empty_string
}
}

#[rustfmt::skip]
fn issue_16167() {
println!();
//~^ println_empty_string
match "a" {
_ => println!(),
//~^ println_empty_string
}

eprintln!();
//~^^ println_empty_string
match "a" {
_ => eprintln!(), // tab
//~^ println_empty_string
}

//~v println_empty_string
println!(
);
match "a" {
//~v println_empty_string
_ => println!(
),
}

//~v println_empty_string
eprintln!(
);
match "a" {
//~v println_empty_string
_ => eprintln!(
),
}
}
51 changes: 51 additions & 0 deletions tests/ui/println_empty_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,54 @@ fn main() {
//~^ println_empty_string
}
}

#[rustfmt::skip]
fn issue_16167() {
println!(""/* ,,, */);
//~^ println_empty_string
match "a" {
_ => println!("" ,),
//~^ println_empty_string
}

eprintln!(""
,);
//~^^ println_empty_string
match "a" {
_ => eprintln!("" ,), // tab
//~^ println_empty_string
}

//~v println_empty_string
println!(
"\
\
" /* comment ,,,
, */ ,
);
match "a" {
//~v println_empty_string
_ => println!(
"\
\
"
//, other comment
,
),
}

//~v println_empty_string
eprintln!(
"\
\
",
);
match "a" {
//~v println_empty_string
_ => eprintln!(
"\
\
", // , comment
),
}
}
90 changes: 89 additions & 1 deletion tests/ui/println_empty_string.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,93 @@ LL | _ => eprintln!(""),
| |
| help: remove the empty string

error: aborting due to 4 previous errors
error: empty string literal in `println!`
--> tests/ui/println_empty_string.rs:25:5
|
LL | println!(""/* ,,, */);
| ^^^^^^^^^-----------^
| |
| help: remove the empty string

error: empty string literal in `println!`
--> tests/ui/println_empty_string.rs:28:14
|
LL | _ => println!("" ,),
| ^^^^^^^^^--------^
| |
| help: remove the empty string

error: empty string literal in `eprintln!`
--> tests/ui/println_empty_string.rs:32:5
|
LL | eprintln!(""
| _____^ -
| |_______________|
LL | || ,);
| ||_________-^
| |__________|
| help: remove the empty string

error: empty string literal in `eprintln!`
--> tests/ui/println_empty_string.rs:36:14
|
LL | _ => eprintln!("" ,), // tab
| ^^^^^^^^^^-------^
| |
| help: remove the empty string

error: empty string literal in `println!`
--> tests/ui/println_empty_string.rs:41:5
|
LL | / println!(
LL | |/ "\
LL | || \
LL | || " /* comment ,,,
LL | || , */ ,
LL | || );
| ||____-^
| |____|
| help: remove the empty string

error: empty string literal in `println!`
--> tests/ui/println_empty_string.rs:49:14
|
LL | _ => println!(
| _______________^
LL | |/ "\
LL | || \
LL | || "
LL | || //, other comment
LL | || ,
LL | || ),
| ||________-^
| |________|
| help: remove the empty string

error: empty string literal in `eprintln!`
--> tests/ui/println_empty_string.rs:59:5
|
LL | / eprintln!(
LL | |/ "\
LL | || \
LL | || ",
LL | || );
| ||____-^
| |____|
| help: remove the empty string

error: empty string literal in `eprintln!`
--> tests/ui/println_empty_string.rs:66:14
|
LL | _ => eprintln!(
| _______________^
LL | |/ "\
LL | || \
LL | || ", // , comment
LL | || ),
| ||________-^
| |________|
| help: remove the empty string

error: aborting due to 12 previous errors