]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/manual_async_fn.fixed
Merge commit '645ef505da378b6f810b1567806d1bcc2856395f' into clippyup
[rust.git] / src / tools / clippy / 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 async fn empty_fut()  {}
11
12 async fn core_fut() -> i32 { 42 }
13
14 // should be ignored
15 fn has_other_stmts() -> impl core::future::Future<Output = i32> {
16     let _ = 42;
17     async move { 42 }
18 }
19
20 // should be ignored
21 fn not_fut() -> i32 {
22     42
23 }
24
25 // should be ignored
26 async fn already_async() -> impl Future<Output = i32> {
27     async { 42 }
28 }
29
30 struct S {}
31 impl S {
32     async fn inh_fut() -> i32 {
33         // NOTE: this code is here just to check that the indentation is correct in the suggested fix
34         let a = 42;
35         let b = 21;
36         if a < b {
37             let c = 21;
38             let d = 42;
39             if c < d {
40                 let _ = 42;
41             }
42         }
43         42
44     }
45
46     // should be ignored
47     fn not_fut(&self) -> i32 {
48         42
49     }
50
51     // should be ignored
52     fn has_other_stmts() -> impl core::future::Future<Output = i32> {
53         let _ = 42;
54         async move { 42 }
55     }
56
57     // should be ignored
58     async fn already_async(&self) -> impl Future<Output = i32> {
59         async { 42 }
60     }
61 }
62
63 // Tests related to lifetime capture
64
65 async fn elided(_: &i32) -> i32 { 42 }
66
67 // should be ignored
68 fn elided_not_bound(_: &i32) -> impl Future<Output = i32> {
69     async { 42 }
70 }
71
72 async fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> i32 { 42 }
73
74 // should be ignored
75 #[allow(clippy::needless_lifetimes)]
76 fn explicit_not_bound<'a, 'b>(_: &'a i32, _: &'b i32) -> impl Future<Output = i32> {
77     async { 42 }
78 }
79
80 // should be ignored
81 mod issue_5765 {
82     use std::future::Future;
83
84     struct A;
85     impl A {
86         fn f(&self) -> impl Future<Output = ()> {
87             async {}
88         }
89     }
90
91     fn test() {
92         let _future = {
93             let a = A;
94             a.f()
95         };
96     }
97 }
98
99 fn main() {}