]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/tests/ui/manual_async_fn.rs
New upstream version 1.70.0+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / manual_async_fn.rs
CommitLineData
f20569fa 1// run-rustfix
f20569fa
XL
2#![warn(clippy::manual_async_fn)]
3#![allow(unused)]
4
5use std::future::Future;
6
7fn fut() -> impl Future<Output = i32> {
8 async { 42 }
9}
10
11#[rustfmt::skip]
12fn fut2() ->impl Future<Output = i32> {
13 async { 42 }
14}
15
16#[rustfmt::skip]
17fn fut3()-> impl Future<Output = i32> {
18 async { 42 }
19}
20
21fn empty_fut() -> impl Future<Output = ()> {
22 async {}
23}
24
25#[rustfmt::skip]
26fn empty_fut2() ->impl Future<Output = ()> {
27 async {}
28}
29
30#[rustfmt::skip]
31fn empty_fut3()-> impl Future<Output = ()> {
32 async {}
33}
34
35fn core_fut() -> impl core::future::Future<Output = i32> {
36 async move { 42 }
37}
38
39// should be ignored
40fn has_other_stmts() -> impl core::future::Future<Output = i32> {
41 let _ = 42;
42 async move { 42 }
43}
44
45// should be ignored
46fn not_fut() -> i32 {
47 42
48}
49
50// should be ignored
51async fn already_async() -> impl Future<Output = i32> {
52 async { 42 }
53}
54
04454e1e 55struct S;
f20569fa
XL
56impl 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
92fn elided(_: &i32) -> impl Future<Output = i32> + '_ {
93 async { 42 }
94}
95
96// should be ignored
97fn elided_not_bound(_: &i32) -> impl Future<Output = i32> {
98 async { 42 }
99}
100
101fn 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)]
107fn explicit_not_bound<'a, 'b>(_: &'a i32, _: &'b i32) -> impl Future<Output = i32> {
108 async { 42 }
109}
110
111// should be ignored
112mod 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
353b0b11
FG
130pub fn issue_10450() -> impl Future<Output = i32> {
131 async { 42 }
132}
133
134pub(crate) fn issue_10450_2() -> impl Future<Output = i32> {
135 async { 42 }
136}
137
138pub(self) fn issue_10450_3() -> impl Future<Output = i32> {
139 async { 42 }
140}
141
f20569fa 142fn main() {}