]> git.lizzy.rs Git - rust.git/blob - src/test/ui/object-lifetime/object-lifetime-default-dyn-binding-static.rs
Rollup merge of #104024 - noeddl:unused-must-use, r=compiler-errors
[rust.git] / src / test / ui / object-lifetime / object-lifetime-default-dyn-binding-static.rs
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
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
18 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>`.
22 fn bar(x: &str) -> &dyn Foo<Item = dyn Bar> { &() }
23
24 fn main() {
25     let s = format!("foo");
26     let r = bar(&s);
27     is_static(r.item());
28 }