Skip to content

Commit 3ac6593

Browse files
committed
handle astriks
1 parent 8897ad9 commit 3ac6593

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

clippy_utils/src/macros.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,9 +564,10 @@ fn span_from_inner(base: SpanData, inner: rpf::InnerSpan) -> Span {
564564
pub enum FormatParamKind {
565565
/// An implicit parameter , such as `{}` or `{:?}`.
566566
Implicit,
567-
/// A parameter with an explicit number, or an asterisk precision. e.g. `{1}`, `{0:?}`,
568-
/// `{:.0$}` or `{:.*}`.
567+
/// A parameter with an explicit number, e.g. `{1}`, `{0:?}`, or `{:.0$}`
569568
Numbered,
569+
/// A parameter with an asterisk precision. e.g. `{:.*}`.
570+
Stared,
570571
/// A named parameter with a named `value_arg`, such as the `x` in `format!("{x}", x = 1)`.
571572
Named(Symbol),
572573
/// An implicit named parameter, such as the `y` in `format!("{y}")`.
@@ -646,9 +647,12 @@ impl<'tcx> Count<'tcx> {
646647
span,
647648
values,
648649
)?),
649-
rpf::Count::CountIsParam(_) | rpf::Count::CountIsStar(_) => {
650+
rpf::Count::CountIsParam(_) => {
650651
Self::Param(FormatParam::new(FormatParamKind::Numbered, position?, inner?, values)?)
651652
},
653+
rpf::Count::CountIsStar(_) => {
654+
Self::Param(FormatParam::new(FormatParamKind::Stared, position?, inner?, values)?)
655+
},
652656
rpf::Count::CountImplied => Self::Implied,
653657
})
654658
}

tests/ui/inline_format_args.fixed

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ fn tester(fn_arg: i32) {
3737
println!("{local_i32:<3}");
3838
println!("{local_i32:#010x}");
3939
println!("{local_f64:.1}");
40-
println!("Hello {} is {:.*}", "x", local_i32, local_f64);
41-
println!("Hello {} is {:.*}", local_i32, 5, local_f64);
40+
println!("Hello {} is {local_f64:.*}", "x", local_i32);
41+
println!("Hello {local_i32} is {local_f64:.*}", 5);
4242
println!("Hello {} is {2:.*}", local_i32, 5, local_f64);
4343
println!("{local_i32} {local_f64}");
4444
println!("{local_i32}, {}", local_opt.unwrap());

tests/ui/inline_format_args.stderr

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,30 @@ LL - println!("{:.1}", local_f64);
183183
LL + println!("{local_f64:.1}");
184184
|
185185

186+
error: variables can be used directly in the `format!` string
187+
--> $DIR/inline_format_args.rs:42:5
188+
|
189+
LL | println!("Hello {} is {:.*}", "x", local_i32, local_f64);
190+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
191+
|
192+
help: change this to
193+
|
194+
LL - println!("Hello {} is {:.*}", "x", local_i32, local_f64);
195+
LL + println!("Hello {} is {local_f64:.*}", "x", local_i32);
196+
|
197+
198+
error: variables can be used directly in the `format!` string
199+
--> $DIR/inline_format_args.rs:43:5
200+
|
201+
LL | println!("Hello {} is {:.*}", local_i32, 5, local_f64);
202+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
203+
|
204+
help: change this to
205+
|
206+
LL - println!("Hello {} is {:.*}", local_i32, 5, local_f64);
207+
LL + println!("Hello {local_i32} is {local_f64:.*}", 5);
208+
|
209+
186210
error: variables can be used directly in the `format!` string
187211
--> $DIR/inline_format_args.rs:45:5
188212
|
@@ -279,5 +303,5 @@ LL - println!("{}", format!("{}", local_i32));
279303
LL + println!("{}", format!("{local_i32}"));
280304
|
281305

282-
error: aborting due to 23 previous errors
306+
error: aborting due to 25 previous errors
283307

0 commit comments

Comments
 (0)