]> git.lizzy.rs Git - rust.git/blob - src/test/ui/object-lifetime/object-lifetime-default-mybox.rs
Auto merge of #95295 - CAD97:layout-isize, r=scottmcm
[rust.git] / src / test / ui / object-lifetime / object-lifetime-default-mybox.rs
1 // Test a "pass-through" object-lifetime-default that produces errors.
2
3 #![allow(dead_code)]
4
5 trait SomeTrait {
6     fn dummy(&self) { }
7 }
8
9 struct MyBox<T:?Sized> {
10     r: Box<T>
11 }
12
13 fn deref<T>(ss: &T) -> T {
14     // produces the type of a deref without worrying about whether a
15     // move out would actually be legal
16     loop { }
17 }
18
19 fn load0(ss: &MyBox<dyn SomeTrait>) -> MyBox<dyn SomeTrait> {
20     deref(ss)
21 }
22
23 fn load1<'a,'b>(a: &'a MyBox<dyn SomeTrait>,
24                 b: &'b MyBox<dyn SomeTrait>)
25                 -> &'b MyBox<dyn SomeTrait>
26 {
27     a
28     //~^ ERROR lifetime may not live long enough
29 }
30
31 fn load2<'a>(ss: &MyBox<dyn SomeTrait + 'a>) -> MyBox<dyn SomeTrait + 'a> {
32     load0(ss)
33     //~^ ERROR borrowed data escapes outside of function
34 }
35
36 fn main() {
37 }