]> git.lizzy.rs Git - rust.git/blob - tests/ui/dyn-star/dyn-async-trait.rs
Don't resolve type var roots in point_at_expr_source_of_inferred_type
[rust.git] / tests / ui / dyn-star / dyn-async-trait.rs
1 // check-pass
2 // edition: 2021
3
4 // This test case is meant to demonstrate how close we can get to async
5 // functions in dyn traits with the current level of dyn* support.
6
7 #![feature(dyn_star)]
8 #![allow(incomplete_features)]
9
10 use std::future::Future;
11
12 trait DynAsyncCounter {
13     fn increment<'a>(&'a mut self) -> dyn* Future<Output = usize> + 'a;
14 }
15
16 struct MyCounter {
17     count: usize,
18 }
19
20 impl DynAsyncCounter for MyCounter {
21     fn increment<'a>(&'a mut self) -> dyn* Future<Output = usize> + 'a {
22         Box::pin(async {
23             self.count += 1;
24             self.count
25         })
26     }
27 }
28
29 async fn do_counter(counter: &mut dyn DynAsyncCounter) -> usize {
30     counter.increment().await
31 }
32
33 fn main() {
34     let mut counter = MyCounter { count: 0 };
35     let _ = do_counter(&mut counter);
36 }