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