]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/future_not_send.rs
Auto merge of #71794 - RalfJung:miri, r=RalfJung
[rust.git] / src / tools / clippy / 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     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 }