]> git.lizzy.rs Git - rust.git/blob - tests/ui/future_not_send.rs
d3a920de4b6ad8a685f3c04096a3afd414826998
[rust.git] / tests / ui / future_not_send.rs
1 // edition:2018
2 #![warn(clippy::future_not_send)]
3
4 use std::cell::Cell;
5 use std::rc::Rc;
6 use std::sync::Arc;
7
8 async fn private_future(rc: Rc<[u8]>, cell: &Cell<usize>) -> bool {
9     async { true }.await
10 }
11
12 pub async fn public_future(rc: Rc<[u8]>) {
13     async { true }.await;
14 }
15
16 pub async fn public_send(arc: Arc<[u8]>) -> bool {
17     async { false }.await
18 }
19
20 async fn private_future2(rc: Rc<[u8]>, cell: &Cell<usize>) -> bool {
21     true
22 }
23
24 pub async fn public_future2(rc: Rc<[u8]>) {}
25
26 pub async fn public_send2(arc: Arc<[u8]>) -> bool {
27     false
28 }
29
30 struct Dummy {
31     rc: Rc<[u8]>,
32 }
33
34 impl Dummy {
35     async fn private_future(&self) -> usize {
36         async { true }.await;
37         self.rc.len()
38     }
39
40     pub async fn public_future(&self) {
41         self.private_future().await;
42     }
43
44     #[allow(clippy::manual_async_fn)]
45     pub fn public_send(&self) -> impl std::future::Future<Output = bool> {
46         async { false }
47     }
48 }
49
50 async fn generic_future<T>(t: T) -> T
51 where
52     T: Send,
53 {
54     let rt = &t;
55     async { true }.await;
56     t
57 }
58
59 async fn generic_future_send<T>(t: T)
60 where
61     T: Send,
62 {
63     async { true }.await;
64 }
65
66 async fn unclear_future<T>(t: T) {}
67
68 fn main() {
69     let rc = Rc::new([1, 2, 3]);
70     private_future(rc.clone(), &Cell::new(42));
71     public_future(rc.clone());
72     let arc = Arc::new([4, 5, 6]);
73     public_send(arc);
74     generic_future(42);
75     generic_future_send(42);
76
77     let dummy = Dummy { rc };
78     dummy.public_future();
79     dummy.public_send();
80 }