]> git.lizzy.rs Git - rust.git/blob - src/test/ui/regions/regions-assoc-type-in-supertrait-outlives-container.rs
Auto merge of #57101 - o01eg:fix-57014, r=alexcrichton
[rust.git] / src / test / 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 ///////////////////////////////////////////////////////////////////////////
9
10 pub trait TheTrait {
11     type TheAssocType;
12 }
13
14 pub trait TheSubTrait : TheTrait {
15 }
16
17 pub struct TheType<'b> {
18     m: [fn(&'b()); 0]
19 }
20
21 impl<'b> TheTrait for TheType<'b> {
22     type TheAssocType = &'b ();
23 }
24
25 impl<'b> TheSubTrait for TheType<'b> {
26 }
27
28 ///////////////////////////////////////////////////////////////////////////
29
30 pub struct WithAssoc<T:TheSubTrait> {
31     m: [T; 0]
32 }
33
34 fn with_assoc<'a,'b>() {
35     // For this type to be valid, the rules require that all
36     // associated types of traits that appear in `WithAssoc` must
37     // outlive 'a. In this case, that means TheType<'b>::TheAssocType,
38     // which is &'b (), must outlive 'a.
39
40     // FIXME (#54943) NLL doesn't enforce WF condition in unreachable code if
41     // `_x` is changed to `_`
42     let _x: &'a WithAssoc<TheType<'b>> = loop { };
43     //~^ ERROR reference has a longer lifetime
44 }
45
46 fn main() {
47 }