]> git.proxmox.com Git - rustc.git/blame_incremental - src/tools/clippy/tests/ui/unused_async.rs
bump version to 1.80.1+dfsg1-1~bpo12+pve1
[rustc.git] / src / tools / clippy / tests / ui / unused_async.rs
... / ...
CommitLineData
1#![warn(clippy::unused_async)]
2#![allow(incomplete_features)]
3
4use std::future::Future;
5use std::pin::Pin;
6
7mod issue10800 {
8 #![allow(dead_code, unused_must_use, clippy::no_effect)]
9
10 use std::future::ready;
11
12 async fn async_block_await() {
13 //~^ ERROR: unused `async` for function with no await statements
14 async {
15 ready(()).await;
16 };
17 }
18
19 async fn normal_block_await() {
20 {
21 {
22 ready(()).await;
23 }
24 }
25 }
26}
27
28mod issue10459 {
29 trait HasAsyncMethod {
30 async fn do_something() -> u32;
31 }
32
33 impl HasAsyncMethod for () {
34 async fn do_something() -> u32 {
35 1
36 }
37 }
38}
39
40mod issue9695 {
41 use std::future::Future;
42
43 async fn f() {}
44 async fn f2() {}
45 async fn f3() {}
46 //~^ ERROR: unused `async` for function with no await statements
47
48 fn needs_async_fn<F: Future<Output = ()>>(_: fn() -> F) {}
49
50 fn test() {
51 let x = f;
52 needs_async_fn(x); // async needed in f
53 needs_async_fn(f2); // async needed in f2
54 f3(); // async not needed in f3
55 }
56}
57
58async fn foo() -> i32 {
59 //~^ ERROR: unused `async` for function with no await statements
60 4
61}
62
63async fn bar() -> i32 {
64 foo().await
65}
66
67struct S;
68
69impl S {
70 async fn unused(&self) -> i32 {
71 //~^ ERROR: unused `async` for function with no await statements
72 1
73 }
74
75 async fn used(&self) -> i32 {
76 self.unused().await
77 }
78}
79
80trait AsyncTrait {
81 fn trait_method() -> Pin<Box<dyn Future<Output = i32>>>;
82}
83
84macro_rules! async_trait_impl {
85 () => {
86 impl AsyncTrait for S {
87 fn trait_method() -> Pin<Box<dyn Future<Output = i32>>> {
88 async fn unused() -> i32 {
89 5
90 }
91
92 Box::pin(unused())
93 }
94 }
95 };
96}
97async_trait_impl!();
98
99fn main() {
100 foo();
101 bar();
102}