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