]> git.lizzy.rs Git - rust.git/blob - src/test/ui/async-await/unused-lifetime.rs
remove [async output] from impl Future
[rust.git] / src / test / ui / async-await / unused-lifetime.rs
1 // Check "unused_lifetimes" lint on both async and sync functions
2
3 // edition:2018
4
5 #![deny(unused_lifetimes)]
6
7
8 // Async part with unused lifetimes
9 //
10 // Even wrong cases don't cause errors because async functions are desugared with all lifetimes
11 // involved in the signature. So, we cannot predict what lifetimes are unused in async function.
12 async fn async_wrong_without_args<'a>() {}
13
14 async fn async_wrong_1_lifetime<'a>(_: &i32) {}
15
16 async fn async_wrong_2_lifetimes<'a, 'b>(_: &'a i32, _: &i32) {}
17
18 async fn async_right_1_lifetime<'a>(_: &'a i32) {}
19
20 async fn async_right_2_lifetimes<'a, 'b>(_: &'a i32, _: &'b i32) {}
21
22 async fn async_right_trait_bound_lifetime<'a, I>(_: I)
23 where
24     I: Iterator<Item = &'a i32>
25 {}
26
27
28 // Sync part with unused lifetimes
29 //
30 // These functions are compiled as supposed
31 fn wrong_without_args<'a>() {} //~ ERROR lifetime parameter `'a` never used
32
33 fn wrong_1_lifetime<'a>(_: &i32) {} //~ ERROR lifetime parameter `'a` never used
34
35 fn wrong_2_lifetimes<'a, 'b>(_: &'a i32, _: &i32) {} //~ ERROR lifetime parameter `'b` never used
36
37 fn right_1_lifetime<'a>(_: &'a i32) {}
38
39 fn right_2_lifetimes<'a, 'b>(_: &'a i32, _: &'b i32) {}
40
41 fn right_trait_bound_lifetime<'a, I>(_: I)
42 where
43     I: Iterator<Item = &'a i32>
44 {}
45
46
47 fn main() {}