Skip to content

Add test for #8855 #8857

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Aug 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions tests/ui/format_args.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,27 @@ fn issue8643(vendor_id: usize, product_id: usize, name: &str) {
name
);
}

// https://github.com/rust-lang/rust-clippy/issues/8855
mod issue_8855 {
#![allow(dead_code)]

struct A {}

impl std::fmt::Display for A {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "test")
}
}

fn main() {
let a = A {};
let b = A {};

let x = format!("{} {}", a, b);
dbg!(x);

let x = format!("{:>6} {:>6}", a, b.to_string());
dbg!(x);
}
}
24 changes: 24 additions & 0 deletions tests/ui/format_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,27 @@ fn issue8643(vendor_id: usize, product_id: usize, name: &str) {
name
);
}

// https://github.com/rust-lang/rust-clippy/issues/8855
mod issue_8855 {
#![allow(dead_code)]

struct A {}

impl std::fmt::Display for A {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "test")
}
}

fn main() {
let a = A {};
let b = A {};

let x = format!("{} {}", a, b.to_string());
dbg!(x);

let x = format!("{:>6} {:>6}", a, b.to_string());
dbg!(x);
}
}
8 changes: 7 additions & 1 deletion tests/ui/format_args.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,11 @@ error: `to_string` applied to a type that implements `Display` in `println!` arg
LL | println!("{foo}{bar}", bar = "bar", foo = "foo".to_string());
| ^^^^^^^^^^^^ help: remove this

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

error: aborting due to 22 previous errors