rust-clippy/tests/ui/eprint_with_newline.fixed

60 lines
1.2 KiB
Rust
Raw Normal View History

2023-07-27 11:40:22 +00:00
#![allow(clippy::print_literal)]
#![warn(clippy::print_with_newline)]
fn main() {
eprintln!("Hello");
eprintln!("Hello {}", "world");
eprintln!("Hello {} {}", "world", "#2");
eprintln!("{}", 1265);
eprintln!();
// 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");
// #3126
eprintln!("\ndon't\nwarn\nfor\nmultiple\nnewlines\n");
// #3126
eprintln!("\nbla\n\n");
2023-07-27 11:40:22 +00:00
// Escaping
// #3514
eprint!("\\n");
eprintln!("\\");
2023-07-27 11:40:22 +00:00
eprint!("\\\\n");
// Raw strings
// #3778
eprint!(r"\n");
2023-07-27 11:40:22 +00:00
// Literal newlines should also fail
eprintln!(
);
eprintln!(
);
// Don't warn on CRLF (#4208)
eprint!("\r\n");
eprint!("foo\r\n");
eprintln!("\\r");
eprint!("foo\rbar\n");
// Ignore expanded format strings
macro_rules! newline {
() => {
"\n"
};
}
eprint!(newline!());
}