]> git.lizzy.rs Git - rust.git/blob - src/test/ui/regions/regions-outlives-projection-container-wc.rs
Rollup merge of #57107 - mjbshaw:thread_local_test, r=nikomatsakis
[rust.git] / src / test / ui / regions / regions-outlives-projection-container-wc.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 // constraint is in a where clause not a bound. Issue #22246.
5
6 #![allow(dead_code)]
7
8 ///////////////////////////////////////////////////////////////////////////
9
10 pub trait TheTrait {
11     type TheAssocType;
12 }
13
14 pub struct TheType<'b> {
15     m: [fn(&'b()); 0]
16 }
17
18 impl<'b> TheTrait for TheType<'b> {
19     type TheAssocType = &'b ();
20 }
21
22 ///////////////////////////////////////////////////////////////////////////
23
24 pub struct WithAssoc<T> where T : TheTrait {
25     m: [T; 0]
26 }
27
28 fn with_assoc<'a,'b>() {
29     // For this type to be valid, the rules require that all
30     // associated types of traits that appear in `WithAssoc` must
31     // outlive 'a. In this case, that means TheType<'b>::TheAssocType,
32     // which is &'b (), must outlive 'a.
33
34     let _: &'a WithAssoc<TheType<'b>> = loop { };
35     //~^ ERROR reference has a longer lifetime
36 }
37
38 fn main() {
39 }