1 // Test various cases where the defaults should lead to errors being 2 // reported. 3 4 #![allow(dead_code)] 5 6 trait SomeTrait { dummy(&self)7 fn dummy(&self) { } 8 } 9 10 struct SomeStruct<'a> { 11 r: Box<dyn SomeTrait+'a> 12 } 13 load(ss: &mut SomeStruct) -> Box<dyn SomeTrait>14fn 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 store(ss: &mut SomeStruct, b: Box<dyn SomeTrait>)21fn 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 store1<'b>(ss: &mut SomeStruct, b: Box<dyn SomeTrait+'b>)28fn 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 main()34fn main() { 35 } 36