Skip to content

Commit 65aeafa

Browse files
committed
parser: Permit trailing +'s in bound lists
1 parent 375cb2e commit 65aeafa

8 files changed

+11
-61
lines changed

src/libsyntax/parse/parser.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -4003,14 +4003,7 @@ impl<'a> Parser<'a> {
40034003
break
40044004
}}
40054005

4006-
// Trailing plus is not allowed for now and we have to detect it.
4007-
let is_bound_start = |token: &token::Token| {
4008-
token == &token::Question || token.is_lifetime() ||
4009-
token.is_keyword(keywords::For) || token.is_path_start()
4010-
};
4011-
if self.check(&token::BinOp(token::Plus)) && self.look_ahead(1, is_bound_start) {
4012-
self.bump();
4013-
} else {
4006+
if !self.eat(&token::BinOp(token::Plus)) {
40144007
break
40154008
}
40164009
}
@@ -4024,9 +4017,8 @@ impl<'a> Parser<'a> {
40244017
let mut lifetimes = Vec::new();
40254018
while let Some(lifetime) = self.eat_lifetime() {
40264019
lifetimes.push(lifetime);
4027-
if self.check(&token::BinOp(token::Plus)) && self.look_ahead(1, |t| t.is_lifetime()) {
4028-
self.bump();
4029-
} else {
4020+
4021+
if !self.eat(&token::BinOp(token::Plus)) {
40304022
break
40314023
}
40324024
}

src/test/parse-fail/bounds-lifetime-3.rs

-15
This file was deleted.

src/test/parse-fail/bounds-lifetime-where-2.rs

-15
This file was deleted.

src/test/parse-fail/bounds-lifetime-where.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type A where 'a: = u8; // OK
1616
type A where 'a:, = u8; // OK
1717
type A where 'a: 'b + 'c = u8; // OK
1818
type A where = u8; // OK
19-
type A where 'a: 'b + = u8; //~ ERROR expected one of `,` or `=`, found `+`
19+
type A where 'a: 'b + = u8; // OK
20+
type A where , = u8; //~ ERROR expected one of `=`, lifetime, or type, found `,`
2021

2122
fn main() {}

src/test/parse-fail/bounds-lifetime.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ type A = for<'a:> fn(); // OK
1616
type A = for<'a:,> fn(); // OK
1717
type A = for<'a> fn(); // OK
1818
type A = for<> fn(); // OK
19+
type A = for<'a: 'b +> fn(); // OK
1920

2021
type A = for<'a, T> fn(); //~ ERROR only lifetime parameters can be used in this context
21-
type A = for<'a: 'b +> fn(); //~ ERROR expected one of `,` or `>`, found `+`
22+
type A = for<,> fn(); //~ ERROR expected one of `>`, identifier, or lifetime, found `,`
2223

2324
fn main() {}

src/test/parse-fail/bounds-type-where-1.rs

-16
This file was deleted.

src/test/parse-fail/bounds-type-where.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ type A where T: = u8; // OK
1616
type A where T:, = u8; // OK
1717
type A where T: Trait + Trait = u8; // OK
1818
type A where = u8; // OK
19-
type A where T: Trait + = u8; //~ ERROR expected one of `(`, `,`, `::`, `<`, or `=`, found `+`
19+
type A where T: Trait + = u8; // OK
20+
type A where T, = u8;
21+
//~^ ERROR expected one of `!`, `(`, `+`, `::`, `:`, `<`, `==`, or `=`, found `,`
2022

2123
fn main() {}

src/test/parse-fail/bounds-type.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ struct S<
1616
T: 'a, // OK
1717
T:, // OK
1818
T: ?for<'a: 'b + 'c> Trait, // OK
19+
T: Tr +, // OK
1920
T: ?'a, //~ ERROR `?` may only modify trait bounds, not lifetime bounds
20-
T: Tr +, //~ ERROR expected one of `(`, `,`, `::`, `<`, `=`, or `>`, found `+`
2121
>;
2222

2323
fn main() {}

0 commit comments

Comments
 (0)