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.
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 // ignore-tidy-linelength
13 struct Foo<'x> { bar: isize }
14 fn foo1<'a>(x: &Foo) -> &'a isize {
15 //~^ HELP: consider using an explicit lifetime parameter as shown: fn foo1<'a>(x: &'a Foo) -> &'a isize
16 &x.bar //~ ERROR: cannot infer
19 fn foo2<'a, 'b>(x: &'a Foo) -> &'b isize {
20 //~^ HELP: consider using an explicit lifetime parameter as shown: fn foo2<'a>(x: &'a Foo) -> &'a isize
21 &x.bar //~ ERROR: cannot infer
24 fn foo3<'a>(x: &Foo) -> (&'a isize, &'a isize) {
25 //~^ HELP: consider using an explicit lifetime parameter as shown: fn foo3<'a>(x: &'a Foo) -> (&'a isize, &'a isize)
26 (&x.bar, &x.bar) //~ ERROR: cannot infer
27 //~^ ERROR: cannot infer
30 fn foo4<'a, 'b>(x: &'a Foo) -> (&'b isize, &'a isize, &'b isize) {
31 //~^ HELP: consider using an explicit lifetime parameter as shown: fn foo4<'a>(x: &'a Foo) -> (&'a isize, &'a isize, &'a isize)
32 (&x.bar, &x.bar, &x.bar) //~ ERROR: cannot infer
33 //~^ ERROR: cannot infer
36 struct Cat<'x, T> { cat: &'x isize, t: T }
37 struct Dog<'y> { dog: &'y isize }
39 fn cat2<'x, 'y>(x: Cat<'x, Dog<'y>>) -> &'x isize {
40 //~^ HELP: consider using an explicit lifetime parameter as shown: fn cat2<'x>(x: Cat<'x, Dog<'x>>) -> &'x isize
41 x.t.dog //~ ERROR: cannot infer
49 fn baz2<'b>(&self, x: &isize) -> (&'b isize, &'b isize) {
50 // The lifetime that gets assigned to `x` seems somewhat random.
51 // I have disabled this test for the time being. --pcwalton
52 (self.bar, x) //~ ERROR: cannot infer
53 //~^ ERROR: cannot infer