mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-12-18 00:53:31 +00:00
69 lines
2 KiB
Rust
69 lines
2 KiB
Rust
#![allow(clippy::print_literal)]
|
|
#![warn(clippy::print_with_newline)]
|
|
|
|
fn main() {
|
|
eprintln!("Hello");
|
|
//~^ ERROR: using `eprint!()` with a format string that ends in a single newline
|
|
//~| NOTE: `-D clippy::print-with-newline` implied by `-D warnings`
|
|
eprintln!("Hello {}", "world");
|
|
//~^ ERROR: using `eprint!()` with a format string that ends in a single newline
|
|
eprintln!("Hello {} {}", "world", "#2");
|
|
//~^ ERROR: using `eprint!()` with a format string that ends in a single newline
|
|
eprintln!("{}", 1265);
|
|
//~^ ERROR: using `eprint!()` with a format string that ends in a single newline
|
|
eprintln!();
|
|
//~^ ERROR: using `eprint!()` with a format string that ends in a single newline
|
|
|
|
// 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");
|
|
|
|
// Escaping
|
|
// #3514
|
|
eprint!("\\n");
|
|
eprintln!("\\");
|
|
//~^ ERROR: using `eprint!()` with a format string that ends in a single newline
|
|
eprint!("\\\\n");
|
|
|
|
// Raw strings
|
|
// #3778
|
|
eprint!(r"\n");
|
|
|
|
// Literal newlines should also fail
|
|
eprintln!(
|
|
//~^ ERROR: using `eprint!()` with a format string that ends in a single newline
|
|
|
|
);
|
|
eprintln!(
|
|
//~^ ERROR: using `eprint!()` with a format string that ends in a single newline
|
|
|
|
);
|
|
|
|
// Don't warn on CRLF (#4208)
|
|
eprint!("\r\n");
|
|
eprint!("foo\r\n");
|
|
eprintln!("\\r");
|
|
//~^ ERROR: using `eprint!()` with a format string that ends in a single newline
|
|
eprint!("foo\rbar\n");
|
|
|
|
// Ignore expanded format strings
|
|
macro_rules! newline {
|
|
() => {
|
|
"\n"
|
|
};
|
|
}
|
|
eprint!(newline!());
|
|
}
|