fork/rust
git clone https://git.julia.blue/fork/rust
3bcad65fbf6
master
1// FIXME: Ideally these suggestions would be fixed via rustfix. Blocked by rust-lang/rust#53934 2 3#![allow(clippy::write_literal)] 4#![warn(clippy::write_with_newline)] 5 6use std::io::Write; 7 8fn main() { 9 let mut v = Vec::new(); 10 11 // These should fail 12 writeln!(v, "Hello"); 13 //~^ ERROR: using `write!()` with a format string that ends in a single newline 14 //~| NOTE: `-D clippy::write-with-newline` implied by `-D warnings` 15 writeln!(v, "Hello {}", "world"); 16 //~^ ERROR: using `write!()` with a format string that ends in a single newline 17 writeln!(v, "Hello {} {}", "world", "#2"); 18 //~^ ERROR: using `write!()` with a format string that ends in a single newline 19 writeln!(v, "{}", 1265); 20 //~^ ERROR: using `write!()` with a format string that ends in a single newline 21 writeln!(v); 22 //~^ ERROR: using `write!()` with a format string that ends in a single newline 23 24 // These should be fine 25 write!(v, ""); 26 write!(v, "Hello"); 27 writeln!(v, "Hello"); 28 writeln!(v, "Hello\n"); 29 writeln!(v, "Hello {}\n", "world"); 30 write!(v, "Issue\n{}", 1265); 31 write!(v, "{}", 1265); 32 write!(v, "\n{}", 1275); 33 write!(v, "\n\n"); 34 write!(v, "like eof\n\n"); 35 write!(v, "Hello {} {}\n\n", "world", "#2"); 36 // #3126 37 writeln!(v, "\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); 38 // #3126 39 writeln!(v, "\nbla\n\n"); 40 41 // Escaping 42 // #3514 43 write!(v, "\\n"); 44 writeln!(v, "\\"); 45 //~^ ERROR: using `write!()` with a format string that ends in a single newline 46 write!(v, "\\\\n"); 47 48 // Raw strings 49 // #3778 50 write!(v, r"\n"); 51 52 // Literal newlines should also fail 53 writeln!( 54 //~^ ERROR: using `write!()` with a format string that ends in a single newline 55 v 56 ); 57 writeln!( 58 //~^ ERROR: using `write!()` with a format string that ends in a single newline 59 v 60 ); 61 62 // Don't warn on CRLF (#4208) 63 write!(v, "\r\n"); 64 write!(v, "foo\r\n"); 65 writeln!(v, "\\r"); 66 //~^ ERROR: using `write!()` with a format string that ends in a single newline 67 write!(v, "foo\rbar\n"); 68 69 // Ignore expanded format strings 70 macro_rules! newline { 71 () => { 72 "\n" 73 }; 74 } 75 write!(v, newline!()); 76}