Skip to content

Commit 1d8e177

Browse files
committed
Add two format_args test cases
1 parent 84c7fb7 commit 1d8e177

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

tests/ui/format_args.fixed

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,24 @@
66
use std::io::{Error, ErrorKind};
77
use std::panic::Location;
88

9+
struct Somewhere;
10+
11+
impl ToString for Somewhere {
12+
fn to_string(&self) -> String {
13+
String::from("somewhere")
14+
}
15+
}
16+
917
fn main() {
1018
let error = Error::new(ErrorKind::Other, "bad thing");
1119
println!("error: something failed at {}", Location::caller());
1220
println!("{}: something failed at {}", error, Location::caller());
1321
println!("{:?}: something failed at {}", error, Location::caller());
22+
println!("{{}}: something failed at {}", Location::caller());
1423
println!(r#"error: "something failed at {}""#, Location::caller());
1524
println!("error: {}", format_args!("something failed at {}", Location::caller()));
1625
println!("error: {:>70}", format!("something failed at {}", Location::caller()));
1726
let _ = format!("error: something failed at {}", Location::caller());
1827
println!("error: something failed at {}", Location::caller());
28+
println!("error: something failed at {}", Somewhere.to_string());
1929
}

tests/ui/format_args.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,24 @@
66
use std::io::{Error, ErrorKind};
77
use std::panic::Location;
88

9+
struct Somewhere;
10+
11+
impl ToString for Somewhere {
12+
fn to_string(&self) -> String {
13+
String::from("somewhere")
14+
}
15+
}
16+
917
fn main() {
1018
let error = Error::new(ErrorKind::Other, "bad thing");
1119
println!("error: {}", format!("something failed at {}", Location::caller()));
1220
println!("{}: {}", error, format!("something failed at {}", Location::caller()));
1321
println!("{:?}: {}", error, format!("something failed at {}", Location::caller()));
22+
println!("{{}}: {}", format!("something failed at {}", Location::caller()));
1423
println!(r#"error: "{}""#, format!("something failed at {}", Location::caller()));
1524
println!("error: {}", format_args!("something failed at {}", Location::caller()));
1625
println!("error: {:>70}", format!("something failed at {}", Location::caller()));
1726
let _ = format!("error: {}", format!("something failed at {}", Location::caller()));
1827
println!("error: something failed at {}", Location::caller().to_string());
28+
println!("error: something failed at {}", Somewhere.to_string());
1929
}

tests/ui/format_args.stderr

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,48 @@
11
error: `format!` in `println!` args
2-
--> $DIR/format_args.rs:11:5
2+
--> $DIR/format_args.rs:19:5
33
|
44
LL | println!("error: {}", format!("something failed at {}", Location::caller()));
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: inline the `format!` call: `println!("error: something failed at {}", Location::caller())`
66
|
77
= note: `-D clippy::format-in-format-args` implied by `-D warnings`
88

99
error: `format!` in `println!` args
10-
--> $DIR/format_args.rs:12:5
10+
--> $DIR/format_args.rs:20:5
1111
|
1212
LL | println!("{}: {}", error, format!("something failed at {}", Location::caller()));
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: inline the `format!` call: `println!("{}: something failed at {}", error, Location::caller())`
1414

1515
error: `format!` in `println!` args
16-
--> $DIR/format_args.rs:13:5
16+
--> $DIR/format_args.rs:21:5
1717
|
1818
LL | println!("{:?}: {}", error, format!("something failed at {}", Location::caller()));
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: inline the `format!` call: `println!("{:?}: something failed at {}", error, Location::caller())`
2020

2121
error: `format!` in `println!` args
22-
--> $DIR/format_args.rs:14:5
22+
--> $DIR/format_args.rs:22:5
23+
|
24+
LL | println!("{{}}: {}", format!("something failed at {}", Location::caller()));
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: inline the `format!` call: `println!("{{}}: something failed at {}", Location::caller())`
26+
27+
error: `format!` in `println!` args
28+
--> $DIR/format_args.rs:23:5
2329
|
2430
LL | println!(r#"error: "{}""#, format!("something failed at {}", Location::caller()));
2531
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: inline the `format!` call: `println!(r#"error: "something failed at {}""#, Location::caller())`
2632

2733
error: `format!` in `format!` args
28-
--> $DIR/format_args.rs:17:13
34+
--> $DIR/format_args.rs:26:13
2935
|
3036
LL | let _ = format!("error: {}", format!("something failed at {}", Location::caller()));
3137
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: inline the `format!` call: `format!("error: something failed at {}", Location::caller())`
3238

3339
error: `to_string` applied to a type that implements `Display` in `println!` args
34-
--> $DIR/format_args.rs:18:65
40+
--> $DIR/format_args.rs:27:65
3541
|
3642
LL | println!("error: something failed at {}", Location::caller().to_string());
3743
| ^^^^^^^^^^^^ help: remove this
3844
|
3945
= note: `-D clippy::to-string-in-format-args` implied by `-D warnings`
4046

41-
error: aborting due to 6 previous errors
47+
error: aborting due to 7 previous errors
4248

0 commit comments

Comments
 (0)