]> git.lizzy.rs Git - rust.git/blob - src/test/ui/span/issue-24805-dropck-child-has-items-via-parent.rs
Rollup merge of #87922 - Manishearth:c-enum-target-spec, r=nagisa,eddyb
[rust.git] / src / test / ui / span / issue-24805-dropck-child-has-items-via-parent.rs
1 // Check that child trait who only has items via its *parent* trait
2 // does cause dropck to inject extra region constraints.
3
4 #![allow(non_camel_case_types)]
5
6 trait Parent { fn foo(&self); }
7 trait Child: Parent { }
8
9 impl Parent for i32 { fn foo(&self) { } }
10 impl<'a> Parent for &'a D_Child<i32> {
11     fn foo(&self) {
12         println!("accessing child value: {}", self.0);
13     }
14 }
15
16 impl Child for i32 { }
17 impl<'a> Child for &'a D_Child<i32> { }
18
19 struct D_Child<T:Child>(T);
20 impl <T:Child> Drop for D_Child<T> { fn drop(&mut self) { self.0.foo() } }
21
22 fn f_child() {
23     // `_d` and `d1` are assigned the *same* lifetime by region inference ...
24     let (_d, d1);
25
26     d1 = D_Child(1);
27     // ... we store a reference to `d1` within `_d` ...
28     _d = D_Child(&d1);
29     //~^ ERROR `d1` does not live long enough
30
31     // ... dropck *should* complain, because Drop of _d could (and
32     // does) access the already dropped `d1` via the `foo` method.
33 }
34
35 fn main() {
36     f_child();
37 }