fork/rust
git clone https://git.julia.blue/fork/rust
3bcad65fbf6
master
1#![warn(clippy::print_literal)] 2#![allow(clippy::uninlined_format_args)] 3 4fn main() { 5 // these should be fine 6 print!("Hello"); 7 println!("Hello"); 8 let world = "world"; 9 println!("Hello {}", world); 10 println!("Hello {world}", world = world); 11 println!("3 in hex is {:X}", 3); 12 println!("2 + 1 = {:.4}", 3); 13 println!("2 + 1 = {:5.4}", 3); 14 println!("Debug test {:?}", "hello, world"); 15 println!("{0:8} {1:>8}", "hello", "world"); 16 println!("{1:8} {0:>8}", "hello", "world"); 17 println!("{foo:8} {bar:>8}", foo = "hello", bar = "world"); 18 println!("{bar:8} {foo:>8}", foo = "hello", bar = "world"); 19 println!("{number:>width$}", number = 1, width = 6); 20 println!("{number:>0width$}", number = 1, width = 6); 21 println!("{} of {:b} people know binary, the other half doesn't", 1, 2); 22 println!("10 / 4 is {}", 2.5); 23 println!("2 + 1 = {}", 3); 24 println!("From expansion {}", stringify!(not a string literal)); 25 26 // these should throw warnings 27 print!("Hello world"); 28 //~^ ERROR: literal with an empty format string 29 //~| NOTE: `-D clippy::print-literal` implied by `-D warnings` 30 println!("Hello {} world", world); 31 //~^ ERROR: literal with an empty format string 32 println!("Hello world"); 33 //~^ ERROR: literal with an empty format string 34 println!("a literal {:.4}", 5); 35 //~^ ERROR: literal with an empty format string 36 37 // positional args don't change the fact 38 // that we're using a literal -- this should 39 // throw a warning 40 println!("hello world"); 41 //~^ ERROR: literal with an empty format string 42 //~| ERROR: literal with an empty format string 43 println!("world hello"); 44 //~^ ERROR: literal with an empty format string 45 //~| ERROR: literal with an empty format string 46 47 // named args shouldn't change anything either 48 println!("hello world"); 49 //~^ ERROR: literal with an empty format string 50 //~| ERROR: literal with an empty format string 51 println!("world hello"); 52 //~^ ERROR: literal with an empty format string 53 //~| ERROR: literal with an empty format string 54 55 // The string literal from `file!()` has a callsite span that isn't marked as coming from an 56 // expansion 57 println!("file: {}", file!()); 58}