]> git.lizzy.rs Git - rust.git/blob - src/test/ui/span/issue-24805-dropck-child-has-items-via-parent.rs
Rollup merge of #46636 - frewsxcv:frewsxcv-fn-box, r=estebank
[rust.git] / src / test / ui / span / issue-24805-dropck-child-has-items-via-parent.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 // Check that child trait who only has items via its *parent* trait
12 // does cause dropck to inject extra region constraints.
13
14 #![allow(non_camel_case_types)]
15
16 trait Parent { fn foo(&self); }
17 trait Child: Parent { }
18
19 impl Parent for i32 { fn foo(&self) { } }
20 impl<'a> Parent for &'a D_Child<i32> {
21     fn foo(&self) {
22         println!("accessing child value: {}", self.0);
23     }
24 }
25
26 impl Child for i32 { }
27 impl<'a> Child for &'a D_Child<i32> { }
28
29 struct D_Child<T:Child>(T);
30 impl <T:Child> Drop for D_Child<T> { fn drop(&mut self) { self.0.foo() } }
31
32 fn f_child() {
33     // `_d` and `d1` are assigned the *same* lifetime by region inference ...
34     let (_d, d1);
35
36     d1 = D_Child(1);
37     // ... we store a reference to `d1` within `_d` ...
38     _d = D_Child(&d1);
39     //~^ ERROR `d1` does not live long enough
40
41     // ... dropck *should* complain, because Drop of _d could (and
42     // does) access the already dropped `d1` via the `foo` method.
43 }
44
45 fn main() {
46     f_child();
47 }