mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-04 10:50:15 +00:00
Remove all upcasts!
It turns out there were a lot redundant too.
This commit is contained in:
parent
a775d21112
commit
8a9a1e3345
80 changed files with 1009 additions and 1257 deletions
|
@ -52,11 +52,11 @@ use std::{fmt, mem::ManuallyDrop};
|
|||
|
||||
use base_db::{
|
||||
CrateGraphBuilder, CratesMap, FileSourceRootInput, FileText, Files, RootQueryDb,
|
||||
SourceDatabase, SourceRoot, SourceRootId, SourceRootInput, Upcast, query_group,
|
||||
SourceDatabase, SourceRoot, SourceRootId, SourceRootInput, query_group,
|
||||
};
|
||||
use hir::{
|
||||
FilePositionWrapper, FileRangeWrapper,
|
||||
db::{DefDatabase, ExpandDatabase, HirDatabase},
|
||||
db::{DefDatabase, ExpandDatabase},
|
||||
};
|
||||
use triomphe::Arc;
|
||||
|
||||
|
@ -116,39 +116,6 @@ impl fmt::Debug for RootDatabase {
|
|||
}
|
||||
}
|
||||
|
||||
impl Upcast<dyn ExpandDatabase> for RootDatabase {
|
||||
#[inline]
|
||||
fn upcast(&self) -> &(dyn ExpandDatabase + 'static) {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Upcast<dyn DefDatabase> for RootDatabase {
|
||||
#[inline]
|
||||
fn upcast(&self) -> &(dyn DefDatabase + 'static) {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Upcast<dyn HirDatabase> for RootDatabase {
|
||||
#[inline]
|
||||
fn upcast(&self) -> &(dyn HirDatabase + 'static) {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Upcast<dyn RootQueryDb> for RootDatabase {
|
||||
fn upcast(&self) -> &(dyn RootQueryDb + 'static) {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Upcast<dyn SourceDatabase> for RootDatabase {
|
||||
fn upcast(&self) -> &(dyn SourceDatabase + 'static) {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[salsa::db]
|
||||
impl SourceDatabase for RootDatabase {
|
||||
fn file_text(&self, file_id: vfs::FileId) -> FileText {
|
||||
|
|
|
@ -210,7 +210,7 @@ impl<'a> PathTransform<'a> {
|
|||
.flat_map(|it| it.lifetime_params(db))
|
||||
.zip(self.substs.lifetimes.clone())
|
||||
.filter_map(|(k, v)| {
|
||||
Some((k.name(db).display(db.upcast(), target_edition).to_string(), v.lifetime()?))
|
||||
Some((k.name(db).display(db, target_edition).to_string(), v.lifetime()?))
|
||||
})
|
||||
.collect();
|
||||
let ctx = Ctx {
|
||||
|
@ -325,7 +325,7 @@ impl Ctx<'_> {
|
|||
allow_unstable: true,
|
||||
};
|
||||
let found_path = self.target_module.find_path(
|
||||
self.source_scope.db.upcast(),
|
||||
self.source_scope.db,
|
||||
hir::ModuleDef::Trait(trait_ref),
|
||||
cfg,
|
||||
)?;
|
||||
|
@ -384,8 +384,7 @@ impl Ctx<'_> {
|
|||
prefer_absolute: false,
|
||||
allow_unstable: true,
|
||||
};
|
||||
let found_path =
|
||||
self.target_module.find_path(self.source_scope.db.upcast(), def, cfg)?;
|
||||
let found_path = self.target_module.find_path(self.source_scope.db, def, cfg)?;
|
||||
let res = mod_path_to_ast(&found_path, self.target_edition).clone_for_update();
|
||||
if let Some(args) = path.segment().and_then(|it| it.generic_arg_list()) {
|
||||
if let Some(segment) = res.segment() {
|
||||
|
@ -425,7 +424,7 @@ impl Ctx<'_> {
|
|||
allow_unstable: true,
|
||||
};
|
||||
let found_path = self.target_module.find_path(
|
||||
self.source_scope.db.upcast(),
|
||||
self.source_scope.db,
|
||||
ModuleDef::from(adt),
|
||||
cfg,
|
||||
)?;
|
||||
|
|
|
@ -27,7 +27,7 @@ use std::{
|
|||
ops::ControlFlow,
|
||||
};
|
||||
|
||||
use base_db::{RootQueryDb, SourceDatabase, SourceRootId, Upcast};
|
||||
use base_db::{RootQueryDb, SourceDatabase, SourceRootId};
|
||||
use fst::{Automaton, Streamer, raw::IndexedValue};
|
||||
use hir::{
|
||||
Crate, Module,
|
||||
|
@ -97,7 +97,7 @@ impl Query {
|
|||
}
|
||||
|
||||
#[query_group::query_group]
|
||||
pub trait SymbolsDatabase: HirDatabase + SourceDatabase + Upcast<dyn HirDatabase> {
|
||||
pub trait SymbolsDatabase: HirDatabase + SourceDatabase {
|
||||
/// The symbol index for a given module. These modules should only be in source roots that
|
||||
/// are inside local_roots.
|
||||
fn module_symbols(&self, module: Module) -> Arc<SymbolIndex>;
|
||||
|
@ -123,11 +123,11 @@ pub trait SymbolsDatabase: HirDatabase + SourceDatabase + Upcast<dyn HirDatabase
|
|||
fn library_symbols(db: &dyn SymbolsDatabase, source_root_id: SourceRootId) -> Arc<SymbolIndex> {
|
||||
let _p = tracing::info_span!("library_symbols").entered();
|
||||
|
||||
let mut symbol_collector = SymbolCollector::new(db.upcast());
|
||||
let mut symbol_collector = SymbolCollector::new(db);
|
||||
|
||||
db.source_root_crates(source_root_id)
|
||||
.iter()
|
||||
.flat_map(|&krate| Crate::from(krate).modules(db.upcast()))
|
||||
.flat_map(|&krate| Crate::from(krate).modules(db))
|
||||
// we specifically avoid calling other SymbolsDatabase queries here, even though they do the same thing,
|
||||
// as the index for a library is not going to really ever change, and we do not want to store each
|
||||
// the module or crate indices for those in salsa unless we need to.
|
||||
|
@ -139,12 +139,12 @@ fn library_symbols(db: &dyn SymbolsDatabase, source_root_id: SourceRootId) -> Ar
|
|||
fn module_symbols(db: &dyn SymbolsDatabase, module: Module) -> Arc<SymbolIndex> {
|
||||
let _p = tracing::info_span!("module_symbols").entered();
|
||||
|
||||
Arc::new(SymbolIndex::new(SymbolCollector::new_module(db.upcast(), module)))
|
||||
Arc::new(SymbolIndex::new(SymbolCollector::new_module(db, module)))
|
||||
}
|
||||
|
||||
pub fn crate_symbols(db: &dyn SymbolsDatabase, krate: Crate) -> Box<[Arc<SymbolIndex>]> {
|
||||
let _p = tracing::info_span!("crate_symbols").entered();
|
||||
krate.modules(db.upcast()).into_iter().map(|module| db.module_symbols(module)).collect()
|
||||
krate.modules(db).into_iter().map(|module| db.module_symbols(module)).collect()
|
||||
}
|
||||
|
||||
// Feature: Workspace Symbol
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue