]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/print_with_newline.rs
Auto merge of #101846 - chenyukang:fix-101793, r=davidtwco
[rust.git] / src / tools / clippy / tests / ui / print_with_newline.rs
1 // FIXME: Ideally these suggestions would be fixed via rustfix. Blocked by rust-lang/rust#53934
2 // // run-rustfix
3
4 #![allow(clippy::print_literal)]
5 #![warn(clippy::print_with_newline)]
6
7 fn main() {
8     print!("Hello\n");
9     print!("Hello {}\n", "world");
10     print!("Hello {} {}\n", "world", "#2");
11     print!("{}\n", 1265);
12     print!("\n");
13
14     // these are all fine
15     print!("");
16     print!("Hello");
17     println!("Hello");
18     println!("Hello\n");
19     println!("Hello {}\n", "world");
20     print!("Issue\n{}", 1265);
21     print!("{}", 1265);
22     print!("\n{}", 1275);
23     print!("\n\n");
24     print!("like eof\n\n");
25     print!("Hello {} {}\n\n", "world", "#2");
26     println!("\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); // #3126
27     println!("\nbla\n\n"); // #3126
28
29     // Escaping
30     print!("\\n"); // #3514
31     print!("\\\n"); // should fail
32     print!("\\\\n");
33
34     // Raw strings
35     print!(r"\n"); // #3778
36
37     // Literal newlines should also fail
38     print!(
39         "
40 "
41     );
42     print!(
43         r"
44 "
45     );
46
47     // Don't warn on CRLF (#4208)
48     print!("\r\n");
49     print!("foo\r\n");
50     print!("\\r\n"); //~ ERROR
51     print!("foo\rbar\n") // ~ ERROR
52 }