Skip to content

Commit 1246798

Browse files
committed
auto merge of #14389 : Ryman/rust/14303, r=alexcrichton
Closes #14303.
2 parents 6cf4301 + da663cc commit 1246798

8 files changed

+107
-1
lines changed

src/libsyntax/parse/parser.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -3425,6 +3425,7 @@ impl<'a> Parser<'a> {
34253425
let lifetimes = self.parse_lifetimes();
34263426
let mut seen_default = false;
34273427
let ty_params = self.parse_seq_to_gt(Some(token::COMMA), |p| {
3428+
p.forbid_lifetime();
34283429
let ty_param = p.parse_ty_param();
34293430
if ty_param.default.is_some() {
34303431
seen_default = true;
@@ -3444,10 +3445,21 @@ impl<'a> Parser<'a> {
34443445
let lifetimes = self.parse_lifetimes();
34453446
let result = self.parse_seq_to_gt(
34463447
Some(token::COMMA),
3447-
|p| p.parse_ty(false));
3448+
|p| {
3449+
p.forbid_lifetime();
3450+
p.parse_ty(false)
3451+
}
3452+
);
34483453
(lifetimes, result.into_vec())
34493454
}
34503455

3456+
fn forbid_lifetime(&mut self) {
3457+
if Parser::token_is_lifetime(&self.token) {
3458+
self.span_fatal(self.span, "lifetime parameters must be declared \
3459+
prior to type parameters");
3460+
}
3461+
}
3462+
34513463
fn parse_fn_args(&mut self, named_args: bool, allow_variadic: bool)
34523464
-> (Vec<Arg> , bool) {
34533465
let sp = self.span;
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
enum X<'a, T, 'b> {
12+
//~^ ERROR lifetime parameters must be declared prior to type parameters
13+
A(&'a T)
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn foo<'a, T, 'b>(x: &'a T) {}
12+
//~^ ERROR lifetime parameters must be declared prior to type parameters
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
range(0, 4)
13+
.map(|x| x * 2)
14+
.collect::<Vec<'a, uint, 'b>>()
15+
//~^ ERROR lifetime parameters must be declared prior to type parameters
16+
}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct X { x: int }
12+
13+
impl<'a, T, 'b> X {}
14+
//~^ ERROR lifetime parameters must be declared prior to type parameters
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn bar<'a, T>(x: mymodule::X<'a, T, 'b, 'c>) {}
12+
//~^ ERROR lifetime parameters must be declared prior to type parameters
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct X<'a, T, 'b> {
12+
//~^ ERROR lifetime parameters must be declared prior to type parameters
13+
x: &'a T
14+
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
trait Foo<'a, T, 'b> {}
12+
//~^ ERROR lifetime parameters must be declared prior to type parameters

0 commit comments

Comments
 (0)