]> git.lizzy.rs Git - rust.git/blob - src/test/ui/regions/regions-assoc-type-in-supertrait-outlives-container.rs
Use the same message as type & const generics.
[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: migrate nll
7 //[nll]compile-flags: -Z borrowck=mir
8
9 // Since we are testing nll (and migration) explicitly as a separate
10 // revisions, don't worry about the --compare-mode=nll on this test.
11
12 // ignore-compare-mode-nll
13
14 #![allow(dead_code)]
15
16 pub trait TheTrait {
17     type TheAssocType;
18 }
19
20 pub trait TheSubTrait : TheTrait {
21 }
22
23 pub struct TheType<'b> {
24     m: [fn(&'b()); 0]
25 }
26
27 impl<'b> TheTrait for TheType<'b> {
28     type TheAssocType = &'b ();
29 }
30
31 impl<'b> TheSubTrait for TheType<'b> {
32 }
33
34 pub struct WithAssoc<T:TheSubTrait> {
35     m: [T; 0]
36 }
37
38 fn with_assoc<'a,'b>() {
39     // For this type to be valid, the rules require that all
40     // associated types of traits that appear in `WithAssoc` must
41     // outlive 'a. In this case, that means TheType<'b>::TheAssocType,
42     // which is &'b (), must outlive 'a.
43
44     let _: &'a WithAssoc<TheType<'b>> = loop { };
45     //[migrate]~^ ERROR reference has a longer lifetime
46     //[nll]~^^ ERROR lifetime may not live long enough
47 }
48
49 fn main() {
50 }