Skip to content

Commit

Permalink
rustc_parse_format: Fix character indices in find_skips
Browse files Browse the repository at this point in the history
Fixes #81006
  • Loading branch information
osa1 committed Jan 17, 2021
1 parent d51cf96 commit 9111e9d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/rustc_parse_format/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ fn find_skips_from_snippet(

fn find_skips(snippet: &str, is_raw: bool) -> Vec<usize> {
let mut eat_ws = false;
let mut s = snippet.chars().enumerate().peekable();
let mut s = snippet.char_indices().peekable();
let mut skips = vec![];
while let Some((pos, c)) = s.next() {
match (c, s.peek()) {
Expand Down
10 changes: 10 additions & 0 deletions src/test/ui/macros/issue-81006.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// check-fail

// First format below would cause a panic, second would generate error with incorrect span

fn main() {
let _ = format!("→{}→\n");
//~^ ERROR 1 positional argument in format string, but no arguments were given
let _ = format!("→{} \n");
//~^ ERROR 1 positional argument in format string, but no arguments were given
}
14 changes: 14 additions & 0 deletions src/test/ui/macros/issue-81006.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error: 1 positional argument in format string, but no arguments were given
--> $DIR/issue-81006.rs:6:23
|
LL | let _ = format!("→{}→\n");
| ^^

error: 1 positional argument in format string, but no arguments were given
--> $DIR/issue-81006.rs:8:23
|
LL | let _ = format!("→{} \n");
| ^^

error: aborting due to 2 previous errors

0 comments on commit 9111e9d

Please sign in to comment.