Skip to content

Commit 6c728e3

Browse files
committed
Parse (and discard) lifetime declarations on function types
1 parent ad8b437 commit 6c728e3

File tree

3 files changed

+43
-31
lines changed

3 files changed

+43
-31
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,12 @@ pub impl Parser {
307307
{
308308
/*
309309
310-
extern "ABI" [pure|unsafe] fn (S) -> T
311-
^~~~^ ^~~~~~~~~~~~^ ^~^ ^
312-
| | | |
313-
| | | Return type
314-
| | Argument types
315-
| |
310+
extern "ABI" [pure|unsafe] fn <'lt> (S) -> T
311+
^~~~^ ^~~~~~~~~~~~^ ^~~~^ ^~^ ^
312+
| | | | |
313+
| | | | Return type
314+
| | | Argument types
315+
| | Lifetimes
316316
| |
317317
| Purity
318318
ABI
@@ -333,12 +333,12 @@ pub impl Parser {
333333
{
334334
/*
335335
336-
(&|~|@) [r/] [pure|unsafe] [once] fn (S) -> T
337-
^~~~~~^ ^~~^ ^~~~~~~~~~~~^ ^~~~~^ ^~^ ^
338-
| | | | | |
339-
| | | | | Return type
340-
| | | | Argument types
341-
| | | |
336+
(&|~|@) [r/] [pure|unsafe] [once] fn <'lt> (S) -> T
337+
^~~~~~^ ^~~^ ^~~~~~~~~~~~^ ^~~~~^ ^~~~^ ^~^ ^
338+
| | | | | | |
339+
| | | | | | Return type
340+
| | | | | Argument types
341+
| | | | Lifetimes
342342
| | | Once-ness (a.k.a., affine)
343343
| | Purity
344344
| Lifetime bound
@@ -394,12 +394,24 @@ pub impl Parser {
394394
}
395395
396396
fn parse_ty_fn_decl() -> fn_decl {
397-
let inputs = do self.parse_unspanned_seq(
398-
token::LPAREN, token::RPAREN,
399-
seq_sep_trailing_disallowed(token::COMMA)) |p| {
397+
/*
400398
401-
p.parse_arg_general(false)
402-
};
399+
(fn) <'lt> (S) -> T
400+
^~~~^ ^~^ ^
401+
| | |
402+
| | Return type
403+
| Argument types
404+
Lifetimes
405+
406+
*/
407+
if self.eat(token::LT) {
408+
let _lifetimes = self.parse_lifetimes();
409+
self.expect(token::GT);
410+
}
411+
let inputs = self.parse_unspanned_seq(
412+
token::LPAREN, token::RPAREN,
413+
seq_sep_trailing_disallowed(token::COMMA),
414+
|p| p.parse_arg_general(false));
403415
let (ret_style, ret_ty) = self.parse_ret_ty();
404416
ast::fn_decl { inputs: inputs, output: ret_ty, cf: ret_style }
405417
}

src/test/compile-fail/regions-in-enums.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010

1111
enum yes0<'lt> {
1212
// This will eventually be legal (and in fact the only way):
13-
x3(&'lt uint) //~ ERROR named regions other than `self` are not allowed as part of a type declaration
13+
X3(&'lt uint) //~ ERROR named regions other than `self` are not allowed as part of a type declaration
1414
}
1515

1616
enum yes1 {
17-
x4(&'self uint)
17+
X4(&'self uint)
1818
}
1919

2020
enum yes2 {
21-
x5(&'foo uint) //~ ERROR named regions other than `self` are not allowed as part of a type declaration
21+
X5(&'foo uint) //~ ERROR named regions other than `self` are not allowed as part of a type declaration
2222
}
2323

2424
fn main() {}

src/test/compile-fail/regions-scoping.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010

1111
fn with<T>(t: T, f: fn(T)) { f(t) }
1212

13-
fn nested(x: &x/int) { // (1)
13+
fn nested<'x>(x: &'x int) { // (1)
1414
do with(
15-
fn&(x: &x/int, // Refers to the region `x` at (1)
16-
y: &y/int, // A fresh region `y` (2)
17-
z: fn(x: &x/int, // Refers to `x` at (1)
18-
y: &y/int, // Refers to `y` at (2)
19-
z: &z/int) -> &z/int) // A fresh region `z` (3)
15+
fn&(x: &'x int, // Refers to the region `x` at (1)
16+
y: &'y int, // A fresh region `y` (2)
17+
z: fn<'z>(x: &'x int, // Refers to `x` at (1)
18+
y: &'y int, // Refers to `y` at (2)
19+
z: &'z int) -> &'z int) // A fresh region `z` (3)
2020
-> &x/int {
2121

2222
if false { return z(x, y, x); }
@@ -29,13 +29,13 @@ fn nested(x: &x/int) { // (1)
2929
}
3030
) |foo| {
3131

32-
let a: &x/int = foo(x, x, |_x, _y, z| z );
33-
let b: &x/int = foo(x, a, |_x, _y, z| z );
34-
let c: &x/int = foo(a, a, |_x, _y, z| z );
32+
let a: &'x int = foo(x, x, |_x, _y, z| z );
33+
let b: &'x int = foo(x, a, |_x, _y, z| z );
34+
let c: &'x int = foo(a, a, |_x, _y, z| z );
3535

3636
let z = 3i;
37-
let d: &x/int = foo(x, x, |_x, _y, z| z );
38-
let e: &x/int = foo(x, &z, |_x, _y, z| z );
37+
let d: &'x int = foo(x, x, |_x, _y, z| z );
38+
let e: &'x int = foo(x, &z, |_x, _y, z| z );
3939

4040
// This would result in an error, but it is not reported by typeck
4141
// anymore but rather borrowck. Therefore, it doesn't end up

0 commit comments

Comments
 (0)