]> git.lizzy.rs Git - rust.git/blob - src/test/ui/lifetimes/lifetime-elision-return-type-requires-explicit-lifetime.rs
Auto merge of #54720 - davidtwco:issue-51191, r=nikomatsakis
[rust.git] / src / test / ui / lifetimes / lifetime-elision-return-type-requires-explicit-lifetime.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 // Lifetime annotation needed because we have no arguments.
12 fn f() -> &isize {    //~ ERROR missing lifetime specifier
13     panic!()
14 }
15
16 // Lifetime annotation needed because we have two by-reference parameters.
17 fn g(_x: &isize, _y: &isize) -> &isize {    //~ ERROR missing lifetime specifier
18     panic!()
19 }
20
21 struct Foo<'a> {
22     x: &'a isize,
23 }
24
25 // Lifetime annotation needed because we have two lifetimes: one as a parameter
26 // and one on the reference.
27 fn h(_x: &Foo) -> &isize { //~ ERROR missing lifetime specifier
28     panic!()
29 }
30
31 fn i(_x: isize) -> &isize { //~ ERROR missing lifetime specifier
32     panic!()
33 }
34
35 // Cases which used to work but now don't.
36
37 type StaticStr = &'static str; // hides 'static
38 trait WithLifetime<'a> {
39     type Output; // can hide 'a
40 }
41
42 // This worked because the type of the first argument contains
43 // 'static, although StaticStr doesn't even have parameters.
44 fn j(_x: StaticStr) -> &isize { //~ ERROR missing lifetime specifier
45     panic!()
46 }
47
48 // This worked because the compiler resolved the argument type
49 // to <T as WithLifetime<'a>>::Output which has the hidden 'a.
50 fn k<'a, T: WithLifetime<'a>>(_x: T::Output) -> &isize {
51 //~^ ERROR missing lifetime specifier
52     panic!()
53 }
54
55 fn main() {}