1
Fork 0

parser: Permit trailing +'s in bound lists

This commit is contained in:
Vadim Petrochenkov 2017-01-24 22:55:45 +03:00
parent 375cb2eec7
commit 65aeafa24f
8 changed files with 11 additions and 61 deletions

View file

@ -4003,14 +4003,7 @@ impl<'a> Parser<'a> {
break break
}} }}
// Trailing plus is not allowed for now and we have to detect it. if !self.eat(&token::BinOp(token::Plus)) {
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 {
break break
} }
} }
@ -4024,9 +4017,8 @@ impl<'a> Parser<'a> {
let mut lifetimes = Vec::new(); let mut lifetimes = Vec::new();
while let Some(lifetime) = self.eat_lifetime() { while let Some(lifetime) = self.eat_lifetime() {
lifetimes.push(lifetime); lifetimes.push(lifetime);
if self.check(&token::BinOp(token::Plus)) && self.look_ahead(1, |t| t.is_lifetime()) {
self.bump(); if !self.eat(&token::BinOp(token::Plus)) {
} else {
break break
} }
} }

View file

@ -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() {}

View file

@ -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() {}

View file

@ -16,6 +16,7 @@ type A where 'a: = u8; // OK
type A where 'a:, = u8; // OK type A where 'a:, = u8; // OK
type A where 'a: 'b + 'c = u8; // OK type A where 'a: 'b + 'c = u8; // OK
type A where = 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() {} fn main() {}

View file

@ -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<'a> fn(); // OK type A = for<'a> fn(); // OK
type A = for<> 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, 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() {} fn main() {}

View file

@ -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() {}

View file

@ -16,6 +16,8 @@ type A where T: = u8; // OK
type A where T:, = u8; // OK type A where T:, = u8; // OK
type A where T: Trait + Trait = u8; // OK type A where T: Trait + Trait = u8; // OK
type A where = 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() {} fn main() {}

View file

@ -16,8 +16,8 @@ struct S<
T: 'a, // OK T: 'a, // OK
T:, // OK T:, // OK
T: ?for<'a: 'b + 'c> Trait, // OK T: ?for<'a: 'b + 'c> Trait, // OK
T: Tr +, // OK
T: ?'a, //~ ERROR `?` may only modify trait bounds, not lifetime bounds T: ?'a, //~ ERROR `?` may only modify trait bounds, not lifetime bounds
T: Tr +, //~ ERROR expected one of `(`, `,`, `::`, `<`, `=`, or `>`, found `+`
>; >;
fn main() {} fn main() {}