Skip to content

Commit b0dabce

Browse files
authored
Merge pull request #2963 from commandline/master
Fix regression in print_literal
2 parents e109639 + 9b11be7 commit b0dabce

File tree

5 files changed

+75
-71
lines changed

5 files changed

+75
-71
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/print_literal.stderr

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,87 @@
11
error: literal with an empty format string
2-
--> $DIR/print_literal.rs:23:71
2+
--> $DIR/print_literal.rs:24:71
33
|
4-
23 | println!("{} of {:b} people know binary, the other half doesn't", 1, 2);
4+
24 | println!("{} of {:b} people know binary, the other half doesn't", 1, 2);
55
| ^
66
|
77
= note: `-D print-literal` implied by `-D warnings`
88

99
error: literal with an empty format string
10-
--> $DIR/print_literal.rs:24:24
10+
--> $DIR/print_literal.rs:25:24
1111
|
12-
24 | print!("Hello {}", "world");
12+
25 | print!("Hello {}", "world");
1313
| ^^^^^^^
1414

1515
error: literal with an empty format string
16-
--> $DIR/print_literal.rs:25:36
16+
--> $DIR/print_literal.rs:26:36
1717
|
18-
25 | println!("Hello {} {}", world, "world");
18+
26 | println!("Hello {} {}", world, "world");
1919
| ^^^^^^^
2020

2121
error: literal with an empty format string
22-
--> $DIR/print_literal.rs:26:26
22+
--> $DIR/print_literal.rs:27:26
2323
|
24-
26 | println!("Hello {}", "world");
24+
27 | println!("Hello {}", "world");
2525
| ^^^^^^^
2626

2727
error: literal with an empty format string
28-
--> $DIR/print_literal.rs:27:30
28+
--> $DIR/print_literal.rs:28:30
2929
|
30-
27 | println!("10 / 4 is {}", 2.5);
30+
28 | println!("10 / 4 is {}", 2.5);
3131
| ^^^
3232

3333
error: literal with an empty format string
34-
--> $DIR/print_literal.rs:28:28
34+
--> $DIR/print_literal.rs:29:28
3535
|
36-
28 | println!("2 + 1 = {}", 3);
36+
29 | println!("2 + 1 = {}", 3);
3737
| ^
3838

3939
error: literal with an empty format string
40-
--> $DIR/print_literal.rs:33:25
40+
--> $DIR/print_literal.rs:34:25
4141
|
42-
33 | println!("{0} {1}", "hello", "world");
42+
34 | println!("{0} {1}", "hello", "world");
4343
| ^^^^^^^
4444

4545
error: literal with an empty format string
46-
--> $DIR/print_literal.rs:33:34
46+
--> $DIR/print_literal.rs:34:34
4747
|
48-
33 | println!("{0} {1}", "hello", "world");
48+
34 | println!("{0} {1}", "hello", "world");
4949
| ^^^^^^^
5050

5151
error: literal with an empty format string
52-
--> $DIR/print_literal.rs:34:25
52+
--> $DIR/print_literal.rs:35:25
5353
|
54-
34 | println!("{1} {0}", "hello", "world");
54+
35 | println!("{1} {0}", "hello", "world");
5555
| ^^^^^^^
5656

5757
error: literal with an empty format string
58-
--> $DIR/print_literal.rs:34:34
58+
--> $DIR/print_literal.rs:35:34
5959
|
60-
34 | println!("{1} {0}", "hello", "world");
60+
35 | println!("{1} {0}", "hello", "world");
6161
| ^^^^^^^
6262

6363
error: literal with an empty format string
64-
--> $DIR/print_literal.rs:37:33
64+
--> $DIR/print_literal.rs:38:33
6565
|
66-
37 | println!("{foo} {bar}", foo="hello", bar="world");
66+
38 | println!("{foo} {bar}", foo="hello", bar="world");
6767
| ^^^^^^^
6868

6969
error: literal with an empty format string
70-
--> $DIR/print_literal.rs:37:46
70+
--> $DIR/print_literal.rs:38:46
7171
|
72-
37 | println!("{foo} {bar}", foo="hello", bar="world");
72+
38 | println!("{foo} {bar}", foo="hello", bar="world");
7373
| ^^^^^^^
7474

7575
error: literal with an empty format string
76-
--> $DIR/print_literal.rs:38:33
76+
--> $DIR/print_literal.rs:39:33
7777
|
78-
38 | println!("{bar} {foo}", foo="hello", bar="world");
78+
39 | println!("{bar} {foo}", foo="hello", bar="world");
7979
| ^^^^^^^
8080

8181
error: literal with an empty format string
82-
--> $DIR/print_literal.rs:38:46
82+
--> $DIR/print_literal.rs:39:46
8383
|
84-
38 | println!("{bar} {foo}", foo="hello", bar="world");
84+
39 | println!("{bar} {foo}", foo="hello", bar="world");
8585
| ^^^^^^^
8686

8787
error: aborting due to 14 previous errors

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=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);

tests/ui/write_literal.stderr

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,87 @@
11
error: literal with an empty format string
2-
--> $DIR/write_literal.rs:26:79
2+
--> $DIR/write_literal.rs:27:79
33
|
4-
26 | writeln!(&mut v, "{} of {:b} people know binary, the other half doesn't", 1, 2);
4+
27 | writeln!(&mut v, "{} of {:b} people know binary, the other half doesn't", 1, 2);
55
| ^
66
|
77
= note: `-D write-literal` implied by `-D warnings`
88

99
error: literal with an empty format string
10-
--> $DIR/write_literal.rs:27:32
10+
--> $DIR/write_literal.rs:28:32
1111
|
12-
27 | write!(&mut v, "Hello {}", "world");
12+
28 | write!(&mut v, "Hello {}", "world");
1313
| ^^^^^^^
1414

1515
error: literal with an empty format string
16-
--> $DIR/write_literal.rs:28:44
16+
--> $DIR/write_literal.rs:29:44
1717
|
18-
28 | writeln!(&mut v, "Hello {} {}", world, "world");
18+
29 | writeln!(&mut v, "Hello {} {}", world, "world");
1919
| ^^^^^^^
2020

2121
error: literal with an empty format string
22-
--> $DIR/write_literal.rs:29:34
22+
--> $DIR/write_literal.rs:30:34
2323
|
24-
29 | writeln!(&mut v, "Hello {}", "world");
24+
30 | writeln!(&mut v, "Hello {}", "world");
2525
| ^^^^^^^
2626

2727
error: literal with an empty format string
28-
--> $DIR/write_literal.rs:30:38
28+
--> $DIR/write_literal.rs:31:38
2929
|
30-
30 | writeln!(&mut v, "10 / 4 is {}", 2.5);
30+
31 | writeln!(&mut v, "10 / 4 is {}", 2.5);
3131
| ^^^
3232

3333
error: literal with an empty format string
34-
--> $DIR/write_literal.rs:31:36
34+
--> $DIR/write_literal.rs:32:36
3535
|
36-
31 | writeln!(&mut v, "2 + 1 = {}", 3);
36+
32 | writeln!(&mut v, "2 + 1 = {}", 3);
3737
| ^
3838

3939
error: literal with an empty format string
40-
--> $DIR/write_literal.rs:36:33
40+
--> $DIR/write_literal.rs:37:33
4141
|
42-
36 | writeln!(&mut v, "{0} {1}", "hello", "world");
42+
37 | writeln!(&mut v, "{0} {1}", "hello", "world");
4343
| ^^^^^^^
4444

4545
error: literal with an empty format string
46-
--> $DIR/write_literal.rs:36:42
46+
--> $DIR/write_literal.rs:37:42
4747
|
48-
36 | writeln!(&mut v, "{0} {1}", "hello", "world");
48+
37 | writeln!(&mut v, "{0} {1}", "hello", "world");
4949
| ^^^^^^^
5050

5151
error: literal with an empty format string
52-
--> $DIR/write_literal.rs:37:33
52+
--> $DIR/write_literal.rs:38:33
5353
|
54-
37 | writeln!(&mut v, "{1} {0}", "hello", "world");
54+
38 | writeln!(&mut v, "{1} {0}", "hello", "world");
5555
| ^^^^^^^
5656

5757
error: literal with an empty format string
58-
--> $DIR/write_literal.rs:37:42
58+
--> $DIR/write_literal.rs:38:42
5959
|
60-
37 | writeln!(&mut v, "{1} {0}", "hello", "world");
60+
38 | writeln!(&mut v, "{1} {0}", "hello", "world");
6161
| ^^^^^^^
6262

6363
error: literal with an empty format string
64-
--> $DIR/write_literal.rs:40:41
64+
--> $DIR/write_literal.rs:41:41
6565
|
66-
40 | writeln!(&mut v, "{foo} {bar}", foo="hello", bar="world");
66+
41 | writeln!(&mut v, "{foo} {bar}", foo="hello", bar="world");
6767
| ^^^^^^^
6868

6969
error: literal with an empty format string
70-
--> $DIR/write_literal.rs:40:54
70+
--> $DIR/write_literal.rs:41:54
7171
|
72-
40 | writeln!(&mut v, "{foo} {bar}", foo="hello", bar="world");
72+
41 | writeln!(&mut v, "{foo} {bar}", foo="hello", bar="world");
7373
| ^^^^^^^
7474

7575
error: literal with an empty format string
76-
--> $DIR/write_literal.rs:41:41
76+
--> $DIR/write_literal.rs:42:41
7777
|
78-
41 | writeln!(&mut v, "{bar} {foo}", foo="hello", bar="world");
78+
42 | writeln!(&mut v, "{bar} {foo}", foo="hello", bar="world");
7979
| ^^^^^^^
8080

8181
error: literal with an empty format string
82-
--> $DIR/write_literal.rs:41:54
82+
--> $DIR/write_literal.rs:42:54
8383
|
84-
41 | writeln!(&mut v, "{bar} {foo}", foo="hello", bar="world");
84+
42 | writeln!(&mut v, "{bar} {foo}", foo="hello", bar="world");
8585
| ^^^^^^^
8686

8787
error: aborting due to 14 previous errors

0 commit comments

Comments
 (0)