]> git.lizzy.rs Git - rust.git/blob - tests/ui/print_literal.rs
Add edge case with env! arg to test and known problems
[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!("3 in hex is {:X}", 3);
12
13     // this in theory shouldn't yield a warning,
14     // but at present time, it's a known edge case
15     // that isn't handled (because we can't expand
16     // `println!` and not `env!`)
17     println!("foo: {}", env!("BAR"));
18
19     // these should throw warnings
20     print!("Hello {}", "world");
21     println!("Hello {} {}", world, "world");
22     println!("Hello {}", "world");
23     println!("10 / 4 is {}", 2.5);
24     println!("2 + 1 = {}", 3);
25     println!("2 + 1 = {:.4}", 3);
26     println!("2 + 1 = {:5.4}", 3);
27     println!("Debug test {:?}", "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 }