]> git.lizzy.rs Git - rust.git/blob - src/test/ui/lifetimes/lifetime-doesnt-live-long-enough.rs
Auto merge of #54720 - davidtwco:issue-51191, r=nikomatsakis
[rust.git] / src / test / ui / lifetimes / lifetime-doesnt-live-long-enough.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 trait ListItem<'a> {
12     fn list_name() -> &'a str;
13 }
14
15 trait Collection { fn len(&self) -> usize; }
16
17 // is now well formed. RFC 2093
18 struct List<'a, T: ListItem<'a>> {
19     slice: &'a [T]
20 }
21
22 impl<'a, T: ListItem<'a>> Collection for List<'a, T> {
23     fn len(&self) -> usize {
24         0
25     }
26 }
27
28 struct Foo<T> {
29     foo: &'static T
30     //~^ ERROR may not live long enough
31 }
32
33 trait X<K>: Sized {
34     fn foo<'a, L: X<&'a Nested<K>>>();
35     //~^ ERROR may not live long enough
36
37     // check that we give a sane error for `Self`
38     fn bar<'a, L: X<&'a Nested<Self>>>();
39     //~^ ERROR may not live long enough
40
41     // check that we give a sane error for nested generics
42     fn baz<'a, L, M: X<&'a Nested<L>>>() {
43         //~^ ERROR may not live long enough
44     }
45 }
46
47 trait TraitB {}
48
49 struct Nested<K>(K);
50 impl<K> Nested<K> {
51     fn generic_in_parent<'a, L: X<&'a Nested<K>>>() {
52         //~^ ERROR may not live long enough
53     }
54     fn generic_in_child<'a, 'b, L: X<&'a Nested<M>>, M: 'b>() {
55         //~^ ERROR may not live long enough
56     }
57 }
58
59 fn main() {}