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