]> git.proxmox.com Git - rustc.git/blame - src/test/ui/lifetimes/lifetime-doesnt-live-long-enough.rs
New upstream version 1.31.0~beta.4+dfsg1
[rustc.git] / src / test / ui / lifetimes / lifetime-doesnt-live-long-enough.rs
CommitLineData
1a4d82fc
JJ
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
9346a6ac 11trait ListItem<'a> {
1a4d82fc
JJ
12 fn list_name() -> &'a str;
13}
14
15trait Collection { fn len(&self) -> usize; }
16
0bf4aa26 17// is now well formed. RFC 2093
1a4d82fc 18struct List<'a, T: ListItem<'a>> {
e9174d1e 19 slice: &'a [T]
1a4d82fc 20}
ea8adc8c 21
1a4d82fc
JJ
22impl<'a, T: ListItem<'a>> Collection for List<'a, T> {
23 fn len(&self) -> usize {
24 0
25 }
26}
27
ea8adc8c
XL
28struct Foo<T> {
29 foo: &'static T
ff7c6d11 30 //~^ ERROR may not live long enough
ea8adc8c
XL
31}
32
33trait X<K>: Sized {
34 fn foo<'a, L: X<&'a Nested<K>>>();
ff7c6d11
XL
35 //~^ ERROR may not live long enough
36
ea8adc8c
XL
37 // check that we give a sane error for `Self`
38 fn bar<'a, L: X<&'a Nested<Self>>>();
ff7c6d11
XL
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 }
ea8adc8c
XL
45}
46
ff7c6d11
XL
47trait TraitB {}
48
ea8adc8c
XL
49struct Nested<K>(K);
50impl<K> Nested<K> {
51 fn generic_in_parent<'a, L: X<&'a Nested<K>>>() {
ff7c6d11 52 //~^ ERROR may not live long enough
ea8adc8c
XL
53 }
54 fn generic_in_child<'a, 'b, L: X<&'a Nested<M>>, M: 'b>() {
ff7c6d11 55 //~^ ERROR may not live long enough
ea8adc8c
XL
56 }
57}
58
1a4d82fc 59fn main() {}