From 65aeafa24f1542c23643a67172b7b2fec4f290cc Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Tue, 24 Jan 2017 22:55:45 +0300 Subject: [PATCH] parser: Permit trailing +'s in bound lists --- src/libsyntax/parse/parser.rs | 14 +++----------- src/test/parse-fail/bounds-lifetime-3.rs | 15 --------------- src/test/parse-fail/bounds-lifetime-where-2.rs | 15 --------------- src/test/parse-fail/bounds-lifetime-where.rs | 3 ++- src/test/parse-fail/bounds-lifetime.rs | 3 ++- src/test/parse-fail/bounds-type-where-1.rs | 16 ---------------- src/test/parse-fail/bounds-type-where.rs | 4 +++- src/test/parse-fail/bounds-type.rs | 2 +- 8 files changed, 11 insertions(+), 61 deletions(-) delete mode 100644 src/test/parse-fail/bounds-lifetime-3.rs delete mode 100644 src/test/parse-fail/bounds-lifetime-where-2.rs delete mode 100644 src/test/parse-fail/bounds-type-where-1.rs 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 or the MIT license -// , 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 or the MIT license -// , 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 or the MIT license -// , 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() {}