2 // Check that lifetime resolver enforces the lifetime name scoping
3 // rules correctly in various scenarios.
11 fn m1(&self, arg: &'a isize) { }
13 fn m3(&self, arg: Foo<'a>) { }
16 fn m4(&self, arg: &'b isize) { } //~ ERROR undeclared lifetime
17 fn m5(&'b self) { } //~ ERROR undeclared lifetime
18 fn m6(&self, arg: Foo<'b>) { } //~ ERROR undeclared lifetime
21 fn bar<'a>(x: &'a isize) {
22 // &'a is visible to code:
25 // &'a is not visible to *items*:
26 type X = Option<&'a isize>; //~ ERROR can't use generic parameters from outer item
28 E1(&'a isize) //~ ERROR can't use generic parameters from outer item
31 f: &'a isize //~ ERROR can't use generic parameters from outer item
33 fn f(a: &'a isize) { } //~ ERROR can't use generic parameters from outer item
35 // &'a CAN be declared on functions and used then:
36 fn g<'a>(a: &'a isize) { } // OK
37 fn h(a: Box<dyn for<'a> FnOnce(&'a isize)>) { } // OK
40 // Test nesting of lifetimes in fn type declarations
41 fn fn_types(a: &'a isize, //~ ERROR undeclared lifetime
42 b: Box<dyn for<'a> FnOnce(&'a isize,
43 &'b isize, //~ ERROR undeclared lifetime
44 Box<dyn for<'b> FnOnce(&'a isize,
46 &'b isize)>, //~ ERROR undeclared lifetime
47 c: &'a isize) //~ ERROR undeclared lifetime
53 async fn buggy(&self) -> &'a str { //~ ERROR use of undeclared lifetime name `'a`