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