fork/rust

git clone https://git.julia.blue/fork/rust

borsAuto merge of #103046 - JanBeh:PR_clarify_cmp_terminology, r=workingjubilee3bcad65fbf6

master
2.1 KiB115 linesraw
1#![warn(clippy::manual_async_fn)]
2#![allow(clippy::needless_pub_self, unused)]
3
4use std::future::Future;
5
6async fn fut() -> i32 { 42 }
7
8#[rustfmt::skip]
9async fn fut2() -> i32 { 42 }
10
11#[rustfmt::skip]
12async fn fut3() -> i32 { 42 }
13
14async fn empty_fut() {}
15
16#[rustfmt::skip]
17async fn empty_fut2() {}
18
19#[rustfmt::skip]
20async fn empty_fut3() {}
21
22async fn core_fut() -> i32 { 42 }
23
24// should be ignored
25fn has_other_stmts() -> impl core::future::Future<Output = i32> {
26    let _ = 42;
27    async move { 42 }
28}
29
30// should be ignored
31fn not_fut() -> i32 {
32    42
33}
34
35// should be ignored
36async fn already_async() -> impl Future<Output = i32> {
37    async { 42 }
38}
39
40struct S;
41impl 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
75async fn elided(_: &i32) -> i32 { 42 }
76
77// should be ignored
78fn elided_not_bound(_: &i32) -> impl Future<Output = i32> {
79    async { 42 }
80}
81
82async fn explicit<'a, 'b>(_: &'a i32, _: &'b i32) -> i32 { 42 }
83
84// should be ignored
85#[allow(clippy::needless_lifetimes)]
86fn explicit_not_bound<'a, 'b>(_: &'a i32, _: &'b i32) -> impl Future<Output = i32> {
87    async { 42 }
88}
89
90// should be ignored
91mod 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
109pub async fn issue_10450() -> i32 { 42 }
110
111pub(crate) async fn issue_10450_2() -> i32 { 42 }
112
113pub(self) async fn issue_10450_3() -> i32 { 42 }
114
115fn main() {}