Skip to content

Commit 0b64a56

Browse files
authored
Rollup merge of #35106 - xen0n:issue-35082, r=alexcrichton
syntax_ext: format: fix ICE with bad named arguments Fixes #35082 by guarding against a new case of malformed invocation not previously covered. r? @alexcrichton
2 parents ce79972 + 2a41b31 commit 0b64a56

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/libsyntax_ext/format.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,9 @@ impl<'a, 'b> Context<'a, 'b> {
406406
let arg_idx = match arg_index_consumed.get_mut(i) {
407407
None => 0, // error already emitted elsewhere
408408
Some(offset) => {
409-
let arg_idx = self.arg_index_map[i][*offset];
409+
let ref idx_map = self.arg_index_map[i];
410+
// unwrap_or branch: error already emitted elsewhere
411+
let arg_idx = *idx_map.get(*offset).unwrap_or(&0);
410412
*offset += 1;
411413
arg_idx
412414
}

src/test/compile-fail/ifmt-bad-arg.rs

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ fn main() {
4141
//~^ ERROR invalid reference to argument `0` (no arguments given)
4242
//~^^ ERROR invalid reference to argument `1` (no arguments given)
4343

44+
// bad named arguments, #35082
45+
46+
format!("{valuea} {valueb}", valuea=5, valuec=7);
47+
//~^ ERROR there is no argument named `valueb`
48+
//~^^ ERROR named argument never used
49+
4450
// bad syntax of the format string
4551

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

0 commit comments

Comments
 (0)