]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/manual_async_fn.rs
Rollup merge of #102187 - b-naber:inline-const-source-info, r=eholk
[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 fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> impl Future<Output = i32> + 'a + 'b {
102     async { 42 }
103 }
104
105 // should be ignored
106 #[allow(clippy::needless_lifetimes)]
107 fn explicit_not_bound<'a, 'b>(_: &'a i32, _: &'b i32) -> impl Future<Output = i32> {
108     async { 42 }
109 }
110
111 // should be ignored
112 mod issue_5765 {
113     use std::future::Future;
114
115     struct A;
116     impl A {
117         fn f(&self) -> impl Future<Output = ()> {
118             async {}
119         }
120     }
121
122     fn test() {
123         let _future = {
124             let a = A;
125             a.f()
126         };
127     }
128 }
129
130 fn main() {}