1 // Copyright 2012-2013 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.
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.
11 // Check that lifetime resolver enforces the lifetime name scoping
12 // rules correctly in various scenarios.
20 fn m1(&self, arg: &'a int) { }
22 fn m3(&self, arg: Foo<'a>) { }
25 fn m4(&self, arg: &'b int) { } //~ ERROR undeclared lifetime
26 fn m5(&'b self) { } //~ ERROR undeclared lifetime
27 fn m6(&self, arg: Foo<'b>) { } //~ ERROR undeclared lifetime
30 fn bar<'a>(x: &'a int) {
31 // &'a is visible to code:
34 // &'a is not visible to *items*:
35 type X = Option<&'a int>; //~ ERROR undeclared lifetime
37 E1(&'a int) //~ ERROR undeclared lifetime
40 f: &'a int //~ ERROR undeclared lifetime
42 fn f(a: &'a int) { } //~ ERROR undeclared lifetime
44 // &'a CAN be declared on functions and used then:
45 fn g<'a>(a: &'a int) { } // OK
46 fn h(a: for<'a>|&'a int|) { } // OK
48 // But not in the bound of a closure, it's not in scope *there*
49 fn i(a: for<'a>|&int|:'a) { } //~ ERROR undeclared lifetime
52 // Test nesting of lifetimes in fn type declarations
53 fn fn_types(a: &'a int, //~ ERROR undeclared lifetime
54 b: for<'a>|a: &'a int,
55 b: &'b int, //~ ERROR undeclared lifetime
56 c: for<'b>|a: &'a int,
58 d: &'b int|, //~ ERROR undeclared lifetime
59 c: &'a int) //~ ERROR undeclared lifetime