Add edge case with env! arg to test and known problems

This commit is contained in:
Michael Recachinas 2018-04-02 20:32:46 +01:00
parent 511aa654d7
commit d504290839
3 changed files with 49 additions and 34 deletions

View file

@ -84,6 +84,9 @@ declare_clippy_lint! {
/// (c.f., https://github.com/matthiaskrgr/rust-str-bench) and unnecessary
/// (i.e., just put the literal in the format string)
///
/// **Known problems:** Will also warn with macro calls as arguments that expand to literals
/// -- e.g., `println!("{}", env!("FOO"))`.
///
/// **Example:**
/// ```rust
/// println!("{}", "foo");

View file

@ -10,6 +10,12 @@ fn main() {
println!("Hello {}", world);
println!("3 in hex is {:X}", 3);
// this in theory shouldn't yield a warning,
// but at present time, it's a known edge case
// that isn't handled (because we can't expand
// `println!` and not `env!`)
println!("foo: {}", env!("BAR"));
// these should throw warnings
print!("Hello {}", "world");
println!("Hello {} {}", world, "world");

View file

@ -1,100 +1,106 @@
error: printing a literal with an empty format string
--> $DIR/print_literal.rs:14:24
--> $DIR/print_literal.rs:17:25
|
14 | print!("Hello {}", "world");
| ^^^^^^^
17 | println!("foo: {}", env!("BAR"));
| ^^^^^^^^^^^
|
= note: `-D print-literal` implied by `-D warnings`
error: printing a literal with an empty format string
--> $DIR/print_literal.rs:15:36
--> $DIR/print_literal.rs:20:24
|
15 | println!("Hello {} {}", world, "world");
20 | print!("Hello {}", "world");
| ^^^^^^^
error: printing a literal with an empty format string
--> $DIR/print_literal.rs:21:36
|
21 | println!("Hello {} {}", world, "world");
| ^^^^^^^
error: printing a literal with an empty format string
--> $DIR/print_literal.rs:16:26
--> $DIR/print_literal.rs:22:26
|
16 | println!("Hello {}", "world");
22 | println!("Hello {}", "world");
| ^^^^^^^
error: printing a literal with an empty format string
--> $DIR/print_literal.rs:17:30
--> $DIR/print_literal.rs:23:30
|
17 | println!("10 / 4 is {}", 2.5);
23 | println!("10 / 4 is {}", 2.5);
| ^^^
error: printing a literal with an empty format string
--> $DIR/print_literal.rs:18:28
--> $DIR/print_literal.rs:24:28
|
18 | println!("2 + 1 = {}", 3);
24 | println!("2 + 1 = {}", 3);
| ^
error: printing a literal with an empty format string
--> $DIR/print_literal.rs:19:31
--> $DIR/print_literal.rs:25:31
|
19 | println!("2 + 1 = {:.4}", 3);
25 | println!("2 + 1 = {:.4}", 3);
| ^
error: printing a literal with an empty format string
--> $DIR/print_literal.rs:20:32
--> $DIR/print_literal.rs:26:32
|
20 | println!("2 + 1 = {:5.4}", 3);
26 | println!("2 + 1 = {:5.4}", 3);
| ^
error: printing a literal with an empty format string
--> $DIR/print_literal.rs:21:33
--> $DIR/print_literal.rs:27:33
|
21 | println!("Debug test {:?}", "hello, world");
27 | println!("Debug test {:?}", "hello, world");
| ^^^^^^^^^^^^^^
error: printing a literal with an empty format string
--> $DIR/print_literal.rs:26:25
--> $DIR/print_literal.rs:32:25
|
26 | println!("{0} {1}", "hello", "world");
32 | println!("{0} {1}", "hello", "world");
| ^^^^^^^
error: printing a literal with an empty format string
--> $DIR/print_literal.rs:26:34
--> $DIR/print_literal.rs:32:34
|
26 | println!("{0} {1}", "hello", "world");
32 | println!("{0} {1}", "hello", "world");
| ^^^^^^^
error: printing a literal with an empty format string
--> $DIR/print_literal.rs:27:25
--> $DIR/print_literal.rs:33:25
|
27 | println!("{1} {0}", "hello", "world");
33 | println!("{1} {0}", "hello", "world");
| ^^^^^^^
error: printing a literal with an empty format string
--> $DIR/print_literal.rs:27:34
--> $DIR/print_literal.rs:33:34
|
27 | println!("{1} {0}", "hello", "world");
33 | println!("{1} {0}", "hello", "world");
| ^^^^^^^
error: printing a literal with an empty format string
--> $DIR/print_literal.rs:30:33
--> $DIR/print_literal.rs:36:33
|
30 | println!("{foo} {bar}", foo="hello", bar="world");
36 | println!("{foo} {bar}", foo="hello", bar="world");
| ^^^^^^^
error: printing a literal with an empty format string
--> $DIR/print_literal.rs:30:46
--> $DIR/print_literal.rs:36:46
|
30 | println!("{foo} {bar}", foo="hello", bar="world");
36 | println!("{foo} {bar}", foo="hello", bar="world");
| ^^^^^^^
error: printing a literal with an empty format string
--> $DIR/print_literal.rs:31:33
--> $DIR/print_literal.rs:37:33
|
31 | println!("{bar} {foo}", foo="hello", bar="world");
37 | println!("{bar} {foo}", foo="hello", bar="world");
| ^^^^^^^
error: printing a literal with an empty format string
--> $DIR/print_literal.rs:31:46
--> $DIR/print_literal.rs:37:46
|
31 | println!("{bar} {foo}", foo="hello", bar="world");
37 | println!("{bar} {foo}", foo="hello", bar="world");
| ^^^^^^^
error: aborting due to 16 previous errors
error: aborting due to 17 previous errors