about summary refs log tree commit diff
diff options
context:
space:
mode:
authorWang Xuerui <idontknw.wang@gmail.com>2016-07-29 16:40:10 +0800
committerWang Xuerui <idontknw.wang@gmail.com>2016-07-29 16:40:10 +0800
commit2a41b31a88356d5a772cb644ab8d29af0bf44742 (patch)
tree9a54f52e40d90eb3eefcfd0730637eb1b85daee7
parentd9a911d236cbecb47775276ba51a5f9111bdbc9c (diff)
downloadrust-2a41b31a88356d5a772cb644ab8d29af0bf44742.tar.gz
rust-2a41b31a88356d5a772cb644ab8d29af0bf44742.zip
syntax_ext: format: fix ICE with bad named arguments
-rw-r--r--src/libsyntax_ext/format.rs4
-rw-r--r--src/test/compile-fail/ifmt-bad-arg.rs6
2 files changed, 9 insertions, 1 deletions
diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs
index 94bb78edaac..1f6f57c70f7 100644
--- a/src/libsyntax_ext/format.rs
+++ b/src/libsyntax_ext/format.rs
@@ -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
                                 }
diff --git a/src/test/compile-fail/ifmt-bad-arg.rs b/src/test/compile-fail/ifmt-bad-arg.rs
index 272ad980feb..59c61a42e07 100644
--- a/src/test/compile-fail/ifmt-bad-arg.rs
+++ b/src/test/compile-fail/ifmt-bad-arg.rs
@@ -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