]> git.proxmox.com Git - rustc.git/blob - src/test/ui/regions/regions-name-undeclared.rs
New upstream version 1.37.0+dfsg1
[rustc.git] / src / test / ui / regions / regions-name-undeclared.rs
1 // Check that lifetime resolver enforces the lifetime name scoping
2 // rules correctly in various scenarios.
3
4 struct Foo<'a> {
5 x: &'a isize
6 }
7
8 impl<'a> Foo<'a> {
9 // &'a is inherited:
10 fn m1(&self, arg: &'a isize) { }
11 fn m2(&'a self) { }
12 fn m3(&self, arg: Foo<'a>) { }
13
14 // &'b is not:
15 fn m4(&self, arg: &'b isize) { } //~ ERROR undeclared lifetime
16 fn m5(&'b self) { } //~ ERROR undeclared lifetime
17 fn m6(&self, arg: Foo<'b>) { } //~ ERROR undeclared lifetime
18 }
19
20 fn bar<'a>(x: &'a isize) {
21 // &'a is visible to code:
22 let y: &'a isize = x;
23
24 // &'a is not visible to *items*:
25 type X = Option<&'a isize>; //~ ERROR undeclared lifetime
26 enum E {
27 E1(&'a isize) //~ ERROR undeclared lifetime
28 }
29 struct S {
30 f: &'a isize //~ ERROR undeclared lifetime
31 }
32 fn f(a: &'a isize) { } //~ ERROR undeclared lifetime
33
34 // &'a CAN be declared on functions and used then:
35 fn g<'a>(a: &'a isize) { } // OK
36 fn h(a: Box<dyn for<'a> FnOnce(&'a isize)>) { } // OK
37 }
38
39 // Test nesting of lifetimes in fn type declarations
40 fn fn_types(a: &'a isize, //~ ERROR undeclared lifetime
41 b: Box<dyn for<'a> FnOnce(&'a isize,
42 &'b isize, //~ ERROR undeclared lifetime
43 Box<dyn for<'b> FnOnce(&'a isize,
44 &'b isize)>,
45 &'b isize)>, //~ ERROR undeclared lifetime
46 c: &'a isize) //~ ERROR undeclared lifetime
47 {
48 }
49
50 pub fn main() {}