2020-12-20 10:19:49 -06:00
|
|
|
#![allow(clippy::print_literal)]
|
|
|
|
#![warn(clippy::print_with_newline)]
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
eprint!("Hello\n");
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: using `eprint!()` with a format string that ends in a single newline
|
|
|
|
//~| NOTE: `-D clippy::print-with-newline` implied by `-D warnings`
|
2020-12-20 10:19:49 -06:00
|
|
|
eprint!("Hello {}\n", "world");
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: using `eprint!()` with a format string that ends in a single newline
|
2020-12-20 10:19:49 -06:00
|
|
|
eprint!("Hello {} {}\n", "world", "#2");
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: using `eprint!()` with a format string that ends in a single newline
|
2020-12-20 10:19:49 -06:00
|
|
|
eprint!("{}\n", 1265);
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: using `eprint!()` with a format string that ends in a single newline
|
2020-12-20 10:19:49 -06:00
|
|
|
eprint!("\n");
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: using `eprint!()` with a format string that ends in a single newline
|
2020-12-20 10:19:49 -06:00
|
|
|
|
|
|
|
// these are all fine
|
|
|
|
eprint!("");
|
|
|
|
eprint!("Hello");
|
|
|
|
eprintln!("Hello");
|
|
|
|
eprintln!("Hello\n");
|
|
|
|
eprintln!("Hello {}\n", "world");
|
|
|
|
eprint!("Issue\n{}", 1265);
|
|
|
|
eprint!("{}", 1265);
|
|
|
|
eprint!("\n{}", 1275);
|
|
|
|
eprint!("\n\n");
|
|
|
|
eprint!("like eof\n\n");
|
|
|
|
eprint!("Hello {} {}\n\n", "world", "#2");
|
2023-08-24 14:32:12 -05:00
|
|
|
// #3126
|
|
|
|
eprintln!("\ndon't\nwarn\nfor\nmultiple\nnewlines\n");
|
|
|
|
// #3126
|
|
|
|
eprintln!("\nbla\n\n");
|
2020-12-20 10:19:49 -06:00
|
|
|
|
|
|
|
// Escaping
|
2023-08-24 14:32:12 -05:00
|
|
|
// #3514
|
|
|
|
eprint!("\\n");
|
|
|
|
eprint!("\\\n");
|
|
|
|
//~^ ERROR: using `eprint!()` with a format string that ends in a single newline
|
2020-12-20 10:19:49 -06:00
|
|
|
eprint!("\\\\n");
|
|
|
|
|
|
|
|
// Raw strings
|
2023-08-24 14:32:12 -05:00
|
|
|
// #3778
|
|
|
|
eprint!(r"\n");
|
2020-12-20 10:19:49 -06:00
|
|
|
|
|
|
|
// Literal newlines should also fail
|
|
|
|
eprint!(
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: using `eprint!()` with a format string that ends in a single newline
|
2020-12-20 10:19:49 -06:00
|
|
|
"
|
|
|
|
"
|
|
|
|
);
|
|
|
|
eprint!(
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: using `eprint!()` with a format string that ends in a single newline
|
2020-12-20 10:19:49 -06:00
|
|
|
r"
|
|
|
|
"
|
|
|
|
);
|
|
|
|
|
|
|
|
// Don't warn on CRLF (#4208)
|
|
|
|
eprint!("\r\n");
|
|
|
|
eprint!("foo\r\n");
|
2023-07-02 07:35:19 -05:00
|
|
|
eprint!("\\r\n");
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: using `eprint!()` with a format string that ends in a single newline
|
2022-09-21 12:02:37 -05:00
|
|
|
eprint!("foo\rbar\n");
|
|
|
|
|
|
|
|
// Ignore expanded format strings
|
|
|
|
macro_rules! newline {
|
|
|
|
() => {
|
|
|
|
"\n"
|
|
|
|
};
|
|
|
|
}
|
|
|
|
eprint!(newline!());
|
2020-12-20 10:19:49 -06:00
|
|
|
}
|