]> git.lizzy.rs Git - rust.git/blob - src/test/ui/object-lifetime/object-lifetime-default-from-box-error.rs
Merge commit '3e7c6dec244539970b593824334876f8b6ed0b18' into clippyup
[rust.git] / src / test / ui / object-lifetime / object-lifetime-default-from-box-error.rs
1 // Test various cases where the defaults should lead to errors being
2 // reported.
3
4 #![allow(dead_code)]
5
6 trait SomeTrait {
7     fn dummy(&self) { }
8 }
9
10 struct SomeStruct<'a> {
11     r: Box<dyn SomeTrait+'a>
12 }
13
14 fn load(ss: &mut SomeStruct) -> Box<dyn SomeTrait> {
15     // `Box<SomeTrait>` defaults to a `'static` bound, so this return
16     // is illegal.
17
18     ss.r //~ ERROR E0759
19 }
20
21 fn store(ss: &mut SomeStruct, b: Box<dyn SomeTrait>) {
22     // No error: b is bounded by 'static which outlives the
23     // (anonymous) lifetime on the struct.
24
25     ss.r = b;
26 }
27
28 fn store1<'b>(ss: &mut SomeStruct, b: Box<dyn SomeTrait+'b>) {
29     // Here we override the lifetimes explicitly, and so naturally we get an error.
30
31     ss.r = b; //~ ERROR explicit lifetime required in the type of `ss` [E0621]
32 }
33
34 fn main() {
35 }