gluon_salsa/doctest.rs
1#![allow(dead_code)]
2
3/// Test that a database with a key/value that is not `Send` will,
4/// indeed, not be `Send`.
5///
6/// ```compile_fail,E0277
7/// use std::rc::Rc;
8///
9/// #[salsa::query_group(NoSendSyncStorage)]
10/// trait NoSendSyncDatabase: salsa::Database {
11/// fn no_send_sync_value(&self, key: bool) -> Rc<bool>;
12/// fn no_send_sync_key(&self, key: Rc<bool>) -> bool;
13/// }
14///
15/// fn no_send_sync_value(_db: &dyn NoSendSyncDatabase, key: bool) -> Rc<bool> {
16/// Rc::new(key)
17/// }
18///
19/// fn no_send_sync_key(_db: &dyn NoSendSyncDatabase, key: Rc<bool>) -> bool {
20/// *key
21/// }
22///
23/// #[salsa::database(NoSendSyncStorage)]
24/// #[derive(Default)]
25/// struct DatabaseImpl {
26/// storage: salsa::Storage<Self>,
27/// }
28///
29/// impl salsa::Database for DatabaseImpl {
30/// }
31///
32/// fn is_send<T: Send>(_: T) { }
33///
34/// fn assert_send() {
35/// is_send(DatabaseImpl::default());
36/// }
37/// ```
38fn test_key_not_send_db_not_send() {}
39
40/// Test that a database with a key/value that is not `Sync` will not
41/// be `Send`.
42///
43/// ```compile_fail,E0277
44/// use std::rc::Rc;
45/// use std::cell::Cell;
46///
47/// #[salsa::query_group(NoSendSyncStorage)]
48/// trait NoSendSyncDatabase: salsa::Database {
49/// fn no_send_sync_value(&self, key: bool) -> Cell<bool>;
50/// fn no_send_sync_key(&self, key: Cell<bool>) -> bool;
51/// }
52///
53/// fn no_send_sync_value(_db: &dyn NoSendSyncDatabase, key: bool) -> Cell<bool> {
54/// Cell::new(key)
55/// }
56///
57/// fn no_send_sync_key(_db: &dyn NoSendSyncDatabase, key: Cell<bool>) -> bool {
58/// *key
59/// }
60///
61/// #[salsa::database(NoSendSyncStorage)]
62/// #[derive(Default)]
63/// struct DatabaseImpl {
64/// runtime: salsa::Storage<Self>,
65/// }
66///
67/// impl salsa::Database for DatabaseImpl {
68/// }
69///
70/// fn is_send<T: Send>(_: T) { }
71///
72/// fn assert_send() {
73/// is_send(DatabaseImpl::default());
74/// }
75/// ```
76fn test_key_not_sync_db_not_send() {}
77
78/// Test that a database with a key/value that is not `Sync` will
79/// not be `Sync`.
80///
81/// ```compile_fail,E0277
82/// use std::cell::Cell;
83/// use std::rc::Rc;
84///
85/// #[salsa::query_group(NoSendSyncStorage)]
86/// trait NoSendSyncDatabase: salsa::Database {
87/// fn no_send_sync_value(&self, key: bool) -> Cell<bool>;
88/// fn no_send_sync_key(&self, key: Cell<bool>) -> bool;
89/// }
90///
91/// fn no_send_sync_value(_db: &dyn NoSendSyncDatabase, key: bool) -> Cell<bool> {
92/// Cell::new(key)
93/// }
94///
95/// fn no_send_sync_key(_db: &dyn NoSendSyncDatabase, key: Cell<bool>) -> bool {
96/// *key
97/// }
98///
99/// #[salsa::database(NoSendSyncStorage)]
100/// #[derive(Default)]
101/// struct DatabaseImpl {
102/// runtime: salsa::Storage<Self>,
103/// }
104///
105/// impl salsa::Database for DatabaseImpl {
106/// }
107///
108/// fn is_sync<T: Sync>(_: T) { }
109///
110/// fn assert_send() {
111/// is_sync(DatabaseImpl::default());
112/// }
113/// ```
114fn test_key_not_sync_db_not_sync() {}