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