Skip to content

Commit bf3f976

Browse files
committed
Fix regression in print_literal
1 parent fde487c commit bf3f976

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

clippy_lints/src/write.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -290,22 +290,24 @@ fn check_tts(cx: &EarlyContext<'a>, tts: &ThinTokenStream, is_write: bool) -> Op
290290
idx += 1;
291291
},
292292
ExprKind::Assign(lhs, rhs) => {
293-
if let ExprKind::Path(_, p) = &lhs.node {
294-
let mut all_simple = true;
295-
let mut seen = false;
296-
for arg in &args {
297-
match arg.position {
298-
| ArgumentImplicitlyIs(_)
299-
| ArgumentIs(_)
300-
=> {},
301-
ArgumentNamed(name) => if *p == name {
302-
seen = true;
303-
all_simple &= arg.format == SIMPLE;
304-
},
293+
if let ExprKind::Lit(_) = rhs.node {
294+
if let ExprKind::Path(_, p) = &lhs.node {
295+
let mut all_simple = true;
296+
let mut seen = false;
297+
for arg in &args {
298+
match arg.position {
299+
| ArgumentImplicitlyIs(_)
300+
| ArgumentIs(_)
301+
=> {},
302+
ArgumentNamed(name) => if *p == name {
303+
seen = true;
304+
all_simple &= arg.format == SIMPLE;
305+
},
306+
}
307+
}
308+
if all_simple && seen {
309+
span_lint(cx, lint, rhs.span, "literal with an empty format string");
305310
}
306-
}
307-
if all_simple && seen {
308-
span_lint(cx, lint, rhs.span, "literal with an empty format string");
309311
}
310312
}
311313
},

tests/ui/print_literal.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ fn main() {
88
println!("Hello");
99
let world = "world";
1010
println!("Hello {}", world);
11+
println!("Hello {world}", world=world);
1112
println!("3 in hex is {:X}", 3);
1213
println!("2 + 1 = {:.4}", 3);
1314
println!("2 + 1 = {:5.4}", 3);

tests/ui/write_literal.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ fn main() {
1111
writeln!(&mut v, "Hello");
1212
let world = "world";
1313
writeln!(&mut v, "Hello {}", world);
14+
writeln!(&mut v, "Hello {world}", world);
1415
writeln!(&mut v, "3 in hex is {:X}", 3);
1516
writeln!(&mut v, "2 + 1 = {:.4}", 3);
1617
writeln!(&mut v, "2 + 1 = {:5.4}", 3);

0 commit comments

Comments
 (0)