Rollup merge of #81071 - osa1:fix_81006, r=estebank

rustc_parse_format: Fix character indices in find_skips

Fixes #81006
This commit is contained in:
Ashley Mannix 2021-01-18 21:53:24 +10:00 committed by GitHub
commit c7ca540da2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 1 deletions

View File

@ -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()) {

View File

@ -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
}

View File

@ -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