]> git.lizzy.rs Git - rust.git/blob - src/test/ui/regions/regions-outlives-projection-container-wc.rs
Rollup merge of #53317 - estebank:abolish-ice, r=oli-obk
[rust.git] / src / test / ui / regions / regions-outlives-projection-container-wc.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 // ignore-compare-mode-nll
12
13 // Test that we are imposing the requirement that every associated
14 // type of a bound that appears in the where clause on a struct must
15 // outlive the location in which the type appears, even when the
16 // constraint is in a where clause not a bound. Issue #22246.
17
18 #![allow(dead_code)]
19
20 ///////////////////////////////////////////////////////////////////////////
21
22 pub trait TheTrait {
23     type TheAssocType;
24 }
25
26 pub struct TheType<'b> {
27     m: [fn(&'b()); 0]
28 }
29
30 impl<'b> TheTrait for TheType<'b> {
31     type TheAssocType = &'b ();
32 }
33
34 ///////////////////////////////////////////////////////////////////////////
35
36 pub struct WithAssoc<T> where T : TheTrait {
37     m: [T; 0]
38 }
39
40 fn with_assoc<'a,'b>() {
41     // For this type to be valid, the rules require that all
42     // associated types of traits that appear in `WithAssoc` must
43     // outlive 'a. In this case, that means TheType<'b>::TheAssocType,
44     // which is &'b (), must outlive 'a.
45
46     let _: &'a WithAssoc<TheType<'b>> = loop { };
47     //~^ ERROR reference has a longer lifetime
48 }
49
50 fn main() {
51 }