cf5d4a1b45
Literal `\n` characters (not a newline) in a `r"raw"` string should not fail the lint. This affects both write_with_newline and print_with_newline, so it is added in both places. I also copied a missing test case from write_with_newline over to print_with_newline and added a note that one of those tests is supposed to fail.
38 lines
1.0 KiB
Rust
38 lines
1.0 KiB
Rust
#![allow(clippy::write_literal)]
|
|
#![warn(clippy::write_with_newline)]
|
|
|
|
use std::io::Write;
|
|
|
|
fn main() {
|
|
let mut v = Vec::new();
|
|
|
|
// These should fail
|
|
write!(&mut v, "Hello\n");
|
|
write!(&mut v, "Hello {}\n", "world");
|
|
write!(&mut v, "Hello {} {}\n", "world", "#2");
|
|
write!(&mut v, "{}\n", 1265);
|
|
|
|
// These should be fine
|
|
write!(&mut v, "");
|
|
write!(&mut v, "Hello");
|
|
writeln!(&mut v, "Hello");
|
|
writeln!(&mut v, "Hello\n");
|
|
writeln!(&mut v, "Hello {}\n", "world");
|
|
write!(&mut v, "Issue\n{}", 1265);
|
|
write!(&mut v, "{}", 1265);
|
|
write!(&mut v, "\n{}", 1275);
|
|
write!(&mut v, "\n\n");
|
|
write!(&mut v, "like eof\n\n");
|
|
write!(&mut v, "Hello {} {}\n\n", "world", "#2");
|
|
writeln!(&mut v, "\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); // #3126
|
|
writeln!(&mut v, "\nbla\n\n"); // #3126
|
|
|
|
// Escaping
|
|
write!(&mut v, "\\n"); // #3514
|
|
write!(&mut v, "\\\n"); // should fail
|
|
write!(&mut v, "\\\\n");
|
|
|
|
// Raw strings
|
|
write!(&mut v, r"\n"); // #3778
|
|
}
|