|
1 | | -// edition:2018 |
| 1 | +// Check "unused_lifetimes" lint on both async and sync functions |
2 | 2 |
|
3 | | -// Avoid spurious warnings of unused lifetime. The below async functions |
4 | | -// are desugered to have an unused lifetime |
5 | | -// but we don't want to warn about that as there's nothing they can do about it. |
| 3 | +// edition:2018 |
6 | 4 |
|
7 | 5 | #![deny(unused_lifetimes)] |
8 | | -#![allow(dead_code)] |
9 | | - |
10 | | -pub async fn october(s: &str) { |
11 | | - println!("{}", s); |
12 | | -} |
13 | | - |
14 | | -pub async fn async_fn(&mut ref s: &mut[i32]) { |
15 | | - println!("{:?}", s); |
16 | | -} |
17 | | - |
18 | | -macro_rules! foo_macro { |
19 | | - () => { |
20 | | - pub async fn async_fn_in_macro(&mut ref _s: &mut[i32]) {} |
21 | | - }; |
22 | | -} |
23 | | - |
24 | | -foo_macro!(); |
25 | | - |
26 | | -pub async fn func_with_unused_lifetime<'a>(s: &'a str) { |
27 | | - //~^ ERROR lifetime parameter `'a` never used |
28 | | - println!("{}", s); |
29 | | -} |
30 | | - |
31 | | -pub async fn func_with_two_unused_lifetime<'a, 'b>(s: &'a str, t: &'b str) { |
32 | | - //~^ ERROR lifetime parameter `'a` never used |
33 | | - //~^^ ERROR lifetime parameter `'b` never used |
34 | | - println!("{}", s); |
35 | | -} |
36 | | - |
37 | | -pub async fn func_with_unused_lifetime_in_two_params<'c>(s: &'c str, t: &'c str) { |
38 | | - //~^ ERROR lifetime parameter `'c` never used |
39 | | - println!("{}", s); |
40 | | -} |
| 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 | + |
41 | 46 |
|
42 | 47 | fn main() {} |
0 commit comments