about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2017-01-24 22:55:45 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2017-01-24 22:56:02 +0300
commit65aeafa24f1542c23643a67172b7b2fec4f290cc (patch)
tree92464a7e8ce69e08cc98ab7bb211d4ba4cda45a1 /src
parent375cb2eec70f239b477c6b88852c8258765b5420 (diff)
downloadrust-65aeafa24f1542c23643a67172b7b2fec4f290cc.tar.gz
rust-65aeafa24f1542c23643a67172b7b2fec4f290cc.zip
parser: Permit trailing +'s in bound lists
Diffstat (limited to 'src')
-rw-r--r--src/libsyntax/parse/parser.rs14
-rw-r--r--src/test/parse-fail/bounds-lifetime-3.rs15
-rw-r--r--src/test/parse-fail/bounds-lifetime-where-2.rs15
-rw-r--r--src/test/parse-fail/bounds-lifetime-where.rs3
-rw-r--r--src/test/parse-fail/bounds-lifetime.rs3
-rw-r--r--src/test/parse-fail/bounds-type-where-1.rs16
-rw-r--r--src/test/parse-fail/bounds-type-where.rs4
-rw-r--r--src/test/parse-fail/bounds-type.rs2
8 files changed, 11 insertions, 61 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 939f126640d..9e3c1dcef8a 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -4003,14 +4003,7 @@ impl<'a> Parser<'a> {
                 break
             }}
 
-            // Trailing plus is not allowed for now and we have to detect it.
-            let is_bound_start = |token: &token::Token| {
-                token == &token::Question || token.is_lifetime() ||
-                token.is_keyword(keywords::For) || token.is_path_start()
-            };
-            if self.check(&token::BinOp(token::Plus)) && self.look_ahead(1, is_bound_start) {
-                self.bump();
-            } else {
+            if !self.eat(&token::BinOp(token::Plus)) {
                 break
             }
         }
@@ -4024,9 +4017,8 @@ impl<'a> Parser<'a> {
         let mut lifetimes = Vec::new();
         while let Some(lifetime) = self.eat_lifetime() {
             lifetimes.push(lifetime);
-            if self.check(&token::BinOp(token::Plus)) && self.look_ahead(1, |t| t.is_lifetime()) {
-                self.bump();
-            } else {
+
+            if !self.eat(&token::BinOp(token::Plus)) {
                 break
             }
         }
diff --git a/src/test/parse-fail/bounds-lifetime-3.rs b/src/test/parse-fail/bounds-lifetime-3.rs
deleted file mode 100644
index e0443159815..00000000000
--- a/src/test/parse-fail/bounds-lifetime-3.rs
+++ /dev/null
@@ -1,15 +0,0 @@
-// 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.
-
-// compile-flags: -Z parse-only
-
-type A = for<,> fn(); //~ ERROR expected one of `>`, identifier, or lifetime, found `,`
-
-fn main() {}
diff --git a/src/test/parse-fail/bounds-lifetime-where-2.rs b/src/test/parse-fail/bounds-lifetime-where-2.rs
deleted file mode 100644
index ffcacdf357d..00000000000
--- a/src/test/parse-fail/bounds-lifetime-where-2.rs
+++ /dev/null
@@ -1,15 +0,0 @@
-// 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.
-
-// compile-flags: -Z parse-only
-
-type A where , = u8; //~ ERROR expected one of `=`, lifetime, or type, found `,`
-
-fn main() {}
diff --git a/src/test/parse-fail/bounds-lifetime-where.rs b/src/test/parse-fail/bounds-lifetime-where.rs
index f7f56446006..0a30818bc96 100644
--- a/src/test/parse-fail/bounds-lifetime-where.rs
+++ b/src/test/parse-fail/bounds-lifetime-where.rs
@@ -16,6 +16,7 @@ type A where 'a: = u8; // OK
 type A where 'a:, = u8; // OK
 type A where 'a: 'b + 'c = u8; // OK
 type A where = u8; // OK
-type A where 'a: 'b + = u8; //~ ERROR expected one of `,` or `=`, found `+`
+type A where 'a: 'b + = u8; // OK
+type A where , = u8; //~ ERROR expected one of `=`, lifetime, or type, found `,`
 
 fn main() {}
diff --git a/src/test/parse-fail/bounds-lifetime.rs b/src/test/parse-fail/bounds-lifetime.rs
index 71547b543c3..5113a6b4803 100644
--- a/src/test/parse-fail/bounds-lifetime.rs
+++ b/src/test/parse-fail/bounds-lifetime.rs
@@ -16,8 +16,9 @@ type A = for<'a:> fn(); // OK
 type A = for<'a:,> fn(); // OK
 type A = for<'a> fn(); // OK
 type A = for<> fn(); // OK
+type A = for<'a: 'b +> fn(); // OK
 
 type A = for<'a, T> fn(); //~ ERROR only lifetime parameters can be used in this context
-type A = for<'a: 'b +> fn(); //~ ERROR expected one of `,` or `>`, found `+`
+type A = for<,> fn(); //~ ERROR expected one of `>`, identifier, or lifetime, found `,`
 
 fn main() {}
diff --git a/src/test/parse-fail/bounds-type-where-1.rs b/src/test/parse-fail/bounds-type-where-1.rs
deleted file mode 100644
index 52b5035abda..00000000000
--- a/src/test/parse-fail/bounds-type-where-1.rs
+++ /dev/null
@@ -1,16 +0,0 @@
-// 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.
-
-// compile-flags: -Z parse-only
-
-type A where T, = u8;
-//~^ ERROR expected one of `!`, `(`, `+`, `::`, `:`, `<`, `==`, or `=`, found `,`
-
-fn main() {}
diff --git a/src/test/parse-fail/bounds-type-where.rs b/src/test/parse-fail/bounds-type-where.rs
index 789a0934a83..9dc5d827744 100644
--- a/src/test/parse-fail/bounds-type-where.rs
+++ b/src/test/parse-fail/bounds-type-where.rs
@@ -16,6 +16,8 @@ type A where T: = u8; // OK
 type A where T:, = u8; // OK
 type A where T: Trait + Trait = u8; // OK
 type A where = u8; // OK
-type A where T: Trait + = u8; //~ ERROR expected one of `(`, `,`, `::`, `<`, or `=`, found `+`
+type A where T: Trait + = u8; // OK
+type A where T, = u8;
+//~^ ERROR expected one of `!`, `(`, `+`, `::`, `:`, `<`, `==`, or `=`, found `,`
 
 fn main() {}
diff --git a/src/test/parse-fail/bounds-type.rs b/src/test/parse-fail/bounds-type.rs
index 6e339429eed..c224b44a14b 100644
--- a/src/test/parse-fail/bounds-type.rs
+++ b/src/test/parse-fail/bounds-type.rs
@@ -16,8 +16,8 @@ struct S<
     T: 'a, // OK
     T:, // OK
     T: ?for<'a: 'b + 'c> Trait, // OK
+    T: Tr +, // OK
     T: ?'a, //~ ERROR `?` may only modify trait bounds, not lifetime bounds
-    T: Tr +, //~ ERROR expected one of `(`, `,`, `::`, `<`, `=`, or `>`, found `+`
 >;
 
 fn main() {}