]> git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/write_literal_2.rs
New upstream version 1.74.1+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / write_literal_2.rs
1 //@no-rustfix: overlapping suggestions
2 #![allow(unused_must_use)]
3 #![warn(clippy::needless_raw_strings, clippy::write_literal)]
4
5 use std::io::Write;
6
7 fn main() {
8 let mut v = Vec::new();
9
10 writeln!(v, "{}", "{hello}");
11 //~^ ERROR: literal with an empty format string
12 //~| NOTE: `-D clippy::write-literal` implied by `-D warnings`
13 writeln!(v, r"{}", r"{hello}");
14 //~^ ERROR: unnecessary raw string literal
15 //~| NOTE: `-D clippy::needless-raw-strings` implied by `-D warnings`
16 //~| ERROR: literal with an empty format string
17 writeln!(v, "{}", '\'');
18 //~^ ERROR: literal with an empty format string
19 writeln!(v, "{}", '"');
20 //~^ ERROR: literal with an empty format string
21 writeln!(v, r"{}", '"');
22 //~^ ERROR: literal with an empty format string
23 writeln!(v, r"{}", '\'');
24 //~^ ERROR: literal with an empty format string
25 writeln!(
26 v,
27 "some {}",
28 "hello \
29 //~^ ERROR: literal with an empty format string
30 world!"
31 );
32 writeln!(
33 v,
34 "some {}\
35 {} \\ {}",
36 "1",
37 "2",
38 "3",
39 //~^ ERROR: literal with an empty format string
40 );
41 writeln!(v, "{}", "\\");
42 //~^ ERROR: literal with an empty format string
43 writeln!(v, r"{}", "\\");
44 //~^ ERROR: literal with an empty format string
45 writeln!(v, r#"{}"#, "\\");
46 //~^ ERROR: literal with an empty format string
47 writeln!(v, "{}", r"\");
48 //~^ ERROR: literal with an empty format string
49 writeln!(v, "{}", "\r");
50 //~^ ERROR: literal with an empty format string
51 // hard mode
52 writeln!(v, r#"{}{}"#, '#', '"');
53 //~^ ERROR: literal with an empty format string
54 //~| ERROR: literal with an empty format string
55 // should not lint
56 writeln!(v, r"{}", "\r");
57 }