File tree 4 files changed +58
-1
lines changed
4 files changed +58
-1
lines changed Original file line number Diff line number Diff line change @@ -359,6 +359,9 @@ impl<'tcx> FormatArgsExpn<'tcx> {
359
359
sym:: const_format_args | sym:: format_args | sym:: format_args_nl
360
360
)
361
361
} ) ?;
362
+ if !matches ! ( expr. kind, ExprKind :: Call ( ..) ) {
363
+ return None ;
364
+ }
362
365
let mut format_string_span: Option < Span > = None ;
363
366
let mut format_string_parts: Vec < Symbol > = Vec :: new ( ) ;
364
367
let mut value_args: Vec < & Expr < ' _ > > = Vec :: new ( ) ;
Original file line number Diff line number Diff line change @@ -115,3 +115,27 @@ fn main() {
115
115
// https://github.com/rust-lang/rust-clippy/issues/7903
116
116
println!("{foo}{foo:?}", foo = "foo".to_string());
117
117
}
118
+
119
+ // https://github.com/rust-lang/rust-clippy/issues/8855
120
+ mod issue_8855 {
121
+ #![allow(dead_code)]
122
+
123
+ struct A {}
124
+
125
+ impl std::fmt::Display for A {
126
+ fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
127
+ write!(f, "test")
128
+ }
129
+ }
130
+
131
+ fn main() {
132
+ let a = A {};
133
+ let b = A {};
134
+
135
+ let x = format!("{} {}", a, b);
136
+ dbg!(x);
137
+
138
+ let x = format!("{:>6} {:>6}", a, b.to_string());
139
+ dbg!(x);
140
+ }
141
+ }
Original file line number Diff line number Diff line change @@ -115,3 +115,27 @@ fn main() {
115
115
// https://github.com/rust-lang/rust-clippy/issues/7903
116
116
println ! ( "{foo}{foo:?}" , foo = "foo" . to_string( ) ) ;
117
117
}
118
+
119
+ // https://github.com/rust-lang/rust-clippy/issues/8855
120
+ mod issue_8855 {
121
+ #![ allow( dead_code) ]
122
+
123
+ struct A { }
124
+
125
+ impl std:: fmt:: Display for A {
126
+ fn fmt ( & self , f : & mut std:: fmt:: Formatter ) -> std:: fmt:: Result {
127
+ write ! ( f, "test" )
128
+ }
129
+ }
130
+
131
+ fn main ( ) {
132
+ let a = A { } ;
133
+ let b = A { } ;
134
+
135
+ let x = format ! ( "{} {}" , a, b. to_string( ) ) ;
136
+ dbg ! ( x) ;
137
+
138
+ let x = format ! ( "{:>6} {:>6}" , a, b. to_string( ) ) ;
139
+ dbg ! ( x) ;
140
+ }
141
+ }
Original file line number Diff line number Diff line change @@ -126,5 +126,11 @@ error: `to_string` applied to a type that implements `Display` in `println!` arg
126
126
LL | println!("{foo}{bar}", bar = "bar", foo = "foo".to_string());
127
127
| ^^^^^^^^^^^^ help: remove this
128
128
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:135:38
131
+ |
132
+ LL | let x = format!("{} {}", a, b.to_string());
133
+ | ^^^^^^^^^^^^ help: remove this
134
+
135
+ error: aborting due to 22 previous errors
130
136
You can’t perform that action at this time.
0 commit comments