]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/manual_async_fn.rs
Auto merge of #76931 - oli-obk:const_prop_inline_lint_madness, r=wesleywiser
[rust.git] / src / tools / clippy / tests / ui / manual_async_fn.rs
1 // run-rustfix
2 // edition:2018
3 #![warn(clippy::manual_async_fn)]
4 #![allow(unused)]
5
6 use std::future::Future;
7
8 fn fut() -> impl Future<Output = i32> {
9     async { 42 }
10 }
11
12 fn empty_fut() -> impl Future<Output = ()> {
13     async {}
14 }
15
16 fn core_fut() -> impl core::future::Future<Output = i32> {
17     async move { 42 }
18 }
19
20 // should be ignored
21 fn has_other_stmts() -> impl core::future::Future<Output = i32> {
22     let _ = 42;
23     async move { 42 }
24 }
25
26 // should be ignored
27 fn not_fut() -> i32 {
28     42
29 }
30
31 // should be ignored
32 async fn already_async() -> impl Future<Output = i32> {
33     async { 42 }
34 }
35
36 struct S {}
37 impl S {
38     fn inh_fut() -> impl Future<Output = i32> {
39         async {
40             // NOTE: this code is here just to check that the indentation is correct in the suggested fix
41             let a = 42;
42             let b = 21;
43             if a < b {
44                 let c = 21;
45                 let d = 42;
46                 if c < d {
47                     let _ = 42;
48                 }
49             }
50             42
51         }
52     }
53
54     // should be ignored
55     fn not_fut(&self) -> i32 {
56         42
57     }
58
59     // should be ignored
60     fn has_other_stmts() -> impl core::future::Future<Output = i32> {
61         let _ = 42;
62         async move { 42 }
63     }
64
65     // should be ignored
66     async fn already_async(&self) -> impl Future<Output = i32> {
67         async { 42 }
68     }
69 }
70
71 // Tests related to lifetime capture
72
73 fn elided(_: &i32) -> impl Future<Output = i32> + '_ {
74     async { 42 }
75 }
76
77 // should be ignored
78 fn elided_not_bound(_: &i32) -> impl Future<Output = i32> {
79     async { 42 }
80 }
81
82 fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> impl Future<Output = i32> + 'a + 'b {
83     async { 42 }
84 }
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() {}