2019-05-23 13:11:38 -05:00
|
|
|
// FIXME: Ideally these suggestions would be fixed via rustfix. Blocked by rust-lang/rust#53934
|
|
|
|
// // run-rustfix
|
|
|
|
|
2018-07-28 10:34:52 -05:00
|
|
|
#![allow(clippy::write_literal)]
|
|
|
|
#![warn(clippy::write_with_newline)]
|
2018-04-04 22:46:39 -05:00
|
|
|
|
|
|
|
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");
|
2018-08-07 15:01:10 -05:00
|
|
|
write!(&mut v, "Hello {} {}\n", "world", "#2");
|
2018-04-04 22:46:39 -05:00
|
|
|
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);
|
2018-08-07 15:01:10 -05:00
|
|
|
write!(&mut v, "\n\n");
|
|
|
|
write!(&mut v, "like eof\n\n");
|
|
|
|
write!(&mut v, "Hello {} {}\n\n", "world", "#2");
|
2018-09-06 05:55:04 -05:00
|
|
|
writeln!(&mut v, "\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); // #3126
|
|
|
|
writeln!(&mut v, "\nbla\n\n"); // #3126
|
2018-12-11 00:28:25 -06:00
|
|
|
|
|
|
|
// Escaping
|
|
|
|
write!(&mut v, "\\n"); // #3514
|
2019-02-17 21:32:58 -06:00
|
|
|
write!(&mut v, "\\\n"); // should fail
|
2018-12-11 00:28:25 -06:00
|
|
|
write!(&mut v, "\\\\n");
|
2019-02-17 21:32:58 -06:00
|
|
|
|
|
|
|
// Raw strings
|
|
|
|
write!(&mut v, r"\n"); // #3778
|
2019-02-18 10:39:23 -06:00
|
|
|
|
|
|
|
// Literal newlines should also fail
|
|
|
|
write!(
|
|
|
|
&mut v,
|
|
|
|
"
|
|
|
|
"
|
|
|
|
);
|
|
|
|
write!(
|
|
|
|
&mut v,
|
|
|
|
r"
|
|
|
|
"
|
|
|
|
);
|
2019-11-02 23:41:22 -05:00
|
|
|
|
|
|
|
// Don't warn on CRLF (#4208)
|
|
|
|
write!(&mut v, "\r\n");
|
|
|
|
write!(&mut v, "foo\r\n");
|
|
|
|
write!(&mut v, "\\r\n"); //~ ERROR
|
|
|
|
write!(&mut v, "foo\rbar\n");
|
2018-04-04 22:46:39 -05:00
|
|
|
}
|