]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/print_literal.rs
Auto merge of #84620 - Dylan-DPC:rollup-wkv97im, r=Dylan-DPC
[rust.git] / src / tools / clippy / tests / ui / print_literal.rs
1 #![warn(clippy::print_literal)]
2
3 fn main() {
4     // these should be fine
5     print!("Hello");
6     println!("Hello");
7     let world = "world";
8     println!("Hello {}", world);
9     println!("Hello {world}", world = world);
10     println!("3 in hex is {:X}", 3);
11     println!("2 + 1 = {:.4}", 3);
12     println!("2 + 1 = {:5.4}", 3);
13     println!("Debug test {:?}", "hello, world");
14     println!("{0:8} {1:>8}", "hello", "world");
15     println!("{1:8} {0:>8}", "hello", "world");
16     println!("{foo:8} {bar:>8}", foo = "hello", bar = "world");
17     println!("{bar:8} {foo:>8}", foo = "hello", bar = "world");
18     println!("{number:>width$}", number = 1, width = 6);
19     println!("{number:>0width$}", number = 1, width = 6);
20     println!("{} of {:b} people know binary, the other half doesn't", 1, 2);
21     println!("10 / 4 is {}", 2.5);
22     println!("2 + 1 = {}", 3);
23
24     // these should throw warnings
25     print!("Hello {}", "world");
26     println!("Hello {} {}", world, "world");
27     println!("Hello {}", "world");
28
29     // positional args don't change the fact
30     // that we're using a literal -- this should
31     // throw a warning
32     println!("{0} {1}", "hello", "world");
33     println!("{1} {0}", "hello", "world");
34
35     // named args shouldn't change anything either
36     println!("{foo} {bar}", foo = "hello", bar = "world");
37     println!("{bar} {foo}", foo = "hello", bar = "world");
38 }