Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/test_db.rs')
-rw-r--r--crates/hir-ty/src/test_db.rs30
1 files changed, 23 insertions, 7 deletions
diff --git a/crates/hir-ty/src/test_db.rs b/crates/hir-ty/src/test_db.rs
index b5de0e52f5..7044ca5d23 100644
--- a/crates/hir-ty/src/test_db.rs
+++ b/crates/hir-ty/src/test_db.rs
@@ -3,26 +3,26 @@
use std::{fmt, panic, sync::Mutex};
use base_db::{
- CrateGraphBuilder, CratesMap, FileSourceRootInput, FileText, RootQueryDb, SourceDatabase,
- SourceRoot, SourceRootId, SourceRootInput,
+ CrateGraphBuilder, CratesMap, FileSourceRootInput, FileText, Nonce, RootQueryDb,
+ SourceDatabase, SourceRoot, SourceRootId, SourceRootInput,
};
use hir_def::{ModuleId, db::DefDatabase, nameres::crate_def_map};
use hir_expand::EditionedFileId;
use rustc_hash::FxHashMap;
-use salsa::{AsDynDatabase, Durability};
+use salsa::Durability;
use span::FileId;
use syntax::TextRange;
use test_utils::extract_annotations;
use triomphe::Arc;
#[salsa_macros::db]
-#[derive(Clone)]
pub(crate) struct TestDB {
storage: salsa::Storage<Self>,
files: Arc<base_db::Files>,
crates_map: Arc<CratesMap>,
events: Arc<Mutex<Option<Vec<salsa::Event>>>>,
+ nonce: Nonce,
}
impl Default for TestDB {
@@ -41,6 +41,7 @@ impl Default for TestDB {
events,
files: Default::default(),
crates_map: Default::default(),
+ nonce: Nonce::new(),
};
this.set_expand_proc_attr_macros_with_durability(true, Durability::HIGH);
// This needs to be here otherwise `CrateGraphBuilder` panics.
@@ -50,6 +51,18 @@ impl Default for TestDB {
}
}
+impl Clone for TestDB {
+ fn clone(&self) -> Self {
+ Self {
+ storage: self.storage.clone(),
+ files: self.files.clone(),
+ crates_map: self.crates_map.clone(),
+ events: self.events.clone(),
+ nonce: Nonce::new(),
+ }
+ }
+}
+
impl fmt::Debug for TestDB {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("TestDB").finish()
@@ -109,6 +122,10 @@ impl SourceDatabase for TestDB {
fn crates_map(&self) -> Arc<CratesMap> {
self.crates_map.clone()
}
+
+ fn nonce_and_revision(&self) -> (Nonce, salsa::Revision) {
+ (self.nonce, salsa::plumbing::ZalsaDatabase::zalsa(self).current_revision())
+ }
}
#[salsa_macros::db]
@@ -149,7 +166,7 @@ impl TestDB {
.into_iter()
.filter_map(|file_id| {
let text = self.file_text(file_id.file_id(self));
- let annotations = extract_annotations(&text.text(self));
+ let annotations = extract_annotations(text.text(self));
if annotations.is_empty() {
return None;
}
@@ -174,8 +191,7 @@ impl TestDB {
// This is pretty horrible, but `Debug` is the only way to inspect
// QueryDescriptor at the moment.
salsa::EventKind::WillExecute { database_key } => {
- let ingredient = self
- .as_dyn_database()
+ let ingredient = (self as &dyn salsa::Database)
.ingredient_debug_name(database_key.ingredient_index());
Some(ingredient.to_string())
}