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