]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/regions-assoc-type-in-supertrait-outlives-container.rs
Auto merge of #22517 - brson:relnotes, r=Gankro
[rust.git] / src / test / compile-fail / regions-assoc-type-in-supertrait-outlives-container.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Test that we are imposing the requirement that every associated
12 // type of a bound that appears in the where clause on a struct must
13 // outlive the location in which the type appears, even when the
14 // associted type is in a supertype. Issue #22246.
15
16 #![allow(dead_code)]
17
18 use std::mem::transmute;
19 use std::ops::Deref;
20
21 ///////////////////////////////////////////////////////////////////////////
22
23 pub trait TheTrait {
24     type TheAssocType;
25
26     fn dummy(&self) { }
27 }
28
29 pub trait TheSubTrait : TheTrait {
30 }
31
32 pub struct TheType<'b> {
33     m: [fn(&'b()); 0]
34 }
35
36 impl<'b> TheTrait for TheType<'b> {
37     type TheAssocType = &'b ();
38 }
39
40 impl<'b> TheSubTrait for TheType<'b> {
41 }
42
43 ///////////////////////////////////////////////////////////////////////////
44
45 pub struct WithAssoc<T:TheSubTrait> {
46     m: [T; 0]
47 }
48
49 fn with_assoc<'a,'b>() {
50     // For this type to be valid, the rules require that all
51     // associated types of traits that appear in `WithAssoc` must
52     // outlive 'a. In this case, that means TheType<'b>::TheAssocType,
53     // which is &'b (), must outlive 'a.
54
55     let _: &'a WithAssoc<TheType<'b>> = loop { }; //~ ERROR cannot infer
56 }
57
58 fn main() {
59 }