syntax_ext: format: fix ICE with bad named arguments

This commit is contained in:
Wang Xuerui 2016-07-29 16:40:10 +08:00
parent d9a911d236
commit 2a41b31a88
No known key found for this signature in database
GPG Key ID: 78396CEF692310EC
2 changed files with 9 additions and 1 deletions

View File

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

View File

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