Skip to content

Commit 6f3d398

Browse files
committed
Add test for rust-lang#8855
1 parent 5820add commit 6f3d398

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

tests/ui/format_args.fixed

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,27 @@ fn issue8643(vendor_id: usize, product_id: usize, name: &str) {
122122
name
123123
);
124124
}
125+
126+
// https://github.com/rust-lang/rust-clippy/issues/8855
127+
mod issue_8855 {
128+
#![allow(dead_code)]
129+
130+
struct A {}
131+
132+
impl std::fmt::Display for A {
133+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
134+
write!(f, "test")
135+
}
136+
}
137+
138+
fn main() {
139+
let a = A {};
140+
let b = A {};
141+
142+
let x = format!("{} {}", a, b);
143+
dbg!(x);
144+
145+
let x = format!("{:>6} {:>6}", a, b.to_string());
146+
dbg!(x);
147+
}
148+
}

tests/ui/format_args.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,27 @@ fn issue8643(vendor_id: usize, product_id: usize, name: &str) {
122122
name
123123
);
124124
}
125+
126+
// https://github.com/rust-lang/rust-clippy/issues/8855
127+
mod issue_8855 {
128+
#![allow(dead_code)]
129+
130+
struct A {}
131+
132+
impl std::fmt::Display for A {
133+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
134+
write!(f, "test")
135+
}
136+
}
137+
138+
fn main() {
139+
let a = A {};
140+
let b = A {};
141+
142+
let x = format!("{} {}", a, b.to_string());
143+
dbg!(x);
144+
145+
let x = format!("{:>6} {:>6}", a, b.to_string());
146+
dbg!(x);
147+
}
148+
}

tests/ui/format_args.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,5 +126,11 @@ error: `to_string` applied to a type that implements `Display` in `println!` arg
126126
LL | println!("{foo}{bar}", bar = "bar", foo = "foo".to_string());
127127
| ^^^^^^^^^^^^ help: remove this
128128

129-
error: aborting due to 21 previous errors
129+
error: `to_string` applied to a type that implements `Display` in `format!` args
130+
--> $DIR/format_args.rs:142:38
131+
|
132+
LL | let x = format!("{} {}", a, b.to_string());
133+
| ^^^^^^^^^^^^ help: remove this
134+
135+
error: aborting due to 22 previous errors
130136

0 commit comments

Comments
 (0)