]> git.lizzy.rs Git - rust.git/blob - tests/ui/print_literal.rs
Auto merge of #3635 - matthiaskrgr:revert_random_state_3603, r=xfix
[rust.git] / tests / ui / print_literal.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 #![warn(clippy::print_literal)]
11
12 fn main() {
13     // these should be fine
14     print!("Hello");
15     println!("Hello");
16     let world = "world";
17     println!("Hello {}", world);
18     println!("Hello {world}", world = world);
19     println!("3 in hex is {:X}", 3);
20     println!("2 + 1 = {:.4}", 3);
21     println!("2 + 1 = {:5.4}", 3);
22     println!("Debug test {:?}", "hello, world");
23     println!("{0:8} {1:>8}", "hello", "world");
24     println!("{1:8} {0:>8}", "hello", "world");
25     println!("{foo:8} {bar:>8}", foo = "hello", bar = "world");
26     println!("{bar:8} {foo:>8}", foo = "hello", bar = "world");
27     println!("{number:>width$}", number = 1, width = 6);
28     println!("{number:>0width$}", number = 1, width = 6);
29
30     // these should throw warnings
31     println!("{} of {:b} people know binary, the other half doesn't", 1, 2);
32     print!("Hello {}", "world");
33     println!("Hello {} {}", world, "world");
34     println!("Hello {}", "world");
35     println!("10 / 4 is {}", 2.5);
36     println!("2 + 1 = {}", 3);
37
38     // positional args don't change the fact
39     // that we're using a literal -- this should
40     // throw a warning
41     println!("{0} {1}", "hello", "world");
42     println!("{1} {0}", "hello", "world");
43
44     // named args shouldn't change anything either
45     println!("{foo} {bar}", foo = "hello", bar = "world");
46     println!("{bar} {foo}", foo = "hello", bar = "world");
47 }