]> git.proxmox.com Git - rustc.git/blob - tests/ui/regions/regions-outlives-projection-container-wc.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / tests / 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 pub trait TheTrait {
9 type TheAssocType;
10 }
11
12 pub struct TheType<'b> {
13 m: [fn(&'b()); 0]
14 }
15
16 impl<'b> TheTrait for TheType<'b> {
17 type TheAssocType = &'b ();
18 }
19
20 pub struct WithAssoc<T> where T : TheTrait {
21 m: [T; 0]
22 }
23
24 fn with_assoc<'a,'b>() {
25 // For this type to be valid, the rules require that all
26 // associated types of traits that appear in `WithAssoc` must
27 // outlive 'a. In this case, that means TheType<'b>::TheAssocType,
28 // which is &'b (), must outlive 'a.
29
30 let _: &'a WithAssoc<TheType<'b>> = loop { };
31 //~^ ERROR lifetime may not live long enough
32 }
33
34 fn main() {
35 }