]> git.lizzy.rs Git - rust.git/blob - tests/ui/object-lifetime/object-lifetime-default-dyn-binding-nonstatic1.rs
Rollup merge of #107615 - notriddle:notriddle/nbsp, r=GuillaumeGomez
[rust.git] / tests / ui / object-lifetime / object-lifetime-default-dyn-binding-nonstatic1.rs
1 // Test that `dyn Bar<Item = XX>` uses `'static` as the default object
2 // lifetime bound for the type `XX`.
3
4 trait Foo<'a> {
5     type Item: ?Sized;
6
7     fn item(&self) -> Box<Self::Item> { panic!() }
8 }
9
10 trait Bar { }
11
12 impl<T> Foo<'_> for T {
13     type Item = dyn Bar;
14 }
15
16 fn is_static<T>(_: T) where T: 'static { }
17
18 // Here, we should default to `dyn Bar + 'static`, but the current
19 // code forces us into a conservative, hacky path.
20 fn bar<'a>(x: &'a str) -> &'a dyn Foo<'a, Item = dyn Bar> { &() }
21 //~^ ERROR please supply an explicit bound
22
23 fn main() {
24     let s = format!("foo");
25     let r = bar(&s);
26     is_static(r.item());
27 }