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