]> git.lizzy.rs Git - rust.git/blob - tests/ui/manual_async_fn.fixed
Auto merge of #85538 - r00ster91:iterrepeat, r=Mark-Simulacrum
[rust.git] / tests / ui / manual_async_fn.fixed
1 // run-rustfix
2 // edition:2018
3 #![warn(clippy::manual_async_fn)]
4 #![allow(unused)]
5
6 use std::future::Future;
7
8 async fn fut() -> i32 { 42 }
9
10 #[rustfmt::skip]
11 async fn fut2() -> i32 { 42 }
12
13 #[rustfmt::skip]
14 async fn fut3() -> i32 { 42 }
15
16 async fn empty_fut() {}
17
18 #[rustfmt::skip]
19 async fn empty_fut2() {}
20
21 #[rustfmt::skip]
22 async fn empty_fut3() {}
23
24 async fn core_fut() -> i32 { 42 }
25
26 // should be ignored
27 fn has_other_stmts() -> impl core::future::Future<Output = i32> {
28     let _ = 42;
29     async move { 42 }
30 }
31
32 // should be ignored
33 fn not_fut() -> i32 {
34     42
35 }
36
37 // should be ignored
38 async fn already_async() -> impl Future<Output = i32> {
39     async { 42 }
40 }
41
42 struct S {}
43 impl S {
44     async fn inh_fut() -> i32 {
45         // NOTE: this code is here just to check that the indentation is correct in the suggested fix
46         let a = 42;
47         let b = 21;
48         if a < b {
49             let c = 21;
50             let d = 42;
51             if c < d {
52                 let _ = 42;
53             }
54         }
55         42
56     }
57
58     // should be ignored
59     fn not_fut(&self) -> i32 {
60         42
61     }
62
63     // should be ignored
64     fn has_other_stmts() -> impl core::future::Future<Output = i32> {
65         let _ = 42;
66         async move { 42 }
67     }
68
69     // should be ignored
70     async fn already_async(&self) -> impl Future<Output = i32> {
71         async { 42 }
72     }
73 }
74
75 // Tests related to lifetime capture
76
77 async fn elided(_: &i32) -> i32 { 42 }
78
79 // should be ignored
80 fn elided_not_bound(_: &i32) -> impl Future<Output = i32> {
81     async { 42 }
82 }
83
84 async fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> i32 { 42 }
85
86 // should be ignored
87 #[allow(clippy::needless_lifetimes)]
88 fn explicit_not_bound<'a, 'b>(_: &'a i32, _: &'b i32) -> impl Future<Output = i32> {
89     async { 42 }
90 }
91
92 // should be ignored
93 mod issue_5765 {
94     use std::future::Future;
95
96     struct A;
97     impl A {
98         fn f(&self) -> impl Future<Output = ()> {
99             async {}
100         }
101     }
102
103     fn test() {
104         let _future = {
105             let a = A;
106             a.f()
107         };
108     }
109 }
110
111 fn main() {}