]>
git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/write_literal.rs
218385ea1296656b9af99d7549084df80164a0cc
1 #![warn(clippy::write_literal)]
2 #![allow(clippy::uninlined_format_args, unused_must_use)]
7 let mut v
= Vec
::new();
9 // these should be fine
13 writeln
!(v
, "Hello {}", world
);
14 writeln
!(v
, "Hello {world}", world
= world
);
15 writeln
!(v
, "3 in hex is {:X}", 3);
16 writeln
!(v
, "2 + 1 = {:.4}", 3);
17 writeln
!(v
, "2 + 1 = {:5.4}", 3);
18 writeln
!(v
, "Debug test {:?}", "hello, world");
19 writeln
!(v
, "{0:8} {1:>8}", "hello", "world");
20 writeln
!(v
, "{1:8} {0:>8}", "hello", "world");
21 writeln
!(v
, "{foo:8} {bar:>8}", foo
= "hello", bar
= "world");
22 writeln
!(v
, "{bar:8} {foo:>8}", foo
= "hello", bar
= "world");
23 writeln
!(v
, "{number:>width$}", number
= 1, width
= 6);
24 writeln
!(v
, "{number:>0width$}", number
= 1, width
= 6);
25 writeln
!(v
, "{} of {:b} people know binary, the other half doesn't", 1, 2);
26 writeln
!(v
, "10 / 4 is {}", 2.5);
27 writeln
!(v
, "2 + 1 = {}", 3);
28 writeln
!(v
, "From expansion {}", stringify
!(not a string literal
));
30 // these should throw warnings
31 write
!(v
, "Hello {}", "world");
32 writeln
!(v
, "Hello {} {}", world
, "world");
33 writeln
!(v
, "Hello {}", "world");
34 writeln
!(v
, "{} {:.4}", "a literal", 5);
36 // positional args don't change the fact
37 // that we're using a literal -- this should
39 writeln
!(v
, "{0} {1}", "hello", "world");
40 writeln
!(v
, "{1} {0}", "hello", "world");
42 // named args shouldn't change anything either
43 writeln
!(v
, "{foo} {bar}", foo
= "hello", bar
= "world");
44 writeln
!(v
, "{bar} {foo}", foo
= "hello", bar
= "world");