]> git.lizzy.rs Git - rust.git/blob - src/test/ui/lifetimes/lifetime-elision-return-type-requires-explicit-lifetime.rs
Rollup merge of #105555 - krasimirgg:llvm-int-opt-2, r=cuviper
[rust.git] / src / test / ui / lifetimes / lifetime-elision-return-type-requires-explicit-lifetime.rs
1 // Lifetime annotation needed because we have no arguments.
2 fn f() -> &isize {    //~ ERROR missing lifetime specifier
3     panic!()
4 }
5
6 // Lifetime annotation needed because we have two by-reference parameters.
7 fn g(_x: &isize, _y: &isize) -> &isize {    //~ ERROR missing lifetime specifier
8     panic!()
9 }
10
11 struct Foo<'a> {
12     x: &'a isize,
13 }
14
15 // Lifetime annotation needed because we have two lifetimes: one as a parameter
16 // and one on the reference.
17 fn h(_x: &Foo) -> &isize { //~ ERROR missing lifetime specifier
18     panic!()
19 }
20
21 fn i(_x: isize) -> &isize { //~ ERROR missing lifetime specifier
22     panic!()
23 }
24
25 // Cases which used to work but now don't.
26
27 type StaticStr = &'static str; // hides 'static
28 trait WithLifetime<'a> {
29     type Output; // can hide 'a
30 }
31
32 // This worked because the type of the first argument contains
33 // 'static, although StaticStr doesn't even have parameters.
34 fn j(_x: StaticStr) -> &isize { //~ ERROR missing lifetime specifier
35     panic!()
36 }
37
38 // This worked because the compiler resolved the argument type
39 // to <T as WithLifetime<'a>>::Output which has the hidden 'a.
40 fn k<'a, T: WithLifetime<'a>>(_x: T::Output) -> &isize {
41 //~^ ERROR missing lifetime specifier
42     panic!()
43 }
44
45 fn l<'a>(_: &'a str, _: &'a str) -> &str { "" }
46 //~^ ERROR missing lifetime specifier
47
48 // This is ok because both `'a` are for the same parameter.
49 fn m<'a>(_: &'a Foo<'a>) -> &str { "" }
50
51 fn main() {}