1 // Test that `dyn Bar<Item = XX>` uses `'static` as the default object
2 // lifetime bound for the type `XX`.
3 //
4 // check-pass
5 
6 trait Foo {
7     type Item: ?Sized;
8 
item(&self) -> Box<Self::Item>9     fn item(&self) -> Box<Self::Item> { panic!() }
10 }
11 
12 trait Bar { }
13 
14 impl<T> Foo for T {
15     type Item = dyn Bar;
16 }
17 
is_static<T>(_: T) where T: 'static18 fn is_static<T>(_: T) where T: 'static { }
19 
20 // Here, we default to `dyn Bar + 'static`, and not `&'x dyn Foo<Item
21 // = dyn Bar + 'x>`.
bar(x: &str) -> &dyn Foo<Item = dyn Bar>22 fn bar(x: &str) -> &dyn Foo<Item = dyn Bar> { &() }
23 
main()24 fn main() {
25     let s = format!("foo");
26     let r = bar(&s);
27     is_static(r.item());
28 }
29