]> git.lizzy.rs Git - rust.git/blob - src/test/ui/underscore-lifetime/dyn-trait-underscore.rs
Rollup merge of #57107 - mjbshaw:thread_local_test, r=nikomatsakis
[rust.git] / src / test / ui / underscore-lifetime / dyn-trait-underscore.rs
1 // Check that the `'_` in `dyn Trait + '_` acts like ordinary elision,
2 // and not like an object lifetime default.
3 //
4 // cc #48468
5
6 fn a<T>(items: &[T]) -> Box<dyn Iterator<Item=&T>> {
7     //                      ^^^^^^^^^^^^^^^^^^^^^ bound *here* defaults to `'static`
8     Box::new(items.iter()) //~ ERROR cannot infer an appropriate lifetime
9 }
10
11 fn b<T>(items: &[T]) -> Box<dyn Iterator<Item=&T> + '_> {
12     Box::new(items.iter()) // OK, equivalent to c
13 }
14
15 fn c<'a, T>(items: &'a [T]) -> Box<dyn Iterator<Item=&'a T> + 'a> {
16     Box::new(items.iter()) // OK, equivalent to b
17 }
18
19 fn main() { }