]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/lifetime-inference-give-expl-lifetime-param.rs
Auto merge of #22517 - brson:relnotes, r=Gankro
[rust.git] / src / test / compile-fail / lifetime-inference-give-expl-lifetime-param.rs
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.
4 //
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.
10
11 // ignore-tidy-linelength
12
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
17 }
18
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
22 }
23
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
28 }
29
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
34 }
35
36 struct Cat<'x, T> { cat: &'x isize, t: T }
37 struct Dog<'y> { dog: &'y isize }
38
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
42 }
43
44 struct Baz<'x> {
45     bar: &'x isize
46 }
47
48 impl<'a> Baz<'a> {
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
54     }
55 }
56
57 fn main() {}