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