Skip to content

Commit c7ca540

Browse files
authored
Rollup merge of #81071 - osa1:fix_81006, r=estebank
rustc_parse_format: Fix character indices in find_skips Fixes #81006
2 parents 090ab8c + 9111e9d commit c7ca540

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

compiler/rustc_parse_format/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ fn find_skips_from_snippet(
736736

737737
fn find_skips(snippet: &str, is_raw: bool) -> Vec<usize> {
738738
let mut eat_ws = false;
739-
let mut s = snippet.chars().enumerate().peekable();
739+
let mut s = snippet.char_indices().peekable();
740740
let mut skips = vec![];
741741
while let Some((pos, c)) = s.next() {
742742
match (c, s.peek()) {

src/test/ui/macros/issue-81006.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// check-fail
2+
3+
// First format below would cause a panic, second would generate error with incorrect span
4+
5+
fn main() {
6+
let _ = format!("→{}→\n");
7+
//~^ ERROR 1 positional argument in format string, but no arguments were given
8+
let _ = format!("→{} \n");
9+
//~^ ERROR 1 positional argument in format string, but no arguments were given
10+
}

src/test/ui/macros/issue-81006.stderr

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: 1 positional argument in format string, but no arguments were given
2+
--> $DIR/issue-81006.rs:6:23
3+
|
4+
LL | let _ = format!("→{}→\n");
5+
| ^^
6+
7+
error: 1 positional argument in format string, but no arguments were given
8+
--> $DIR/issue-81006.rs:8:23
9+
|
10+
LL | let _ = format!("→{} \n");
11+
| ^^
12+
13+
error: aborting due to 2 previous errors
14+

0 commit comments

Comments
 (0)