Skip to content

Commit

Permalink
Rollup merge of rust-lang#35106 - xen0n:issue-35082, r=alexcrichton
Browse files Browse the repository at this point in the history
syntax_ext: format: fix ICE with bad named arguments

Fixes rust-lang#35082 by guarding against a new case of malformed invocation not previously covered.

r? @alexcrichton
  • Loading branch information
Manishearth authored Jul 30, 2016
2 parents ce79972 + 2a41b31 commit 0b64a56
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/libsyntax_ext/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,9 @@ impl<'a, 'b> Context<'a, 'b> {
let arg_idx = match arg_index_consumed.get_mut(i) {
None => 0, // error already emitted elsewhere
Some(offset) => {
let arg_idx = self.arg_index_map[i][*offset];
let ref idx_map = self.arg_index_map[i];
// unwrap_or branch: error already emitted elsewhere
let arg_idx = *idx_map.get(*offset).unwrap_or(&0);
*offset += 1;
arg_idx
}
Expand Down
6 changes: 6 additions & 0 deletions src/test/compile-fail/ifmt-bad-arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ fn main() {
//~^ ERROR invalid reference to argument `0` (no arguments given)
//~^^ ERROR invalid reference to argument `1` (no arguments given)

// bad named arguments, #35082

format!("{valuea} {valueb}", valuea=5, valuec=7);
//~^ ERROR there is no argument named `valueb`
//~^^ ERROR named argument never used

// bad syntax of the format string

format!("{"); //~ ERROR: expected `'}'` but string was terminated
Expand Down

0 comments on commit 0b64a56

Please sign in to comment.