Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustc_parse_format: Fix character indices in find_skips #81071

Merged
merged 1 commit into from
Jan 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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