]> git.lizzy.rs Git - rust.git/blob - tests/ui/regions/regions-assoc-type-in-supertrait-outlives-container.rs
internally change regions to be covariant
[rust.git] / tests / ui / regions / regions-assoc-type-in-supertrait-outlives-container.rs
1 // Test that we are imposing the requirement that every associated
2 // type of a bound that appears in the where clause on a struct must
3 // outlive the location in which the type appears, even when the
4 // associted type is in a supertype. Issue #22246.
5
6 #![allow(dead_code)]
7
8 pub trait TheTrait {
9     type TheAssocType;
10 }
11
12 pub trait TheSubTrait : TheTrait {
13 }
14
15 pub struct TheType<'b> {
16     m: [fn(&'b()); 0]
17 }
18
19 impl<'b> TheTrait for TheType<'b> {
20     type TheAssocType = &'b ();
21 }
22
23 impl<'b> TheSubTrait for TheType<'b> {
24 }
25
26 pub struct WithAssoc<T:TheSubTrait> {
27     m: [T; 0]
28 }
29
30 fn with_assoc<'a,'b>() {
31     // For this type to be valid, the rules require that all
32     // associated types of traits that appear in `WithAssoc` must
33     // outlive 'a. In this case, that means TheType<'b>::TheAssocType,
34     // which is &'b (), must outlive 'a.
35
36     let _: &'a WithAssoc<TheType<'b>> = loop { };
37     //~^ ERROR lifetime may not live long enough
38 }
39
40 fn main() {
41 }