diff options
| author | Samuel E. Moelius III <sam@moeli.us> | 2022-05-20 17:53:03 -0400 |
|---|---|---|
| committer | Samuel Moelius <samuel.moelius@trailofbits.com> | 2022-08-20 15:21:32 +0000 |
| commit | 6f3d398e13607d8ee3eb6d18ea633bc7e5a3a118 (patch) | |
| tree | bb80b682036ef1b47b18cfe8ededc33e127ea6f7 | |
| parent | 5820addb240ddcf13712be686c141a3d00ae792a (diff) | |
| download | rust-6f3d398e13607d8ee3eb6d18ea633bc7e5a3a118.tar.gz rust-6f3d398e13607d8ee3eb6d18ea633bc7e5a3a118.zip | |
Add test for #8855
| -rw-r--r-- | tests/ui/format_args.fixed | 24 | ||||
| -rw-r--r-- | tests/ui/format_args.rs | 24 | ||||
| -rw-r--r-- | tests/ui/format_args.stderr | 8 |
3 files changed, 55 insertions, 1 deletions
diff --git a/tests/ui/format_args.fixed b/tests/ui/format_args.fixed index 4322891db76..e07cae70277 100644 --- a/tests/ui/format_args.fixed +++ b/tests/ui/format_args.fixed @@ -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); + } +} diff --git a/tests/ui/format_args.rs b/tests/ui/format_args.rs index 61ad04612cd..86e66bce2c5 100644 --- a/tests/ui/format_args.rs +++ b/tests/ui/format_args.rs @@ -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); + } +} diff --git a/tests/ui/format_args.stderr b/tests/ui/format_args.stderr index 0aca1c1a0df..e69999cc9d0 100644 --- a/tests/ui/format_args.stderr +++ b/tests/ui/format_args.stderr @@ -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 |
