]> git.lizzy.rs Git - rust.git/commitdiff
parser: Permit trailing +'s in bound lists
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Tue, 24 Jan 2017 19:55:45 +0000 (22:55 +0300)
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Tue, 24 Jan 2017 19:56:02 +0000 (22:56 +0300)
src/libsyntax/parse/parser.rs
src/test/parse-fail/bounds-lifetime-3.rs [deleted file]
src/test/parse-fail/bounds-lifetime-where-2.rs [deleted file]
src/test/parse-fail/bounds-lifetime-where.rs
src/test/parse-fail/bounds-lifetime.rs
src/test/parse-fail/bounds-type-where-1.rs [deleted file]
src/test/parse-fail/bounds-type-where.rs
src/test/parse-fail/bounds-type.rs

index 939f126640d99f1e6fb799b58e155ce22ee36ac6..9e3c1dcef8a6e465887520f66098a366f15c29f2 100644 (file)
@@ -4003,14 +4003,7 @@ fn parse_ty_param_bounds(&mut self) -> PResult<'a, TyParamBounds>
                 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 @@ fn parse_lt_param_bounds(&mut self) -> Vec<Lifetime> {
         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 (file)
index e044315..0000000
+++ /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 (file)
index ffcacdf..0000000
+++ /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() {}
index f7f56446006a5cb7601103e7a6f4d82347641e09..0a30818bc96aed0d5aa6fc3e5b76d0901c6915f4 100644 (file)
@@ -16,6 +16,7 @@
 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() {}
index 71547b543c3571f00eff5ff185d446314c4cfe2b..5113a6b4803fc058bd492dde93594b74146fe926 100644 (file)
@@ -16,8 +16,9 @@
 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 (file)
index 52b5035..0000000
+++ /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() {}
index 789a0934a83cb63a8f60b37c96d7479597f3acd4..9dc5d8277446da21481249c159983e2e0f6648ac 100644 (file)
@@ -16,6 +16,8 @@
 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() {}
index 6e339429eed33dfb719808f1d36ef87b1cd6c872..c224b44a14bf1fb7a94812a048fd08cff6dd660a 100644 (file)
@@ -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() {}