Skip to content

Commit 277bf08

Browse files
Fix regression rust-lang#14007
1 parent e35330c commit 277bf08

3 files changed

+33
-16
lines changed

clippy_lints/src/literal_string_with_formatting_args.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ impl<'tcx> LateLintPass<'tcx> for LiteralStringWithFormattingArg {
128128
pos.start += diff_len;
129129
pos.end += diff_len;
130130

131-
let start = fmt_str[..pos.start].rfind('{').unwrap_or(pos.start);
131+
let mut start = pos.start;
132+
while start < fmt_str.len() && !fmt_str.is_char_boundary(start) {
133+
start += 1;
134+
}
135+
let start = fmt_str[..start].rfind('{').unwrap_or(start);
132136
// If this is a unicode character escape, we don't want to lint.
133137
if start > 1 && fmt_str[..start].ends_with("\\u") {
134138
continue;

tests/ui/literal_string_with_formatting_arg.rs

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ fn compiler_macro() {
1919
assert!(format!("{value}").is_ascii());
2020
}
2121

22+
// Regression test for <https://github.com/rust-lang/rust-clippy/issues/14007>.
23+
fn regression_14007() {
24+
let s = "{и}";
25+
let ш = 12;
26+
let s = "{ш}"; //~ literal_string_with_formatting_args
27+
}
28+
2229
fn main() {
2330
let x: Option<usize> = None;
2431
let y = "hello";
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,83 @@
11
error: this looks like a formatting argument but it is not part of a formatting macro
2-
--> tests/ui/literal_string_with_formatting_arg.rs:25:15
2+
--> tests/ui/literal_string_with_formatting_arg.rs:26:14
33
|
4-
LL | x.expect("{y} {}");
5-
| ^^^
4+
LL | let s = "{ш}";
5+
| ^^^
66
|
77
= note: `-D clippy::literal-string-with-formatting-args` implied by `-D warnings`
88
= help: to override `-D warnings` add `#[allow(clippy::literal_string_with_formatting_args)]`
99

1010
error: this looks like a formatting argument but it is not part of a formatting macro
11-
--> tests/ui/literal_string_with_formatting_arg.rs:26:16
11+
--> tests/ui/literal_string_with_formatting_arg.rs:32:15
12+
|
13+
LL | x.expect("{y} {}");
14+
| ^^^
15+
16+
error: this looks like a formatting argument but it is not part of a formatting macro
17+
--> tests/ui/literal_string_with_formatting_arg.rs:33:16
1218
|
1319
LL | x.expect(" {y} bla");
1420
| ^^^
1521

1622
error: this looks like a formatting argument but it is not part of a formatting macro
17-
--> tests/ui/literal_string_with_formatting_arg.rs:27:15
23+
--> tests/ui/literal_string_with_formatting_arg.rs:34:15
1824
|
1925
LL | x.expect("{:?}");
2026
| ^^^^
2127

2228
error: this looks like a formatting argument but it is not part of a formatting macro
23-
--> tests/ui/literal_string_with_formatting_arg.rs:28:15
29+
--> tests/ui/literal_string_with_formatting_arg.rs:35:15
2430
|
2531
LL | x.expect("{y:?}");
2632
| ^^^^^
2733

2834
error: these look like formatting arguments but are not part of a formatting macro
29-
--> tests/ui/literal_string_with_formatting_arg.rs:29:16
35+
--> tests/ui/literal_string_with_formatting_arg.rs:36:16
3036
|
3137
LL | x.expect(" {y:?} {y:?} ");
3238
| ^^^^^ ^^^^^
3339

3440
error: this looks like a formatting argument but it is not part of a formatting macro
35-
--> tests/ui/literal_string_with_formatting_arg.rs:30:23
41+
--> tests/ui/literal_string_with_formatting_arg.rs:37:23
3642
|
3743
LL | x.expect(" {y:..} {y:?} ");
3844
| ^^^^^
3945

4046
error: these look like formatting arguments but are not part of a formatting macro
41-
--> tests/ui/literal_string_with_formatting_arg.rs:31:16
47+
--> tests/ui/literal_string_with_formatting_arg.rs:38:16
4248
|
4349
LL | x.expect(r"{y:?} {y:?} ");
4450
| ^^^^^ ^^^^^
4551

4652
error: this looks like a formatting argument but it is not part of a formatting macro
47-
--> tests/ui/literal_string_with_formatting_arg.rs:32:16
53+
--> tests/ui/literal_string_with_formatting_arg.rs:39:16
4854
|
4955
LL | x.expect(r"{y:?} y:?}");
5056
| ^^^^^
5157

5258
error: these look like formatting arguments but are not part of a formatting macro
53-
--> tests/ui/literal_string_with_formatting_arg.rs:33:19
59+
--> tests/ui/literal_string_with_formatting_arg.rs:40:19
5460
|
5561
LL | x.expect(r##" {y:?} {y:?} "##);
5662
| ^^^^^ ^^^^^
5763

5864
error: this looks like a formatting argument but it is not part of a formatting macro
59-
--> tests/ui/literal_string_with_formatting_arg.rs:34:14
65+
--> tests/ui/literal_string_with_formatting_arg.rs:41:14
6066
|
6167
LL | assert!("{y}".is_ascii());
6268
| ^^^
6369

6470
error: this looks like a formatting argument but it is not part of a formatting macro
65-
--> tests/ui/literal_string_with_formatting_arg.rs:36:18
71+
--> tests/ui/literal_string_with_formatting_arg.rs:43:18
6672
|
6773
LL | x.expect("———{:?}");
6874
| ^^^^
6975

7076
error: this looks like a formatting argument but it is not part of a formatting macro
71-
--> tests/ui/literal_string_with_formatting_arg.rs:46:19
77+
--> tests/ui/literal_string_with_formatting_arg.rs:53:19
7278
|
7379
LL | x.expect(r##" {x:?} "##); // `x` doesn't exist so we shoud not lint
7480
| ^^^^^
7581

76-
error: aborting due to 12 previous errors
82+
error: aborting due to 13 previous errors
7783

0 commit comments

Comments
 (0)