rust-analyzer/crates/ra-salsa/tests/no_send_sync.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

32 lines
756 B
Rust
Raw Normal View History

2024-02-07 15:29:46 +00:00
use std::rc::Rc;
2024-10-04 19:48:11 +00:00
#[ra_salsa::query_group(NoSendSyncStorage)]
trait NoSendSyncDatabase: ra_salsa::Database {
2024-02-07 15:29:46 +00:00
fn no_send_sync_value(&self, key: bool) -> Rc<bool>;
fn no_send_sync_key(&self, key: Rc<bool>) -> bool;
}
fn no_send_sync_value(_db: &dyn NoSendSyncDatabase, key: bool) -> Rc<bool> {
Rc::new(key)
}
fn no_send_sync_key(_db: &dyn NoSendSyncDatabase, key: Rc<bool>) -> bool {
*key
}
2024-10-04 19:48:11 +00:00
#[ra_salsa::database(NoSendSyncStorage)]
2024-02-07 15:29:46 +00:00
#[derive(Default)]
struct DatabaseImpl {
2024-10-04 19:48:11 +00:00
storage: ra_salsa::Storage<Self>,
2024-02-07 15:29:46 +00:00
}
2024-10-04 19:48:11 +00:00
impl ra_salsa::Database for DatabaseImpl {}
2024-02-07 15:29:46 +00:00
#[test]
fn no_send_sync() {
let db = DatabaseImpl::default();
assert_eq!(db.no_send_sync_value(true), Rc::new(true));
assert!(!db.no_send_sync_key(Rc::new(false)));
}