Skip to content

Commit

Permalink
Rollup merge of rust-lang#81071 - osa1:fix_81006, r=estebank
Browse files Browse the repository at this point in the history
rustc_parse_format: Fix character indices in find_skips

Fixes rust-lang#81006
  • Loading branch information
m-ou-se committed Jan 17, 2021
2 parents ed10e8f + 28501c0 commit c36acae
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/issues/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/issues/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 c36acae

Please sign in to comment.