about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>2017-02-10 23:23:11 +0000
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>2017-02-10 23:58:18 +0000
commitb3d73995dac028f287604dbe763b236be154e787 (patch)
treef6817decd6ef225c839cfecefa7aadc0ca542721 /src
parentf80514426aaf59967e08f32ec44c1876cdeffe9d (diff)
downloadrust-b3d73995dac028f287604dbe763b236be154e787.tar.gz
rust-b3d73995dac028f287604dbe763b236be154e787.zip
Fix ICE on certain sequence repetitions.
Diffstat (limited to 'src')
-rw-r--r--src/libsyntax/parse/parser.rs19
-rw-r--r--src/test/compile-fail/issue-39709.rs15
2 files changed, 29 insertions, 5 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index b051928ff9d..2c4fa8e15ed 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -302,11 +302,20 @@ impl<'a> Parser<'a> {
                 if i + 1 < tts.len() {
                     self.tts.push((tts, i + 1));
                 }
-                if let TokenTree::Token(sp, tok) = tt {
-                    TokenAndSpan { tok: tok, sp: sp }
-                } else {
-                    self.tts.push((tt, 0));
-                    continue
+                // FIXME(jseyfried): remove after fixing #39390 in #39419.
+                if self.quote_depth > 0 {
+                    if let TokenTree::Sequence(sp, _) = tt {
+                        self.span_err(sp, "attempted to repeat an expression containing no \
+                                           syntax variables matched as repeating at this depth");
+                    }
+                }
+                match tt {
+                    TokenTree::Token(sp, tok) => TokenAndSpan { tok: tok, sp: sp },
+                    _ if tt.len() > 0 => {
+                        self.tts.push((tt, 0));
+                        continue
+                    }
+                    _ => continue,
                 }
             } else {
                 TokenAndSpan { tok: token::Eof, sp: self.span }
diff --git a/src/test/compile-fail/issue-39709.rs b/src/test/compile-fail/issue-39709.rs
new file mode 100644
index 00000000000..0f66fe84393
--- /dev/null
+++ b/src/test/compile-fail/issue-39709.rs
@@ -0,0 +1,15 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn main() {
+    println!("{}", { macro_rules! x { ($()*) => {} } 33 });
+    //~^ ERROR no syntax variables matched as repeating at this depth
+}
+