mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 11:20:54 +00:00
Merge pull request #19707 from Veykril/push-kqkpzkymkyyl
refactor: De-arc defmap queries
This commit is contained in:
commit
b3e086ad10
@ -24,8 +24,8 @@ use crate::{
|
|||||||
item_tree::{AttrOwner, ItemTree},
|
item_tree::{AttrOwner, ItemTree},
|
||||||
lang_item::{self, LangItem},
|
lang_item::{self, LangItem},
|
||||||
nameres::{
|
nameres::{
|
||||||
DefMap, LocalDefMap,
|
|
||||||
assoc::{ImplItems, TraitItems},
|
assoc::{ImplItems, TraitItems},
|
||||||
|
crate_def_map,
|
||||||
diagnostics::DefDiagnostics,
|
diagnostics::DefDiagnostics,
|
||||||
},
|
},
|
||||||
signatures::{
|
signatures::{
|
||||||
@ -111,16 +111,6 @@ pub trait DefDatabase: InternDatabase + ExpandDatabase + SourceDatabase {
|
|||||||
#[salsa::invoke(ItemTree::block_item_tree_query)]
|
#[salsa::invoke(ItemTree::block_item_tree_query)]
|
||||||
fn block_item_tree(&self, block_id: BlockId) -> Arc<ItemTree>;
|
fn block_item_tree(&self, block_id: BlockId) -> Arc<ItemTree>;
|
||||||
|
|
||||||
#[salsa::invoke(DefMap::crate_local_def_map_query)]
|
|
||||||
fn crate_local_def_map(&self, krate: Crate) -> (Arc<DefMap>, Arc<LocalDefMap>);
|
|
||||||
|
|
||||||
#[salsa::invoke(DefMap::crate_def_map_query)]
|
|
||||||
fn crate_def_map(&self, krate: Crate) -> Arc<DefMap>;
|
|
||||||
|
|
||||||
/// Computes the block-level `DefMap`.
|
|
||||||
#[salsa::invoke(DefMap::block_def_map_query)]
|
|
||||||
fn block_def_map(&self, block: BlockId) -> Arc<DefMap>;
|
|
||||||
|
|
||||||
/// Turns a MacroId into a MacroDefId, describing the macro's definition post name resolution.
|
/// Turns a MacroId into a MacroDefId, describing the macro's definition post name resolution.
|
||||||
#[salsa::invoke(macro_def)]
|
#[salsa::invoke(macro_def)]
|
||||||
fn macro_def(&self, m: MacroId) -> MacroDefId;
|
fn macro_def(&self, m: MacroId) -> MacroDefId;
|
||||||
@ -363,7 +353,7 @@ fn include_macro_invoc(
|
|||||||
db: &dyn DefDatabase,
|
db: &dyn DefDatabase,
|
||||||
krate: Crate,
|
krate: Crate,
|
||||||
) -> Arc<[(MacroCallId, EditionedFileId)]> {
|
) -> Arc<[(MacroCallId, EditionedFileId)]> {
|
||||||
db.crate_def_map(krate)
|
crate_def_map(db, krate)
|
||||||
.modules
|
.modules
|
||||||
.values()
|
.values()
|
||||||
.flat_map(|m| m.scope.iter_macro_invoc())
|
.flat_map(|m| m.scope.iter_macro_invoc())
|
||||||
|
@ -19,7 +19,6 @@ use rustc_hash::FxHashMap;
|
|||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use span::{Edition, SyntaxContext};
|
use span::{Edition, SyntaxContext};
|
||||||
use syntax::{AstPtr, SyntaxNodePtr, ast};
|
use syntax::{AstPtr, SyntaxNodePtr, ast};
|
||||||
use triomphe::Arc;
|
|
||||||
use tt::TextRange;
|
use tt::TextRange;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -30,7 +29,7 @@ use crate::{
|
|||||||
Array, AsmOperand, Binding, BindingId, Expr, ExprId, ExprOrPatId, Label, LabelId, Pat,
|
Array, AsmOperand, Binding, BindingId, Expr, ExprId, ExprOrPatId, Label, LabelId, Pat,
|
||||||
PatId, RecordFieldPat, Statement,
|
PatId, RecordFieldPat, Statement,
|
||||||
},
|
},
|
||||||
nameres::DefMap,
|
nameres::{DefMap, block_def_map},
|
||||||
type_ref::{LifetimeRef, LifetimeRefId, PathId, TypeRef, TypeRefId},
|
type_ref::{LifetimeRef, LifetimeRefId, PathId, TypeRef, TypeRefId},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -225,8 +224,8 @@ impl ExpressionStore {
|
|||||||
pub fn blocks<'a>(
|
pub fn blocks<'a>(
|
||||||
&'a self,
|
&'a self,
|
||||||
db: &'a dyn DefDatabase,
|
db: &'a dyn DefDatabase,
|
||||||
) -> impl Iterator<Item = (BlockId, Arc<DefMap>)> + 'a {
|
) -> impl Iterator<Item = (BlockId, &'a DefMap)> + 'a {
|
||||||
self.block_scopes.iter().map(move |&block| (block, db.block_def_map(block)))
|
self.block_scopes.iter().map(move |&block| (block, block_def_map(db, block)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_bindings_in_pat(&self, pat_id: PatId, mut f: impl FnMut(BindingId)) {
|
pub fn walk_bindings_in_pat(&self, pat_id: PatId, mut f: impl FnMut(BindingId)) {
|
||||||
|
@ -56,7 +56,7 @@ use crate::{
|
|||||||
item_scope::BuiltinShadowMode,
|
item_scope::BuiltinShadowMode,
|
||||||
item_tree::FieldsShape,
|
item_tree::FieldsShape,
|
||||||
lang_item::LangItem,
|
lang_item::LangItem,
|
||||||
nameres::{DefMap, LocalDefMap, MacroSubNs},
|
nameres::{DefMap, LocalDefMap, MacroSubNs, block_def_map},
|
||||||
type_ref::{
|
type_ref::{
|
||||||
ArrayType, ConstRef, FnType, LifetimeRef, LifetimeRefId, Mutability, PathId, Rawness,
|
ArrayType, ConstRef, FnType, LifetimeRef, LifetimeRefId, Mutability, PathId, Rawness,
|
||||||
RefType, TraitBoundModifier, TraitRef, TypeBound, TypeRef, TypeRefId, UseArgRef,
|
RefType, TraitBoundModifier, TraitRef, TypeBound, TypeRef, TypeRefId, UseArgRef,
|
||||||
@ -436,8 +436,8 @@ pub struct ExprCollector<'db> {
|
|||||||
db: &'db dyn DefDatabase,
|
db: &'db dyn DefDatabase,
|
||||||
cfg_options: &'db CfgOptions,
|
cfg_options: &'db CfgOptions,
|
||||||
expander: Expander,
|
expander: Expander,
|
||||||
def_map: Arc<DefMap>,
|
def_map: &'db DefMap,
|
||||||
local_def_map: Arc<LocalDefMap>,
|
local_def_map: &'db LocalDefMap,
|
||||||
module: ModuleId,
|
module: ModuleId,
|
||||||
pub store: ExpressionStoreBuilder,
|
pub store: ExpressionStoreBuilder,
|
||||||
pub(crate) source_map: ExpressionStoreSourceMap,
|
pub(crate) source_map: ExpressionStoreSourceMap,
|
||||||
@ -544,7 +544,7 @@ impl ExprCollector<'_> {
|
|||||||
current_file_id: HirFileId,
|
current_file_id: HirFileId,
|
||||||
) -> ExprCollector<'_> {
|
) -> ExprCollector<'_> {
|
||||||
let (def_map, local_def_map) = module.local_def_map(db);
|
let (def_map, local_def_map) = module.local_def_map(db);
|
||||||
let expander = Expander::new(db, current_file_id, &def_map);
|
let expander = Expander::new(db, current_file_id, def_map);
|
||||||
ExprCollector {
|
ExprCollector {
|
||||||
db,
|
db,
|
||||||
cfg_options: module.krate().cfg_options(db),
|
cfg_options: module.krate().cfg_options(db),
|
||||||
@ -1947,7 +1947,7 @@ impl ExprCollector<'_> {
|
|||||||
let resolver = |path: &_| {
|
let resolver = |path: &_| {
|
||||||
self.def_map
|
self.def_map
|
||||||
.resolve_path(
|
.resolve_path(
|
||||||
&self.local_def_map,
|
self.local_def_map,
|
||||||
self.db,
|
self.db,
|
||||||
module,
|
module,
|
||||||
path,
|
path,
|
||||||
@ -2163,12 +2163,12 @@ impl ExprCollector<'_> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let (module, def_map) =
|
let (module, def_map) =
|
||||||
match block_id.map(|block_id| (self.db.block_def_map(block_id), block_id)) {
|
match block_id.map(|block_id| (block_def_map(self.db, block_id), block_id)) {
|
||||||
Some((def_map, block_id)) => {
|
Some((def_map, block_id)) => {
|
||||||
self.store.block_scopes.push(block_id);
|
self.store.block_scopes.push(block_id);
|
||||||
(def_map.module_id(DefMap::ROOT), def_map)
|
(def_map.module_id(DefMap::ROOT), def_map)
|
||||||
}
|
}
|
||||||
None => (self.module, self.def_map.clone()),
|
None => (self.module, self.def_map),
|
||||||
};
|
};
|
||||||
let prev_def_map = mem::replace(&mut self.def_map, def_map);
|
let prev_def_map = mem::replace(&mut self.def_map, def_map);
|
||||||
let prev_local_module = mem::replace(&mut self.module, module);
|
let prev_local_module = mem::replace(&mut self.module, module);
|
||||||
@ -2247,7 +2247,7 @@ impl ExprCollector<'_> {
|
|||||||
// This could also be a single-segment path pattern. To
|
// This could also be a single-segment path pattern. To
|
||||||
// decide that, we need to try resolving the name.
|
// decide that, we need to try resolving the name.
|
||||||
let (resolved, _) = self.def_map.resolve_path(
|
let (resolved, _) = self.def_map.resolve_path(
|
||||||
&self.local_def_map,
|
self.local_def_map,
|
||||||
self.db,
|
self.db,
|
||||||
self.module.local_id,
|
self.module.local_id,
|
||||||
&name.clone().into(),
|
&name.clone().into(),
|
||||||
|
@ -4,7 +4,6 @@ use syntax::ast::{self, make};
|
|||||||
use test_fixture::WithFixture;
|
use test_fixture::WithFixture;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::DefDatabase,
|
|
||||||
expr_store::{
|
expr_store::{
|
||||||
ExpressionStore,
|
ExpressionStore,
|
||||||
lower::{
|
lower::{
|
||||||
@ -14,13 +13,15 @@ use crate::{
|
|||||||
path::Path,
|
path::Path,
|
||||||
pretty,
|
pretty,
|
||||||
},
|
},
|
||||||
|
nameres::crate_def_map,
|
||||||
test_db::TestDB,
|
test_db::TestDB,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn lower_path(path: ast::Path) -> (TestDB, ExpressionStore, Option<Path>) {
|
fn lower_path(path: ast::Path) -> (TestDB, ExpressionStore, Option<Path>) {
|
||||||
let (db, file_id) = TestDB::with_single_file("");
|
let (db, file_id) = TestDB::with_single_file("");
|
||||||
let krate = db.fetch_test_crate();
|
let krate = db.fetch_test_crate();
|
||||||
let mut ctx = ExprCollector::new(&db, db.crate_def_map(krate).root_module_id(), file_id.into());
|
let mut ctx =
|
||||||
|
ExprCollector::new(&db, crate_def_map(&db, krate).root_module_id(), file_id.into());
|
||||||
let lowered_path = ctx.lower_path(path, &mut ExprCollector::impl_trait_allocator);
|
let lowered_path = ctx.lower_path(path, &mut ExprCollector::impl_trait_allocator);
|
||||||
let store = ctx.store.finish();
|
let store = ctx.store.finish();
|
||||||
(db, store, lowered_path)
|
(db, store, lowered_path)
|
||||||
|
@ -324,11 +324,13 @@ mod tests {
|
|||||||
use test_fixture::WithFixture;
|
use test_fixture::WithFixture;
|
||||||
use test_utils::{assert_eq_text, extract_offset};
|
use test_utils::{assert_eq_text, extract_offset};
|
||||||
|
|
||||||
use crate::{FunctionId, ModuleDefId, db::DefDatabase, test_db::TestDB};
|
use crate::{
|
||||||
|
FunctionId, ModuleDefId, db::DefDatabase, nameres::crate_def_map, test_db::TestDB,
|
||||||
|
};
|
||||||
|
|
||||||
fn find_function(db: &TestDB, file_id: FileId) -> FunctionId {
|
fn find_function(db: &TestDB, file_id: FileId) -> FunctionId {
|
||||||
let krate = db.test_crate();
|
let krate = db.test_crate();
|
||||||
let crate_def_map = db.crate_def_map(krate);
|
let crate_def_map = crate_def_map(db, krate);
|
||||||
|
|
||||||
let module = crate_def_map.modules_for_file(db, file_id).next().unwrap();
|
let module = crate_def_map.modules_for_file(db, file_id).next().unwrap();
|
||||||
let (_, def) = crate_def_map[module].scope.entries().next().unwrap();
|
let (_, def) = crate_def_map[module].scope.entries().next().unwrap();
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
mod block;
|
mod block;
|
||||||
|
|
||||||
use crate::{DefWithBodyId, ModuleDefId, hir::MatchArm, test_db::TestDB};
|
use crate::{DefWithBodyId, ModuleDefId, hir::MatchArm, nameres::crate_def_map, test_db::TestDB};
|
||||||
use expect_test::{Expect, expect};
|
use expect_test::{Expect, expect};
|
||||||
use la_arena::RawIdx;
|
use la_arena::RawIdx;
|
||||||
use test_fixture::WithFixture;
|
use test_fixture::WithFixture;
|
||||||
|
use triomphe::Arc;
|
||||||
|
|
||||||
use super::super::*;
|
use super::super::*;
|
||||||
|
|
||||||
@ -11,7 +12,7 @@ fn lower(#[rust_analyzer::rust_fixture] ra_fixture: &str) -> (TestDB, Arc<Body>,
|
|||||||
let db = TestDB::with_files(ra_fixture);
|
let db = TestDB::with_files(ra_fixture);
|
||||||
|
|
||||||
let krate = db.fetch_test_crate();
|
let krate = db.fetch_test_crate();
|
||||||
let def_map = db.crate_def_map(krate);
|
let def_map = crate_def_map(&db, krate);
|
||||||
let mut fn_def = None;
|
let mut fn_def = None;
|
||||||
'outer: for (_, module) in def_map.modules() {
|
'outer: for (_, module) in def_map.modules() {
|
||||||
for decl in module.scope.declarations() {
|
for decl in module.scope.declarations() {
|
||||||
|
@ -189,8 +189,8 @@ fn f() {
|
|||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
BlockId(3801) in BlockRelativeModuleId { block: Some(BlockId(3800)), local_id: Idx::<ModuleData>(1) }
|
BlockId(3c01) in BlockRelativeModuleId { block: Some(BlockId(3c00)), local_id: Idx::<ModuleData>(1) }
|
||||||
BlockId(3800) in BlockRelativeModuleId { block: None, local_id: Idx::<ModuleData>(0) }
|
BlockId(3c00) in BlockRelativeModuleId { block: None, local_id: Idx::<ModuleData>(0) }
|
||||||
crate scope
|
crate scope
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
GenericDefId, ModuleDefId,
|
GenericDefId, ModuleDefId,
|
||||||
expr_store::pretty::{print_function, print_struct},
|
expr_store::pretty::{print_function, print_struct},
|
||||||
|
nameres::crate_def_map,
|
||||||
test_db::TestDB,
|
test_db::TestDB,
|
||||||
};
|
};
|
||||||
use expect_test::{Expect, expect};
|
use expect_test::{Expect, expect};
|
||||||
@ -12,7 +13,7 @@ fn lower_and_print(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expe
|
|||||||
let db = TestDB::with_files(ra_fixture);
|
let db = TestDB::with_files(ra_fixture);
|
||||||
|
|
||||||
let krate = db.fetch_test_crate();
|
let krate = db.fetch_test_crate();
|
||||||
let def_map = db.crate_def_map(krate);
|
let def_map = crate_def_map(&db, krate);
|
||||||
let mut defs = vec![];
|
let mut defs = vec![];
|
||||||
for (_, module) in def_map.modules() {
|
for (_, module) in def_map.modules() {
|
||||||
for decl in module.scope.declarations() {
|
for decl in module.scope.declarations() {
|
||||||
|
@ -52,7 +52,7 @@ pub fn find_path(
|
|||||||
ignore_local_imports,
|
ignore_local_imports,
|
||||||
is_std_item: item_module.krate().data(db).origin.is_lang(),
|
is_std_item: item_module.krate().data(db).origin.is_lang(),
|
||||||
from,
|
from,
|
||||||
from_def_map: &from.def_map(db),
|
from_def_map: from.def_map(db),
|
||||||
fuel: Cell::new(FIND_PATH_FUEL),
|
fuel: Cell::new(FIND_PATH_FUEL),
|
||||||
},
|
},
|
||||||
item,
|
item,
|
||||||
@ -691,7 +691,7 @@ mod tests {
|
|||||||
let (def_map, local_def_map) = module.local_def_map(&db);
|
let (def_map, local_def_map) = module.local_def_map(&db);
|
||||||
let resolved = def_map
|
let resolved = def_map
|
||||||
.resolve_path(
|
.resolve_path(
|
||||||
&local_def_map,
|
local_def_map,
|
||||||
&db,
|
&db,
|
||||||
module.local_id,
|
module.local_id,
|
||||||
&mod_path,
|
&mod_path,
|
||||||
|
@ -16,7 +16,7 @@ use crate::{
|
|||||||
AssocItemId, AttrDefId, Complete, FxIndexMap, ModuleDefId, ModuleId, TraitId,
|
AssocItemId, AttrDefId, Complete, FxIndexMap, ModuleDefId, ModuleId, TraitId,
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
item_scope::{ImportOrExternCrate, ItemInNs},
|
item_scope::{ImportOrExternCrate, ItemInNs},
|
||||||
nameres::DefMap,
|
nameres::{DefMap, crate_def_map},
|
||||||
visibility::Visibility,
|
visibility::Visibility,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ impl ImportMap {
|
|||||||
fn collect_import_map(db: &dyn DefDatabase, krate: Crate) -> ImportMapIndex {
|
fn collect_import_map(db: &dyn DefDatabase, krate: Crate) -> ImportMapIndex {
|
||||||
let _p = tracing::info_span!("collect_import_map").entered();
|
let _p = tracing::info_span!("collect_import_map").entered();
|
||||||
|
|
||||||
let def_map = db.crate_def_map(krate);
|
let def_map = crate_def_map(db, krate);
|
||||||
let mut map = FxIndexMap::default();
|
let mut map = FxIndexMap::default();
|
||||||
|
|
||||||
// We look only into modules that are public(ly reexported), starting with the crate root.
|
// We look only into modules that are public(ly reexported), starting with the crate root.
|
||||||
|
@ -10,6 +10,7 @@ use triomphe::Arc;
|
|||||||
use crate::{
|
use crate::{
|
||||||
AdtId, AssocItemId, AttrDefId, Crate, EnumId, EnumVariantId, FunctionId, ImplId, ModuleDefId,
|
AdtId, AssocItemId, AttrDefId, Crate, EnumId, EnumVariantId, FunctionId, ImplId, ModuleDefId,
|
||||||
StaticId, StructId, TraitId, TypeAliasId, UnionId, db::DefDatabase, expr_store::path::Path,
|
StaticId, StructId, TraitId, TypeAliasId, UnionId, db::DefDatabase, expr_store::path::Path,
|
||||||
|
nameres::crate_def_map,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
@ -90,7 +91,7 @@ pub fn crate_lang_items(db: &dyn DefDatabase, krate: Crate) -> Option<Box<LangIt
|
|||||||
|
|
||||||
let mut lang_items = LangItems::default();
|
let mut lang_items = LangItems::default();
|
||||||
|
|
||||||
let crate_def_map = db.crate_def_map(krate);
|
let crate_def_map = crate_def_map(db, krate);
|
||||||
|
|
||||||
for (_, module_data) in crate_def_map.modules() {
|
for (_, module_data) in crate_def_map.modules() {
|
||||||
for impl_def in module_data.scope.impls() {
|
for impl_def in module_data.scope.impls() {
|
||||||
@ -209,7 +210,7 @@ pub(crate) fn crate_notable_traits(db: &dyn DefDatabase, krate: Crate) -> Option
|
|||||||
|
|
||||||
let mut traits = Vec::new();
|
let mut traits = Vec::new();
|
||||||
|
|
||||||
let crate_def_map = db.crate_def_map(krate);
|
let crate_def_map = crate_def_map(db, krate);
|
||||||
|
|
||||||
for (_, module_data) in crate_def_map.modules() {
|
for (_, module_data) in crate_def_map.modules() {
|
||||||
for def in module_data.scope.declarations() {
|
for def in module_data.scope.declarations() {
|
||||||
|
@ -92,7 +92,7 @@ use crate::{
|
|||||||
Const, Enum, ExternCrate, Function, Impl, ItemTreeId, ItemTreeNode, Macro2, MacroRules,
|
Const, Enum, ExternCrate, Function, Impl, ItemTreeId, ItemTreeNode, Macro2, MacroRules,
|
||||||
Static, Struct, Trait, TraitAlias, TypeAlias, Union, Use, Variant,
|
Static, Struct, Trait, TraitAlias, TypeAlias, Union, Use, Variant,
|
||||||
},
|
},
|
||||||
nameres::LocalDefMap,
|
nameres::{LocalDefMap, block_def_map, crate_def_map, crate_local_def_map},
|
||||||
signatures::VariantFields,
|
signatures::VariantFields,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -324,12 +324,13 @@ pub struct CrateRootModuleId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl CrateRootModuleId {
|
impl CrateRootModuleId {
|
||||||
pub fn def_map(&self, db: &dyn DefDatabase) -> Arc<DefMap> {
|
pub fn def_map(self, db: &dyn DefDatabase) -> &DefMap {
|
||||||
db.crate_def_map(self.krate)
|
crate_def_map(db, self.krate)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn local_def_map(&self, db: &dyn DefDatabase) -> (Arc<DefMap>, Arc<LocalDefMap>) {
|
pub(crate) fn local_def_map(self, db: &dyn DefDatabase) -> (&DefMap, &LocalDefMap) {
|
||||||
db.crate_local_def_map(self.krate)
|
let def_map = crate_local_def_map(db, self.krate);
|
||||||
|
(def_map.def_map(db), def_map.local(db))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn krate(self) -> Crate {
|
pub fn krate(self) -> Crate {
|
||||||
@ -390,26 +391,29 @@ pub struct ModuleId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ModuleId {
|
impl ModuleId {
|
||||||
pub fn def_map(self, db: &dyn DefDatabase) -> Arc<DefMap> {
|
pub fn def_map(self, db: &dyn DefDatabase) -> &DefMap {
|
||||||
match self.block {
|
match self.block {
|
||||||
Some(block) => db.block_def_map(block),
|
Some(block) => block_def_map(db, block),
|
||||||
None => db.crate_def_map(self.krate),
|
None => crate_def_map(db, self.krate),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn local_def_map(self, db: &dyn DefDatabase) -> (Arc<DefMap>, Arc<LocalDefMap>) {
|
pub(crate) fn local_def_map(self, db: &dyn DefDatabase) -> (&DefMap, &LocalDefMap) {
|
||||||
match self.block {
|
match self.block {
|
||||||
Some(block) => (db.block_def_map(block), self.only_local_def_map(db)),
|
Some(block) => (block_def_map(db, block), self.only_local_def_map(db)),
|
||||||
None => db.crate_local_def_map(self.krate),
|
None => {
|
||||||
|
let def_map = crate_local_def_map(db, self.krate);
|
||||||
|
(def_map.def_map(db), def_map.local(db))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn only_local_def_map(self, db: &dyn DefDatabase) -> Arc<LocalDefMap> {
|
pub(crate) fn only_local_def_map(self, db: &dyn DefDatabase) -> &LocalDefMap {
|
||||||
db.crate_local_def_map(self.krate).1
|
crate_local_def_map(db, self.krate).local(db)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn crate_def_map(self, db: &dyn DefDatabase) -> Arc<DefMap> {
|
pub fn crate_def_map(self, db: &dyn DefDatabase) -> &DefMap {
|
||||||
db.crate_def_map(self.krate)
|
crate_def_map(db, self.krate)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn krate(self) -> Crate {
|
pub fn krate(self) -> Crate {
|
||||||
|
@ -39,7 +39,7 @@ use test_fixture::WithFixture;
|
|||||||
use crate::{
|
use crate::{
|
||||||
AdtId, Lookup, ModuleDefId,
|
AdtId, Lookup, ModuleDefId,
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
nameres::{DefMap, ModuleSource},
|
nameres::{DefMap, ModuleSource, crate_def_map},
|
||||||
src::HasSource,
|
src::HasSource,
|
||||||
test_db::TestDB,
|
test_db::TestDB,
|
||||||
tt::TopSubtree,
|
tt::TopSubtree,
|
||||||
@ -49,7 +49,7 @@ use crate::{
|
|||||||
fn check_errors(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {
|
fn check_errors(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {
|
||||||
let db = TestDB::with_files(ra_fixture);
|
let db = TestDB::with_files(ra_fixture);
|
||||||
let krate = db.fetch_test_crate();
|
let krate = db.fetch_test_crate();
|
||||||
let def_map = db.crate_def_map(krate);
|
let def_map = crate_def_map(&db, krate);
|
||||||
let errors = def_map
|
let errors = def_map
|
||||||
.modules()
|
.modules()
|
||||||
.flat_map(|module| module.1.scope.all_macro_calls())
|
.flat_map(|module| module.1.scope.all_macro_calls())
|
||||||
@ -113,7 +113,7 @@ pub fn identity_when_valid(_attr: TokenStream, item: TokenStream) -> TokenStream
|
|||||||
|
|
||||||
let (body, sm) = db.body_with_source_map(body);
|
let (body, sm) = db.body_with_source_map(body);
|
||||||
if let Some(it) =
|
if let Some(it) =
|
||||||
body.blocks(db).find_map(|block| resolve(db, &block.1, ast_id, ast_ptr))
|
body.blocks(db).find_map(|block| resolve(db, block.1, ast_id, ast_ptr))
|
||||||
{
|
{
|
||||||
return Some(it);
|
return Some(it);
|
||||||
}
|
}
|
||||||
@ -127,7 +127,7 @@ pub fn identity_when_valid(_attr: TokenStream, item: TokenStream) -> TokenStream
|
|||||||
|
|
||||||
let db = TestDB::with_files_extra_proc_macros(ra_fixture, extra_proc_macros);
|
let db = TestDB::with_files_extra_proc_macros(ra_fixture, extra_proc_macros);
|
||||||
let krate = db.fetch_test_crate();
|
let krate = db.fetch_test_crate();
|
||||||
let def_map = db.crate_def_map(krate);
|
let def_map = crate_def_map(&db, krate);
|
||||||
let local_id = DefMap::ROOT;
|
let local_id = DefMap::ROOT;
|
||||||
let source = def_map[local_id].definition_source(&db);
|
let source = def_map[local_id].definition_source(&db);
|
||||||
let source_file = match source.value {
|
let source_file = match source.value {
|
||||||
@ -142,7 +142,7 @@ pub fn identity_when_valid(_attr: TokenStream, item: TokenStream) -> TokenStream
|
|||||||
let ast_id = db.ast_id_map(source.file_id).ast_id(¯o_call_node);
|
let ast_id = db.ast_id_map(source.file_id).ast_id(¯o_call_node);
|
||||||
let ast_id = InFile::new(source.file_id, ast_id);
|
let ast_id = InFile::new(source.file_id, ast_id);
|
||||||
let ptr = InFile::new(source.file_id, AstPtr::new(¯o_call_node));
|
let ptr = InFile::new(source.file_id, AstPtr::new(¯o_call_node));
|
||||||
let macro_call_id = resolve(&db, &def_map, ast_id, ptr)
|
let macro_call_id = resolve(&db, def_map, ast_id, ptr)
|
||||||
.unwrap_or_else(|| panic!("unable to find semantic macro call {macro_call_node}"));
|
.unwrap_or_else(|| panic!("unable to find semantic macro call {macro_call_node}"));
|
||||||
let expansion_result = db.parse_macro_expansion(macro_call_id);
|
let expansion_result = db.parse_macro_expansion(macro_call_id);
|
||||||
expansions.push((macro_call_node.clone(), expansion_result));
|
expansions.push((macro_call_node.clone(), expansion_result));
|
||||||
|
@ -112,6 +112,18 @@ pub struct LocalDefMap {
|
|||||||
extern_prelude: FxIndexMap<Name, (CrateRootModuleId, Option<ExternCrateId>)>,
|
extern_prelude: FxIndexMap<Name, (CrateRootModuleId, Option<ExternCrateId>)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::hash::Hash for LocalDefMap {
|
||||||
|
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||||
|
let LocalDefMap { extern_prelude } = self;
|
||||||
|
extern_prelude.len().hash(state);
|
||||||
|
for (name, (crate_root, extern_crate)) in extern_prelude {
|
||||||
|
name.hash(state);
|
||||||
|
crate_root.hash(state);
|
||||||
|
extern_crate.hash(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl LocalDefMap {
|
impl LocalDefMap {
|
||||||
pub(crate) const EMPTY: &Self =
|
pub(crate) const EMPTY: &Self =
|
||||||
&Self { extern_prelude: FxIndexMap::with_hasher(rustc_hash::FxBuildHasher) };
|
&Self { extern_prelude: FxIndexMap::with_hasher(rustc_hash::FxBuildHasher) };
|
||||||
@ -250,7 +262,7 @@ struct BlockRelativeModuleId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl BlockRelativeModuleId {
|
impl BlockRelativeModuleId {
|
||||||
fn def_map(self, db: &dyn DefDatabase, krate: Crate) -> Arc<DefMap> {
|
fn def_map(self, db: &dyn DefDatabase, krate: Crate) -> &DefMap {
|
||||||
self.into_module(krate).def_map(db)
|
self.into_module(krate).def_map(db)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -358,6 +370,87 @@ pub struct ModuleData {
|
|||||||
pub scope: ItemScope,
|
pub scope: ItemScope,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn crate_def_map(db: &dyn DefDatabase, crate_id: Crate) -> &DefMap {
|
||||||
|
crate_local_def_map(db, crate_id).def_map(db)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(unused_lifetimes)]
|
||||||
|
mod __ {
|
||||||
|
use super::*;
|
||||||
|
#[salsa_macros::tracked]
|
||||||
|
pub(crate) struct DefMapPair<'db> {
|
||||||
|
#[tracked]
|
||||||
|
#[return_ref]
|
||||||
|
pub(crate) def_map: DefMap,
|
||||||
|
#[return_ref]
|
||||||
|
pub(crate) local: LocalDefMap,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub(crate) use __::DefMapPair;
|
||||||
|
|
||||||
|
#[salsa_macros::tracked(return_ref)]
|
||||||
|
pub(crate) fn crate_local_def_map(db: &dyn DefDatabase, crate_id: Crate) -> DefMapPair<'_> {
|
||||||
|
let krate = crate_id.data(db);
|
||||||
|
let _p = tracing::info_span!(
|
||||||
|
"crate_def_map_query",
|
||||||
|
name=?crate_id
|
||||||
|
.extra_data(db)
|
||||||
|
.display_name
|
||||||
|
.as_ref()
|
||||||
|
.map(|it| it.crate_name().to_smolstr())
|
||||||
|
.unwrap_or_default()
|
||||||
|
)
|
||||||
|
.entered();
|
||||||
|
|
||||||
|
let module_data = ModuleData::new(
|
||||||
|
ModuleOrigin::CrateRoot { definition: krate.root_file_id(db) },
|
||||||
|
Visibility::Public,
|
||||||
|
);
|
||||||
|
|
||||||
|
let def_map =
|
||||||
|
DefMap::empty(crate_id, Arc::new(DefMapCrateData::new(krate.edition)), module_data, None);
|
||||||
|
let (def_map, local_def_map) = collector::collect_defs(
|
||||||
|
db,
|
||||||
|
def_map,
|
||||||
|
TreeId::new(krate.root_file_id(db).into(), None),
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
|
||||||
|
DefMapPair::new(db, def_map, local_def_map)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[salsa_macros::tracked(return_ref)]
|
||||||
|
pub fn block_def_map(db: &dyn DefDatabase, block_id: BlockId) -> DefMap {
|
||||||
|
let BlockLoc { ast_id, module } = block_id.lookup(db);
|
||||||
|
|
||||||
|
let visibility = Visibility::Module(
|
||||||
|
ModuleId { krate: module.krate, local_id: DefMap::ROOT, block: module.block },
|
||||||
|
VisibilityExplicitness::Implicit,
|
||||||
|
);
|
||||||
|
let module_data =
|
||||||
|
ModuleData::new(ModuleOrigin::BlockExpr { block: ast_id, id: block_id }, visibility);
|
||||||
|
|
||||||
|
let local_def_map = crate_local_def_map(db, module.krate);
|
||||||
|
let def_map = DefMap::empty(
|
||||||
|
module.krate,
|
||||||
|
local_def_map.def_map(db).data.clone(),
|
||||||
|
module_data,
|
||||||
|
Some(BlockInfo {
|
||||||
|
block: block_id,
|
||||||
|
parent: BlockRelativeModuleId { block: module.block, local_id: module.local_id },
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
let (def_map, _) = collector::collect_defs(
|
||||||
|
db,
|
||||||
|
def_map,
|
||||||
|
TreeId::new(ast_id.file_id, Some(block_id)),
|
||||||
|
Some(local_def_map.local(db)),
|
||||||
|
);
|
||||||
|
def_map
|
||||||
|
}
|
||||||
|
|
||||||
impl DefMap {
|
impl DefMap {
|
||||||
/// The module id of a crate or block root.
|
/// The module id of a crate or block root.
|
||||||
pub const ROOT: LocalModuleId = LocalModuleId::from_raw(la_arena::RawIdx::from_u32(0));
|
pub const ROOT: LocalModuleId = LocalModuleId::from_raw(la_arena::RawIdx::from_u32(0));
|
||||||
@ -366,77 +459,6 @@ impl DefMap {
|
|||||||
self.data.edition
|
self.data.edition
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn crate_def_map_query(db: &dyn DefDatabase, crate_id: Crate) -> Arc<DefMap> {
|
|
||||||
db.crate_local_def_map(crate_id).0
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn crate_local_def_map_query(
|
|
||||||
db: &dyn DefDatabase,
|
|
||||||
crate_id: Crate,
|
|
||||||
) -> (Arc<DefMap>, Arc<LocalDefMap>) {
|
|
||||||
let krate = crate_id.data(db);
|
|
||||||
let _p = tracing::info_span!(
|
|
||||||
"crate_def_map_query",
|
|
||||||
name=?crate_id
|
|
||||||
.extra_data(db)
|
|
||||||
.display_name
|
|
||||||
.as_ref()
|
|
||||||
.map(|it| it.crate_name().to_smolstr())
|
|
||||||
.unwrap_or_default()
|
|
||||||
)
|
|
||||||
.entered();
|
|
||||||
|
|
||||||
let module_data = ModuleData::new(
|
|
||||||
ModuleOrigin::CrateRoot { definition: krate.root_file_id(db) },
|
|
||||||
Visibility::Public,
|
|
||||||
);
|
|
||||||
|
|
||||||
let def_map = DefMap::empty(
|
|
||||||
crate_id,
|
|
||||||
Arc::new(DefMapCrateData::new(krate.edition)),
|
|
||||||
module_data,
|
|
||||||
None,
|
|
||||||
);
|
|
||||||
let (def_map, local_def_map) = collector::collect_defs(
|
|
||||||
db,
|
|
||||||
def_map,
|
|
||||||
TreeId::new(krate.root_file_id(db).into(), None),
|
|
||||||
None,
|
|
||||||
);
|
|
||||||
|
|
||||||
(Arc::new(def_map), Arc::new(local_def_map))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn block_def_map_query(db: &dyn DefDatabase, block_id: BlockId) -> Arc<DefMap> {
|
|
||||||
let BlockLoc { ast_id, module } = block_id.lookup(db);
|
|
||||||
|
|
||||||
let visibility = Visibility::Module(
|
|
||||||
ModuleId { krate: module.krate, local_id: Self::ROOT, block: module.block },
|
|
||||||
VisibilityExplicitness::Implicit,
|
|
||||||
);
|
|
||||||
let module_data =
|
|
||||||
ModuleData::new(ModuleOrigin::BlockExpr { block: ast_id, id: block_id }, visibility);
|
|
||||||
|
|
||||||
let (crate_map, crate_local_map) = db.crate_local_def_map(module.krate);
|
|
||||||
let def_map = DefMap::empty(
|
|
||||||
module.krate,
|
|
||||||
crate_map.data.clone(),
|
|
||||||
module_data,
|
|
||||||
Some(BlockInfo {
|
|
||||||
block: block_id,
|
|
||||||
parent: BlockRelativeModuleId { block: module.block, local_id: module.local_id },
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
let (def_map, _) = collector::collect_defs(
|
|
||||||
db,
|
|
||||||
def_map,
|
|
||||||
TreeId::new(ast_id.file_id, Some(block_id)),
|
|
||||||
Some(crate_local_map),
|
|
||||||
);
|
|
||||||
Arc::new(def_map)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn empty(
|
fn empty(
|
||||||
krate: Crate,
|
krate: Crate,
|
||||||
crate_data: Arc<DefMapCrateData>,
|
crate_data: Arc<DefMapCrateData>,
|
||||||
@ -595,7 +617,7 @@ impl DefMap {
|
|||||||
go(&mut buf, db, current_map, "block scope", Self::ROOT);
|
go(&mut buf, db, current_map, "block scope", Self::ROOT);
|
||||||
buf.push('\n');
|
buf.push('\n');
|
||||||
arc = block.parent.def_map(db, self.krate);
|
arc = block.parent.def_map(db, self.krate);
|
||||||
current_map = &arc;
|
current_map = arc;
|
||||||
}
|
}
|
||||||
go(&mut buf, db, current_map, "crate", Self::ROOT);
|
go(&mut buf, db, current_map, "crate", Self::ROOT);
|
||||||
return buf;
|
return buf;
|
||||||
@ -628,7 +650,7 @@ impl DefMap {
|
|||||||
while let Some(block) = current_map.block {
|
while let Some(block) = current_map.block {
|
||||||
format_to!(buf, "{:?} in {:?}\n", block.block, block.parent);
|
format_to!(buf, "{:?} in {:?}\n", block.block, block.parent);
|
||||||
arc = block.parent.def_map(db, self.krate);
|
arc = block.parent.def_map(db, self.krate);
|
||||||
current_map = &arc;
|
current_map = arc;
|
||||||
}
|
}
|
||||||
|
|
||||||
format_to!(buf, "crate scope\n");
|
format_to!(buf, "crate scope\n");
|
||||||
@ -708,7 +730,7 @@ impl DefMap {
|
|||||||
let mut block = self.block;
|
let mut block = self.block;
|
||||||
while let Some(block_info) = block {
|
while let Some(block_info) = block {
|
||||||
let parent = block_info.parent.def_map(db, self.krate);
|
let parent = block_info.parent.def_map(db, self.krate);
|
||||||
if let Some(it) = f(&parent, block_info.parent.local_id) {
|
if let Some(it) = f(parent, block_info.parent.local_id) {
|
||||||
return Some(it);
|
return Some(it);
|
||||||
}
|
}
|
||||||
block = parent.block;
|
block = parent.block;
|
||||||
|
@ -117,8 +117,8 @@ impl ImplItems {
|
|||||||
struct AssocItemCollector<'a> {
|
struct AssocItemCollector<'a> {
|
||||||
db: &'a dyn DefDatabase,
|
db: &'a dyn DefDatabase,
|
||||||
module_id: ModuleId,
|
module_id: ModuleId,
|
||||||
def_map: Arc<DefMap>,
|
def_map: &'a DefMap,
|
||||||
local_def_map: Arc<LocalDefMap>,
|
local_def_map: &'a LocalDefMap,
|
||||||
diagnostics: Vec<DefDiagnostic>,
|
diagnostics: Vec<DefDiagnostic>,
|
||||||
container: ItemContainerId,
|
container: ItemContainerId,
|
||||||
|
|
||||||
@ -183,7 +183,7 @@ impl<'a> AssocItemCollector<'a> {
|
|||||||
let ast_id_with_path = AstIdWithPath { path: attr.path.clone(), ast_id };
|
let ast_id_with_path = AstIdWithPath { path: attr.path.clone(), ast_id };
|
||||||
|
|
||||||
match self.def_map.resolve_attr_macro(
|
match self.def_map.resolve_attr_macro(
|
||||||
&self.local_def_map,
|
self.local_def_map,
|
||||||
self.db,
|
self.db,
|
||||||
self.module_id.local_id,
|
self.module_id.local_id,
|
||||||
ast_id_with_path,
|
ast_id_with_path,
|
||||||
@ -255,7 +255,7 @@ impl<'a> AssocItemCollector<'a> {
|
|||||||
let resolver = |path: &_| {
|
let resolver = |path: &_| {
|
||||||
self.def_map
|
self.def_map
|
||||||
.resolve_path(
|
.resolve_path(
|
||||||
&self.local_def_map,
|
self.local_def_map,
|
||||||
self.db,
|
self.db,
|
||||||
self.module_id.local_id,
|
self.module_id.local_id,
|
||||||
path,
|
path,
|
||||||
|
@ -43,6 +43,7 @@ use crate::{
|
|||||||
nameres::{
|
nameres::{
|
||||||
BuiltinShadowMode, DefMap, LocalDefMap, MacroSubNs, ModuleData, ModuleOrigin, ResolveMode,
|
BuiltinShadowMode, DefMap, LocalDefMap, MacroSubNs, ModuleData, ModuleOrigin, ResolveMode,
|
||||||
attr_resolution::{attr_macro_as_call_id, derive_macro_as_call_id},
|
attr_resolution::{attr_macro_as_call_id, derive_macro_as_call_id},
|
||||||
|
crate_def_map,
|
||||||
diagnostics::DefDiagnostic,
|
diagnostics::DefDiagnostic,
|
||||||
mod_resolution::ModDir,
|
mod_resolution::ModDir,
|
||||||
path_resolution::{ReachedFixedPoint, ResolvePathResult},
|
path_resolution::{ReachedFixedPoint, ResolvePathResult},
|
||||||
@ -61,7 +62,7 @@ pub(super) fn collect_defs(
|
|||||||
db: &dyn DefDatabase,
|
db: &dyn DefDatabase,
|
||||||
def_map: DefMap,
|
def_map: DefMap,
|
||||||
tree_id: TreeId,
|
tree_id: TreeId,
|
||||||
crate_local_def_map: Option<Arc<LocalDefMap>>,
|
crate_local_def_map: Option<&LocalDefMap>,
|
||||||
) -> (DefMap, LocalDefMap) {
|
) -> (DefMap, LocalDefMap) {
|
||||||
let krate = &def_map.krate.data(db);
|
let krate = &def_map.krate.data(db);
|
||||||
let cfg_options = def_map.krate.cfg_options(db);
|
let cfg_options = def_map.krate.cfg_options(db);
|
||||||
@ -216,7 +217,7 @@ struct DefCollector<'a> {
|
|||||||
def_map: DefMap,
|
def_map: DefMap,
|
||||||
local_def_map: LocalDefMap,
|
local_def_map: LocalDefMap,
|
||||||
/// Set only in case of blocks.
|
/// Set only in case of blocks.
|
||||||
crate_local_def_map: Option<Arc<LocalDefMap>>,
|
crate_local_def_map: Option<&'a LocalDefMap>,
|
||||||
// The dependencies of the current crate, including optional deps like `test`.
|
// The dependencies of the current crate, including optional deps like `test`.
|
||||||
deps: FxHashMap<Name, BuiltDependency>,
|
deps: FxHashMap<Name, BuiltDependency>,
|
||||||
glob_imports: FxHashMap<LocalModuleId, Vec<(LocalModuleId, Visibility, GlobId)>>,
|
glob_imports: FxHashMap<LocalModuleId, Vec<(LocalModuleId, Visibility, GlobId)>>,
|
||||||
@ -533,7 +534,7 @@ impl DefCollector<'_> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let (per_ns, _) = self.def_map.resolve_path(
|
let (per_ns, _) = self.def_map.resolve_path(
|
||||||
self.crate_local_def_map.as_deref().unwrap_or(&self.local_def_map),
|
self.crate_local_def_map.unwrap_or(&self.local_def_map),
|
||||||
self.db,
|
self.db,
|
||||||
DefMap::ROOT,
|
DefMap::ROOT,
|
||||||
&path,
|
&path,
|
||||||
@ -556,7 +557,7 @@ impl DefCollector<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn local_def_map(&mut self) -> &LocalDefMap {
|
fn local_def_map(&mut self) -> &LocalDefMap {
|
||||||
self.crate_local_def_map.as_deref().unwrap_or(&self.local_def_map)
|
self.crate_local_def_map.unwrap_or(&self.local_def_map)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds a definition of procedural macro `name` to the root module.
|
/// Adds a definition of procedural macro `name` to the root module.
|
||||||
@ -688,7 +689,7 @@ impl DefCollector<'_> {
|
|||||||
let vis = self
|
let vis = self
|
||||||
.def_map
|
.def_map
|
||||||
.resolve_visibility(
|
.resolve_visibility(
|
||||||
self.crate_local_def_map.as_deref().unwrap_or(&self.local_def_map),
|
self.crate_local_def_map.unwrap_or(&self.local_def_map),
|
||||||
self.db,
|
self.db,
|
||||||
module_id,
|
module_id,
|
||||||
vis,
|
vis,
|
||||||
@ -731,7 +732,7 @@ impl DefCollector<'_> {
|
|||||||
names: Option<Vec<Name>>,
|
names: Option<Vec<Name>>,
|
||||||
extern_crate: Option<ExternCrateId>,
|
extern_crate: Option<ExternCrateId>,
|
||||||
) {
|
) {
|
||||||
let def_map = self.db.crate_def_map(krate);
|
let def_map = crate_def_map(self.db, krate);
|
||||||
// `#[macro_use]` brings macros into macro_use prelude. Yes, even non-`macro_rules!`
|
// `#[macro_use]` brings macros into macro_use prelude. Yes, even non-`macro_rules!`
|
||||||
// macros.
|
// macros.
|
||||||
let root_scope = &def_map[DefMap::ROOT].scope;
|
let root_scope = &def_map[DefMap::ROOT].scope;
|
||||||
@ -813,7 +814,7 @@ impl DefCollector<'_> {
|
|||||||
tracing::debug!("resolving import: {:?} ({:?})", import, self.def_map.data.edition);
|
tracing::debug!("resolving import: {:?} ({:?})", import, self.def_map.data.edition);
|
||||||
let ResolvePathResult { resolved_def, segment_index, reached_fixedpoint, prefix_info } =
|
let ResolvePathResult { resolved_def, segment_index, reached_fixedpoint, prefix_info } =
|
||||||
self.def_map.resolve_path_fp_with_macro(
|
self.def_map.resolve_path_fp_with_macro(
|
||||||
self.crate_local_def_map.as_deref().unwrap_or(&self.local_def_map),
|
self.crate_local_def_map.unwrap_or(&self.local_def_map),
|
||||||
self.db,
|
self.db,
|
||||||
ResolveMode::Import,
|
ResolveMode::Import,
|
||||||
module_id,
|
module_id,
|
||||||
@ -852,7 +853,7 @@ impl DefCollector<'_> {
|
|||||||
let vis = self
|
let vis = self
|
||||||
.def_map
|
.def_map
|
||||||
.resolve_visibility(
|
.resolve_visibility(
|
||||||
self.crate_local_def_map.as_deref().unwrap_or(&self.local_def_map),
|
self.crate_local_def_map.unwrap_or(&self.local_def_map),
|
||||||
self.db,
|
self.db,
|
||||||
module_id,
|
module_id,
|
||||||
&directive.import.visibility,
|
&directive.import.visibility,
|
||||||
@ -1280,7 +1281,7 @@ impl DefCollector<'_> {
|
|||||||
};
|
};
|
||||||
let resolver = |path: &_| {
|
let resolver = |path: &_| {
|
||||||
let resolved_res = self.def_map.resolve_path_fp_with_macro(
|
let resolved_res = self.def_map.resolve_path_fp_with_macro(
|
||||||
self.crate_local_def_map.as_deref().unwrap_or(&self.local_def_map),
|
self.crate_local_def_map.unwrap_or(&self.local_def_map),
|
||||||
self.db,
|
self.db,
|
||||||
ResolveMode::Other,
|
ResolveMode::Other,
|
||||||
directive.module_id,
|
directive.module_id,
|
||||||
@ -1347,7 +1348,7 @@ impl DefCollector<'_> {
|
|||||||
);
|
);
|
||||||
// Record its helper attributes.
|
// Record its helper attributes.
|
||||||
if def_id.krate != self.def_map.krate {
|
if def_id.krate != self.def_map.krate {
|
||||||
let def_map = self.db.crate_def_map(def_id.krate);
|
let def_map = crate_def_map(self.db, def_id.krate);
|
||||||
if let Some(helpers) = def_map.data.exported_derives.get(&def_id) {
|
if let Some(helpers) = def_map.data.exported_derives.get(&def_id) {
|
||||||
self.def_map
|
self.def_map
|
||||||
.derive_helpers_in_scope
|
.derive_helpers_in_scope
|
||||||
@ -1593,7 +1594,7 @@ impl DefCollector<'_> {
|
|||||||
self.def_map.krate,
|
self.def_map.krate,
|
||||||
|path| {
|
|path| {
|
||||||
let resolved_res = self.def_map.resolve_path_fp_with_macro(
|
let resolved_res = self.def_map.resolve_path_fp_with_macro(
|
||||||
self.crate_local_def_map.as_deref().unwrap_or(&self.local_def_map),
|
self.crate_local_def_map.unwrap_or(&self.local_def_map),
|
||||||
self.db,
|
self.db,
|
||||||
ResolveMode::Other,
|
ResolveMode::Other,
|
||||||
directive.module_id,
|
directive.module_id,
|
||||||
@ -1742,11 +1743,8 @@ impl ModCollector<'_, '_> {
|
|||||||
|
|
||||||
let module = self.def_collector.def_map.module_id(module_id);
|
let module = self.def_collector.def_map.module_id(module_id);
|
||||||
let def_map = &mut self.def_collector.def_map;
|
let def_map = &mut self.def_collector.def_map;
|
||||||
let local_def_map = self
|
let local_def_map =
|
||||||
.def_collector
|
self.def_collector.crate_local_def_map.unwrap_or(&self.def_collector.local_def_map);
|
||||||
.crate_local_def_map
|
|
||||||
.as_deref()
|
|
||||||
.unwrap_or(&self.def_collector.local_def_map);
|
|
||||||
|
|
||||||
match item {
|
match item {
|
||||||
ModItem::Mod(m) => self.collect_module(m, &attrs),
|
ModItem::Mod(m) => self.collect_module(m, &attrs),
|
||||||
@ -2173,10 +2171,7 @@ impl ModCollector<'_, '_> {
|
|||||||
let def_map = &mut self.def_collector.def_map;
|
let def_map = &mut self.def_collector.def_map;
|
||||||
let vis = def_map
|
let vis = def_map
|
||||||
.resolve_visibility(
|
.resolve_visibility(
|
||||||
self.def_collector
|
self.def_collector.crate_local_def_map.unwrap_or(&self.def_collector.local_def_map),
|
||||||
.crate_local_def_map
|
|
||||||
.as_deref()
|
|
||||||
.unwrap_or(&self.def_collector.local_def_map),
|
|
||||||
self.def_collector.db,
|
self.def_collector.db,
|
||||||
self.module_id,
|
self.module_id,
|
||||||
visibility,
|
visibility,
|
||||||
|
@ -18,14 +18,16 @@ use hir_expand::{
|
|||||||
};
|
};
|
||||||
use span::Edition;
|
use span::Edition;
|
||||||
use stdx::TupleExt;
|
use stdx::TupleExt;
|
||||||
use triomphe::Arc;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
AdtId, LocalModuleId, ModuleDefId,
|
AdtId, LocalModuleId, ModuleDefId,
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
item_scope::{BUILTIN_SCOPE, ImportOrExternCrate},
|
item_scope::{BUILTIN_SCOPE, ImportOrExternCrate},
|
||||||
item_tree::FieldsShape,
|
item_tree::FieldsShape,
|
||||||
nameres::{BlockInfo, BuiltinShadowMode, DefMap, LocalDefMap, MacroSubNs, sub_namespace_match},
|
nameres::{
|
||||||
|
BlockInfo, BuiltinShadowMode, DefMap, LocalDefMap, MacroSubNs, crate_def_map,
|
||||||
|
sub_namespace_match,
|
||||||
|
},
|
||||||
per_ns::PerNs,
|
per_ns::PerNs,
|
||||||
visibility::{RawVisibility, Visibility},
|
visibility::{RawVisibility, Visibility},
|
||||||
};
|
};
|
||||||
@ -175,7 +177,6 @@ impl DefMap {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut arc;
|
|
||||||
let mut current_map = self;
|
let mut current_map = self;
|
||||||
|
|
||||||
let mut merge = |new: ResolvePathResult| {
|
let mut merge = |new: ResolvePathResult| {
|
||||||
@ -197,8 +198,7 @@ impl DefMap {
|
|||||||
Some(block) if original_module == Self::ROOT => {
|
Some(block) if original_module == Self::ROOT => {
|
||||||
// Block modules "inherit" names from its parent module.
|
// Block modules "inherit" names from its parent module.
|
||||||
original_module = block.parent.local_id;
|
original_module = block.parent.local_id;
|
||||||
arc = block.parent.def_map(db, current_map.krate);
|
current_map = block.parent.def_map(db, current_map.krate);
|
||||||
current_map = &arc;
|
|
||||||
}
|
}
|
||||||
// Proper (non-block) modules, including those in block `DefMap`s, don't.
|
// Proper (non-block) modules, including those in block `DefMap`s, don't.
|
||||||
_ => {
|
_ => {
|
||||||
@ -206,8 +206,7 @@ impl DefMap {
|
|||||||
// A module inside a block. Do not resolve items declared in upper blocks, but we do need to get
|
// A module inside a block. Do not resolve items declared in upper blocks, but we do need to get
|
||||||
// the prelude items (which are not inserted into blocks because they can be overridden there).
|
// the prelude items (which are not inserted into blocks because they can be overridden there).
|
||||||
original_module = Self::ROOT;
|
original_module = Self::ROOT;
|
||||||
arc = db.crate_def_map(self.krate);
|
current_map = crate_def_map(db, self.krate);
|
||||||
current_map = &arc;
|
|
||||||
|
|
||||||
let new = current_map.resolve_path_fp_in_all_preludes(
|
let new = current_map.resolve_path_fp_in_all_preludes(
|
||||||
local_def_map,
|
local_def_map,
|
||||||
@ -255,7 +254,7 @@ impl DefMap {
|
|||||||
cov_mark::hit!(macro_dollar_crate_self);
|
cov_mark::hit!(macro_dollar_crate_self);
|
||||||
PerNs::types(self.crate_root().into(), Visibility::Public, None)
|
PerNs::types(self.crate_root().into(), Visibility::Public, None)
|
||||||
} else {
|
} else {
|
||||||
let def_map = db.crate_def_map(krate);
|
let def_map = crate_def_map(db, krate);
|
||||||
let module = def_map.module_id(Self::ROOT);
|
let module = def_map.module_id(Self::ROOT);
|
||||||
cov_mark::hit!(macro_dollar_crate_other);
|
cov_mark::hit!(macro_dollar_crate_other);
|
||||||
PerNs::types(module.into(), Visibility::Public, None)
|
PerNs::types(module.into(), Visibility::Public, None)
|
||||||
@ -314,7 +313,7 @@ impl DefMap {
|
|||||||
// Adjust `local_id` to `self`, i.e. the nearest non-block module.
|
// Adjust `local_id` to `self`, i.e. the nearest non-block module.
|
||||||
if def_map.module_id(local_id).is_block_module() {
|
if def_map.module_id(local_id).is_block_module() {
|
||||||
(ext, local_id) = adjust_to_nearest_non_block_module(db, def_map, local_id);
|
(ext, local_id) = adjust_to_nearest_non_block_module(db, def_map, local_id);
|
||||||
def_map = &ext;
|
def_map = ext;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Go up the module tree but skip block modules as `super` always refers to the
|
// Go up the module tree but skip block modules as `super` always refers to the
|
||||||
@ -327,7 +326,7 @@ impl DefMap {
|
|||||||
if def_map.module_id(local_id).is_block_module() {
|
if def_map.module_id(local_id).is_block_module() {
|
||||||
(ext, local_id) =
|
(ext, local_id) =
|
||||||
adjust_to_nearest_non_block_module(db, def_map, local_id);
|
adjust_to_nearest_non_block_module(db, def_map, local_id);
|
||||||
def_map = &ext;
|
def_map = ext;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
stdx::always!(def_map.block.is_none());
|
stdx::always!(def_map.block.is_none());
|
||||||
@ -772,7 +771,7 @@ impl DefMap {
|
|||||||
} else {
|
} else {
|
||||||
// Extend lifetime
|
// Extend lifetime
|
||||||
keep = prelude.def_map(db);
|
keep = prelude.def_map(db);
|
||||||
&keep
|
keep
|
||||||
};
|
};
|
||||||
def_map[prelude.local_id].scope.get(name)
|
def_map[prelude.local_id].scope.get(name)
|
||||||
} else {
|
} else {
|
||||||
@ -782,25 +781,23 @@ impl DefMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Given a block module, returns its nearest non-block module and the `DefMap` it belongs to.
|
/// Given a block module, returns its nearest non-block module and the `DefMap` it belongs to.
|
||||||
fn adjust_to_nearest_non_block_module(
|
fn adjust_to_nearest_non_block_module<'db>(
|
||||||
db: &dyn DefDatabase,
|
db: &'db dyn DefDatabase,
|
||||||
def_map: &DefMap,
|
def_map: &'db DefMap,
|
||||||
mut local_id: LocalModuleId,
|
mut local_id: LocalModuleId,
|
||||||
) -> (Arc<DefMap>, LocalModuleId) {
|
) -> (&'db DefMap, LocalModuleId) {
|
||||||
// INVARIANT: `local_id` in `def_map` must be a block module.
|
// INVARIANT: `local_id` in `def_map` must be a block module.
|
||||||
stdx::always!(def_map.module_id(local_id).is_block_module());
|
stdx::always!(def_map.module_id(local_id).is_block_module());
|
||||||
|
|
||||||
let mut ext;
|
|
||||||
// This needs to be a local variable due to our mighty lifetime.
|
// This needs to be a local variable due to our mighty lifetime.
|
||||||
let mut def_map = def_map;
|
let mut def_map = def_map;
|
||||||
loop {
|
loop {
|
||||||
let BlockInfo { parent, .. } = def_map.block.expect("block module without parent module");
|
let BlockInfo { parent, .. } = def_map.block.expect("block module without parent module");
|
||||||
|
|
||||||
ext = parent.def_map(db, def_map.krate);
|
def_map = parent.def_map(db, def_map.krate);
|
||||||
def_map = &ext;
|
|
||||||
local_id = parent.local_id;
|
local_id = parent.local_id;
|
||||||
if !parent.is_block_module() {
|
if !parent.is_block_module() {
|
||||||
return (ext, local_id);
|
return (def_map, local_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,20 +7,25 @@ mod primitives;
|
|||||||
use base_db::RootQueryDb;
|
use base_db::RootQueryDb;
|
||||||
use expect_test::{Expect, expect};
|
use expect_test::{Expect, expect};
|
||||||
use test_fixture::WithFixture;
|
use test_fixture::WithFixture;
|
||||||
use triomphe::Arc;
|
|
||||||
|
|
||||||
use crate::{db::DefDatabase, nameres::DefMap, test_db::TestDB};
|
use crate::{
|
||||||
|
nameres::{DefMap, crate_def_map},
|
||||||
|
test_db::TestDB,
|
||||||
|
};
|
||||||
|
|
||||||
fn compute_crate_def_map(#[rust_analyzer::rust_fixture] ra_fixture: &str) -> Arc<DefMap> {
|
fn compute_crate_def_map(
|
||||||
|
#[rust_analyzer::rust_fixture] ra_fixture: &str,
|
||||||
|
cb: impl FnOnce(&DefMap),
|
||||||
|
) {
|
||||||
let db = TestDB::with_files(ra_fixture);
|
let db = TestDB::with_files(ra_fixture);
|
||||||
let krate = db.fetch_test_crate();
|
let krate = db.fetch_test_crate();
|
||||||
db.crate_def_map(krate)
|
cb(crate_def_map(&db, krate));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_crate_def_map(#[rust_analyzer::rust_fixture] ra_fixture: &str) -> String {
|
fn render_crate_def_map(#[rust_analyzer::rust_fixture] ra_fixture: &str) -> String {
|
||||||
let db = TestDB::with_files(ra_fixture);
|
let db = TestDB::with_files(ra_fixture);
|
||||||
let krate = db.fetch_test_crate();
|
let krate = db.fetch_test_crate();
|
||||||
db.crate_def_map(krate).dump(&db)
|
crate_def_map(&db, krate).dump(&db)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {
|
fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {
|
||||||
|
@ -7,24 +7,37 @@ use span::Edition;
|
|||||||
use test_fixture::WithFixture;
|
use test_fixture::WithFixture;
|
||||||
use triomphe::Arc;
|
use triomphe::Arc;
|
||||||
|
|
||||||
use crate::{AdtId, ModuleDefId, db::DefDatabase, nameres::tests::TestDB};
|
use crate::{
|
||||||
|
AdtId, ModuleDefId,
|
||||||
|
db::DefDatabase,
|
||||||
|
nameres::{crate_def_map, tests::TestDB},
|
||||||
|
};
|
||||||
|
|
||||||
fn check_def_map_is_not_recomputed(ra_fixture_initial: &str, ra_fixture_change: &str) {
|
fn check_def_map_is_not_recomputed(
|
||||||
|
#[rust_analyzer::rust_fixture] ra_fixture_initial: &str,
|
||||||
|
#[rust_analyzer::rust_fixture] ra_fixture_change: &str,
|
||||||
|
) {
|
||||||
let (mut db, pos) = TestDB::with_position(ra_fixture_initial);
|
let (mut db, pos) = TestDB::with_position(ra_fixture_initial);
|
||||||
let krate = db.fetch_test_crate();
|
let krate = db.fetch_test_crate();
|
||||||
{
|
{
|
||||||
let events = db.log_executed(|| {
|
let events = db.log_executed(|| {
|
||||||
db.crate_def_map(krate);
|
crate_def_map(&db, krate);
|
||||||
});
|
});
|
||||||
assert!(format!("{events:?}").contains("crate_def_map"), "{events:#?}")
|
assert!(
|
||||||
|
format!("{events:?}").contains("crate_local_def_map"),
|
||||||
|
"no crate def map computed:\n{events:#?}",
|
||||||
|
)
|
||||||
}
|
}
|
||||||
db.set_file_text(pos.file_id.file_id(&db), ra_fixture_change);
|
db.set_file_text(pos.file_id.file_id(&db), ra_fixture_change);
|
||||||
|
|
||||||
{
|
{
|
||||||
let events = db.log_executed(|| {
|
let events = db.log_executed(|| {
|
||||||
db.crate_def_map(krate);
|
crate_def_map(&db, krate);
|
||||||
});
|
});
|
||||||
assert!(!format!("{events:?}").contains("crate_def_map"), "{events:#?}")
|
assert!(
|
||||||
|
!format!("{events:?}").contains("crate_local_def_map"),
|
||||||
|
"crate def map invalidated:\n{events:#?}",
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +57,7 @@ pub const BAZ: u32 = 0;
|
|||||||
);
|
);
|
||||||
|
|
||||||
for &krate in db.all_crates().iter() {
|
for &krate in db.all_crates().iter() {
|
||||||
db.crate_def_map(krate);
|
crate_def_map(&db, krate);
|
||||||
}
|
}
|
||||||
|
|
||||||
let all_crates_before = db.all_crates();
|
let all_crates_before = db.all_crates();
|
||||||
@ -94,11 +107,11 @@ pub const BAZ: u32 = 0;
|
|||||||
|
|
||||||
let events = db.log_executed(|| {
|
let events = db.log_executed(|| {
|
||||||
for &krate in db.all_crates().iter() {
|
for &krate in db.all_crates().iter() {
|
||||||
db.crate_def_map(krate);
|
crate_def_map(&db, krate);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let invalidated_def_maps =
|
let invalidated_def_maps =
|
||||||
events.iter().filter(|event| event.contains("crate_def_map")).count();
|
events.iter().filter(|event| event.contains("crate_local_def_map")).count();
|
||||||
assert_eq!(invalidated_def_maps, 1, "{events:#?}")
|
assert_eq!(invalidated_def_maps, 1, "{events:#?}")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -330,7 +343,7 @@ m!(Z);
|
|||||||
let krate = db.test_crate();
|
let krate = db.test_crate();
|
||||||
{
|
{
|
||||||
let events = db.log_executed(|| {
|
let events = db.log_executed(|| {
|
||||||
let crate_def_map = db.crate_def_map(krate);
|
let crate_def_map = crate_def_map(&db, krate);
|
||||||
let (_, module_data) = crate_def_map.modules.iter().last().unwrap();
|
let (_, module_data) = crate_def_map.modules.iter().last().unwrap();
|
||||||
assert_eq!(module_data.scope.resolutions().count(), 4);
|
assert_eq!(module_data.scope.resolutions().count(), 4);
|
||||||
});
|
});
|
||||||
@ -352,7 +365,7 @@ m!(Z);
|
|||||||
|
|
||||||
{
|
{
|
||||||
let events = db.log_executed(|| {
|
let events = db.log_executed(|| {
|
||||||
let crate_def_map = db.crate_def_map(krate);
|
let crate_def_map = crate_def_map(&db, krate);
|
||||||
let (_, module_data) = crate_def_map.modules.iter().last().unwrap();
|
let (_, module_data) = crate_def_map.modules.iter().last().unwrap();
|
||||||
assert_eq!(module_data.scope.resolutions().count(), 4);
|
assert_eq!(module_data.scope.resolutions().count(), 4);
|
||||||
});
|
});
|
||||||
@ -403,7 +416,7 @@ pub type Ty = ();
|
|||||||
|
|
||||||
{
|
{
|
||||||
let events = db.log_executed(|| {
|
let events = db.log_executed(|| {
|
||||||
let crate_def_map = db.crate_def_map(krate);
|
let crate_def_map = crate_def_map(&db, krate);
|
||||||
let (_, module_data) = crate_def_map.modules.iter().last().unwrap();
|
let (_, module_data) = crate_def_map.modules.iter().last().unwrap();
|
||||||
assert_eq!(module_data.scope.resolutions().count(), 8);
|
assert_eq!(module_data.scope.resolutions().count(), 8);
|
||||||
assert_eq!(module_data.scope.impls().count(), 1);
|
assert_eq!(module_data.scope.impls().count(), 1);
|
||||||
|
@ -736,7 +736,7 @@ pub struct bar;
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn macro_dollar_crate_is_correct_in_derive_meta() {
|
fn macro_dollar_crate_is_correct_in_derive_meta() {
|
||||||
let map = compute_crate_def_map(
|
compute_crate_def_map(
|
||||||
r#"
|
r#"
|
||||||
//- minicore: derive, clone
|
//- minicore: derive, clone
|
||||||
//- /main.rs crate:main deps:lib
|
//- /main.rs crate:main deps:lib
|
||||||
@ -753,13 +753,13 @@ macro_rules! foo {
|
|||||||
|
|
||||||
pub use core::clone::Clone;
|
pub use core::clone::Clone;
|
||||||
"#,
|
"#,
|
||||||
|
|map| assert_eq!(map.modules[DefMap::ROOT].scope.impls().len(), 1),
|
||||||
);
|
);
|
||||||
assert_eq!(map.modules[DefMap::ROOT].scope.impls().len(), 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn expand_derive() {
|
fn expand_derive() {
|
||||||
let map = compute_crate_def_map(
|
compute_crate_def_map(
|
||||||
r#"
|
r#"
|
||||||
//- /main.rs crate:main deps:core
|
//- /main.rs crate:main deps:core
|
||||||
use core::Copy;
|
use core::Copy;
|
||||||
@ -775,8 +775,8 @@ pub macro Copy {}
|
|||||||
#[rustc_builtin_macro]
|
#[rustc_builtin_macro]
|
||||||
pub macro Clone {}
|
pub macro Clone {}
|
||||||
"#,
|
"#,
|
||||||
|
|map| assert_eq!(map.modules[DefMap::ROOT].scope.impls().len(), 2),
|
||||||
);
|
);
|
||||||
assert_eq!(map.modules[DefMap::ROOT].scope.impls().len(), 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -803,7 +803,7 @@ pub trait Clone {}
|
|||||||
fn builtin_derive_with_unresolved_attributes_fall_back() {
|
fn builtin_derive_with_unresolved_attributes_fall_back() {
|
||||||
// Tests that we still resolve derives after ignoring an unresolved attribute.
|
// Tests that we still resolve derives after ignoring an unresolved attribute.
|
||||||
cov_mark::check!(unresolved_attribute_fallback);
|
cov_mark::check!(unresolved_attribute_fallback);
|
||||||
let map = compute_crate_def_map(
|
compute_crate_def_map(
|
||||||
r#"
|
r#"
|
||||||
//- /main.rs crate:main deps:core
|
//- /main.rs crate:main deps:core
|
||||||
use core::{Clone, derive};
|
use core::{Clone, derive};
|
||||||
@ -818,8 +818,8 @@ pub macro derive($item:item) {}
|
|||||||
#[rustc_builtin_macro]
|
#[rustc_builtin_macro]
|
||||||
pub macro Clone {}
|
pub macro Clone {}
|
||||||
"#,
|
"#,
|
||||||
|
|map| assert_eq!(map.modules[DefMap::ROOT].scope.impls().len(), 1),
|
||||||
);
|
);
|
||||||
assert_eq!(map.modules[DefMap::ROOT].scope.impls().len(), 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1096,7 +1096,7 @@ pub fn derive_macro_2(_item: TokenStream) -> TokenStream {
|
|||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
let krate = *db.all_crates().last().expect("no crate graph present");
|
let krate = *db.all_crates().last().expect("no crate graph present");
|
||||||
let def_map = db.crate_def_map(krate);
|
let def_map = crate_def_map(&db, krate);
|
||||||
|
|
||||||
assert_eq!(def_map.data.exported_derives.len(), 1);
|
assert_eq!(def_map.data.exported_derives.len(), 1);
|
||||||
match def_map.data.exported_derives.values().next() {
|
match def_map.data.exported_derives.values().next() {
|
||||||
@ -1446,7 +1446,7 @@ fn proc_attr(a: TokenStream, b: TokenStream) -> TokenStream { a }
|
|||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
let krate = *db.all_crates().last().expect("no crate graph present");
|
let krate = *db.all_crates().last().expect("no crate graph present");
|
||||||
let def_map = db.crate_def_map(krate);
|
let def_map = crate_def_map(&db, krate);
|
||||||
|
|
||||||
let root_module = &def_map[DefMap::ROOT].scope;
|
let root_module = &def_map[DefMap::ROOT].scope;
|
||||||
assert!(
|
assert!(
|
||||||
@ -1544,7 +1544,7 @@ macro_rules! mk_foo {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn macro_sub_namespace() {
|
fn macro_sub_namespace() {
|
||||||
let map = compute_crate_def_map(
|
compute_crate_def_map(
|
||||||
r#"
|
r#"
|
||||||
//- minicore: derive, clone
|
//- minicore: derive, clone
|
||||||
macro_rules! Clone { () => {} }
|
macro_rules! Clone { () => {} }
|
||||||
@ -1553,8 +1553,8 @@ macro_rules! derive { () => {} }
|
|||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct S;
|
struct S;
|
||||||
"#,
|
"#,
|
||||||
|
|map| assert_eq!(map.modules[DefMap::ROOT].scope.impls().len(), 1),
|
||||||
);
|
);
|
||||||
assert_eq!(map.modules[DefMap::ROOT].scope.impls().len(), 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -839,6 +839,7 @@ mod foo;
|
|||||||
#[path = "./foo.rs"]
|
#[path = "./foo.rs"]
|
||||||
mod foo;
|
mod foo;
|
||||||
"#,
|
"#,
|
||||||
|
|_| (),
|
||||||
);
|
);
|
||||||
|
|
||||||
compute_crate_def_map(
|
compute_crate_def_map(
|
||||||
@ -852,6 +853,7 @@ mod bar;
|
|||||||
#[path = "./foo.rs"]
|
#[path = "./foo.rs"]
|
||||||
mod foo;
|
mod foo;
|
||||||
"#,
|
"#,
|
||||||
|
|_| (),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,30 +34,30 @@ use crate::{
|
|||||||
item_scope::{BUILTIN_SCOPE, BuiltinShadowMode, ImportOrExternCrate, ImportOrGlob, ItemScope},
|
item_scope::{BUILTIN_SCOPE, BuiltinShadowMode, ImportOrExternCrate, ImportOrGlob, ItemScope},
|
||||||
item_tree::ImportAlias,
|
item_tree::ImportAlias,
|
||||||
lang_item::LangItemTarget,
|
lang_item::LangItemTarget,
|
||||||
nameres::{DefMap, LocalDefMap, MacroSubNs, ResolvePathResultPrefixInfo},
|
nameres::{DefMap, LocalDefMap, MacroSubNs, ResolvePathResultPrefixInfo, block_def_map},
|
||||||
per_ns::PerNs,
|
per_ns::PerNs,
|
||||||
type_ref::LifetimeRef,
|
type_ref::LifetimeRef,
|
||||||
visibility::{RawVisibility, Visibility},
|
visibility::{RawVisibility, Visibility},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Resolver {
|
pub struct Resolver<'db> {
|
||||||
/// The stack of scopes, where the inner-most scope is the last item.
|
/// The stack of scopes, where the inner-most scope is the last item.
|
||||||
///
|
///
|
||||||
/// When using, you generally want to process the scopes in reverse order,
|
/// When using, you generally want to process the scopes in reverse order,
|
||||||
/// there's `scopes` *method* for that.
|
/// there's `scopes` *method* for that.
|
||||||
scopes: Vec<Scope>,
|
scopes: Vec<Scope<'db>>,
|
||||||
module_scope: ModuleItemMap,
|
module_scope: ModuleItemMap<'db>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct ModuleItemMap {
|
struct ModuleItemMap<'db> {
|
||||||
def_map: Arc<DefMap>,
|
def_map: &'db DefMap,
|
||||||
local_def_map: Arc<LocalDefMap>,
|
local_def_map: &'db LocalDefMap,
|
||||||
module_id: LocalModuleId,
|
module_id: LocalModuleId,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for ModuleItemMap {
|
impl fmt::Debug for ModuleItemMap<'_> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
f.debug_struct("ModuleItemMap").field("module_id", &self.module_id).finish()
|
f.debug_struct("ModuleItemMap").field("module_id", &self.module_id).finish()
|
||||||
}
|
}
|
||||||
@ -80,9 +80,9 @@ impl fmt::Debug for ExprScope {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
enum Scope {
|
enum Scope<'db> {
|
||||||
/// All the items and imported names of a module
|
/// All the items and imported names of a module
|
||||||
BlockScope(ModuleItemMap),
|
BlockScope(ModuleItemMap<'db>),
|
||||||
/// Brings the generic parameters of an item into scope as well as the `Self` type alias /
|
/// Brings the generic parameters of an item into scope as well as the `Self` type alias /
|
||||||
/// generic for ADTs and impls.
|
/// generic for ADTs and impls.
|
||||||
GenericParams { def: GenericDefId, params: Arc<GenericParams> },
|
GenericParams { def: GenericDefId, params: Arc<GenericParams> },
|
||||||
@ -133,7 +133,7 @@ pub enum LifetimeNs {
|
|||||||
LifetimeParam(LifetimeParamId),
|
LifetimeParam(LifetimeParamId),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Resolver {
|
impl<'db> Resolver<'db> {
|
||||||
/// Resolve known trait from std, like `std::futures::Future`
|
/// Resolve known trait from std, like `std::futures::Future`
|
||||||
pub fn resolve_known_trait(&self, db: &dyn DefDatabase, path: &ModPath) -> Option<TraitId> {
|
pub fn resolve_known_trait(&self, db: &dyn DefDatabase, path: &ModPath) -> Option<TraitId> {
|
||||||
let res = self.resolve_module_path(db, path, BuiltinShadowMode::Other).take_types()?;
|
let res = self.resolve_module_path(db, path, BuiltinShadowMode::Other).take_types()?;
|
||||||
@ -580,7 +580,7 @@ impl Resolver {
|
|||||||
for scope in self.scopes() {
|
for scope in self.scopes() {
|
||||||
scope.process_names(&mut res, db);
|
scope.process_names(&mut res, db);
|
||||||
}
|
}
|
||||||
let ModuleItemMap { ref def_map, module_id, ref local_def_map } = self.module_scope;
|
let ModuleItemMap { def_map, module_id, local_def_map } = self.module_scope;
|
||||||
// FIXME: should we provide `self` here?
|
// FIXME: should we provide `self` here?
|
||||||
// f(
|
// f(
|
||||||
// Name::self_param(),
|
// Name::self_param(),
|
||||||
@ -842,14 +842,14 @@ impl Resolver {
|
|||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn update_to_inner_scope(
|
pub fn update_to_inner_scope(
|
||||||
&mut self,
|
&mut self,
|
||||||
db: &dyn DefDatabase,
|
db: &'db dyn DefDatabase,
|
||||||
owner: DefWithBodyId,
|
owner: DefWithBodyId,
|
||||||
expr_id: ExprId,
|
expr_id: ExprId,
|
||||||
) -> UpdateGuard {
|
) -> UpdateGuard {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn append_expr_scope(
|
fn append_expr_scope<'db>(
|
||||||
db: &dyn DefDatabase,
|
db: &'db dyn DefDatabase,
|
||||||
resolver: &mut Resolver,
|
resolver: &mut Resolver<'db>,
|
||||||
owner: DefWithBodyId,
|
owner: DefWithBodyId,
|
||||||
expr_scopes: &Arc<ExprScopes>,
|
expr_scopes: &Arc<ExprScopes>,
|
||||||
scope_id: ScopeId,
|
scope_id: ScopeId,
|
||||||
@ -863,7 +863,7 @@ impl Resolver {
|
|||||||
scope_id,
|
scope_id,
|
||||||
}));
|
}));
|
||||||
if let Some(block) = expr_scopes.block(scope_id) {
|
if let Some(block) = expr_scopes.block(scope_id) {
|
||||||
let def_map = db.block_def_map(block);
|
let def_map = block_def_map(db, block);
|
||||||
let local_def_map = block.lookup(db).module.only_local_def_map(db);
|
let local_def_map = block.lookup(db).module.only_local_def_map(db);
|
||||||
resolver.scopes.push(Scope::BlockScope(ModuleItemMap {
|
resolver.scopes.push(Scope::BlockScope(ModuleItemMap {
|
||||||
def_map,
|
def_map,
|
||||||
@ -945,8 +945,8 @@ fn hygiene_info(
|
|||||||
|
|
||||||
pub struct UpdateGuard(usize);
|
pub struct UpdateGuard(usize);
|
||||||
|
|
||||||
impl Resolver {
|
impl<'db> Resolver<'db> {
|
||||||
fn scopes(&self) -> impl Iterator<Item = &Scope> {
|
fn scopes(&self) -> impl Iterator<Item = &Scope<'db>> {
|
||||||
self.scopes.iter().rev()
|
self.scopes.iter().rev()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -970,12 +970,12 @@ impl Resolver {
|
|||||||
fn item_scope_(&self) -> (&DefMap, &LocalDefMap, LocalModuleId) {
|
fn item_scope_(&self) -> (&DefMap, &LocalDefMap, LocalModuleId) {
|
||||||
self.scopes()
|
self.scopes()
|
||||||
.find_map(|scope| match scope {
|
.find_map(|scope| match scope {
|
||||||
Scope::BlockScope(m) => Some((&*m.def_map, &*m.local_def_map, m.module_id)),
|
Scope::BlockScope(m) => Some((m.def_map, m.local_def_map, m.module_id)),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.unwrap_or((
|
.unwrap_or((
|
||||||
&self.module_scope.def_map,
|
self.module_scope.def_map,
|
||||||
&self.module_scope.local_def_map,
|
self.module_scope.local_def_map,
|
||||||
self.module_scope.module_id,
|
self.module_scope.module_id,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@ -992,8 +992,8 @@ pub enum ScopeDef {
|
|||||||
Label(LabelId),
|
Label(LabelId),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Scope {
|
impl<'db> Scope<'db> {
|
||||||
fn process_names(&self, acc: &mut ScopeNames, db: &dyn DefDatabase) {
|
fn process_names(&self, acc: &mut ScopeNames, db: &'db dyn DefDatabase) {
|
||||||
match self {
|
match self {
|
||||||
Scope::BlockScope(m) => {
|
Scope::BlockScope(m) => {
|
||||||
m.def_map[m.module_id].scope.entries().for_each(|(name, def)| {
|
m.def_map[m.module_id].scope.entries().for_each(|(name, def)| {
|
||||||
@ -1047,7 +1047,11 @@ impl Scope {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resolver_for_expr(db: &dyn DefDatabase, owner: DefWithBodyId, expr_id: ExprId) -> Resolver {
|
pub fn resolver_for_expr(
|
||||||
|
db: &dyn DefDatabase,
|
||||||
|
owner: DefWithBodyId,
|
||||||
|
expr_id: ExprId,
|
||||||
|
) -> Resolver<'_> {
|
||||||
let r = owner.resolver(db);
|
let r = owner.resolver(db);
|
||||||
let scopes = db.expr_scopes(owner);
|
let scopes = db.expr_scopes(owner);
|
||||||
let scope_id = scopes.scope_for(expr_id);
|
let scope_id = scopes.scope_for(expr_id);
|
||||||
@ -1058,25 +1062,25 @@ pub fn resolver_for_scope(
|
|||||||
db: &dyn DefDatabase,
|
db: &dyn DefDatabase,
|
||||||
owner: DefWithBodyId,
|
owner: DefWithBodyId,
|
||||||
scope_id: Option<ScopeId>,
|
scope_id: Option<ScopeId>,
|
||||||
) -> Resolver {
|
) -> Resolver<'_> {
|
||||||
let r = owner.resolver(db);
|
let r = owner.resolver(db);
|
||||||
let scopes = db.expr_scopes(owner);
|
let scopes = db.expr_scopes(owner);
|
||||||
resolver_for_scope_(db, scopes, scope_id, r, owner)
|
resolver_for_scope_(db, scopes, scope_id, r, owner)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolver_for_scope_(
|
fn resolver_for_scope_<'db>(
|
||||||
db: &dyn DefDatabase,
|
db: &'db dyn DefDatabase,
|
||||||
scopes: Arc<ExprScopes>,
|
scopes: Arc<ExprScopes>,
|
||||||
scope_id: Option<ScopeId>,
|
scope_id: Option<ScopeId>,
|
||||||
mut r: Resolver,
|
mut r: Resolver<'db>,
|
||||||
owner: DefWithBodyId,
|
owner: DefWithBodyId,
|
||||||
) -> Resolver {
|
) -> Resolver<'db> {
|
||||||
let scope_chain = scopes.scope_chain(scope_id).collect::<Vec<_>>();
|
let scope_chain = scopes.scope_chain(scope_id).collect::<Vec<_>>();
|
||||||
r.scopes.reserve(scope_chain.len());
|
r.scopes.reserve(scope_chain.len());
|
||||||
|
|
||||||
for scope in scope_chain.into_iter().rev() {
|
for scope in scope_chain.into_iter().rev() {
|
||||||
if let Some(block) = scopes.block(scope) {
|
if let Some(block) = scopes.block(scope) {
|
||||||
let def_map = db.block_def_map(block);
|
let def_map = block_def_map(db, block);
|
||||||
let local_def_map = block.lookup(db).module.only_local_def_map(db);
|
let local_def_map = block.lookup(db).module.only_local_def_map(db);
|
||||||
r = r.push_block_scope(def_map, local_def_map);
|
r = r.push_block_scope(def_map, local_def_map);
|
||||||
// FIXME: This adds as many module scopes as there are blocks, but resolving in each
|
// FIXME: This adds as many module scopes as there are blocks, but resolving in each
|
||||||
@ -1092,18 +1096,26 @@ fn resolver_for_scope_(
|
|||||||
r
|
r
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Resolver {
|
impl<'db> Resolver<'db> {
|
||||||
fn push_scope(mut self, scope: Scope) -> Resolver {
|
fn push_scope(mut self, scope: Scope<'db>) -> Resolver<'db> {
|
||||||
self.scopes.push(scope);
|
self.scopes.push(scope);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
fn push_generic_params_scope(self, db: &dyn DefDatabase, def: GenericDefId) -> Resolver {
|
fn push_generic_params_scope(
|
||||||
|
self,
|
||||||
|
db: &'db dyn DefDatabase,
|
||||||
|
def: GenericDefId,
|
||||||
|
) -> Resolver<'db> {
|
||||||
let params = db.generic_params(def);
|
let params = db.generic_params(def);
|
||||||
self.push_scope(Scope::GenericParams { def, params })
|
self.push_scope(Scope::GenericParams { def, params })
|
||||||
}
|
}
|
||||||
|
|
||||||
fn push_block_scope(self, def_map: Arc<DefMap>, local_def_map: Arc<LocalDefMap>) -> Resolver {
|
fn push_block_scope(
|
||||||
|
self,
|
||||||
|
def_map: &'db DefMap,
|
||||||
|
local_def_map: &'db LocalDefMap,
|
||||||
|
) -> Resolver<'db> {
|
||||||
self.push_scope(Scope::BlockScope(ModuleItemMap {
|
self.push_scope(Scope::BlockScope(ModuleItemMap {
|
||||||
def_map,
|
def_map,
|
||||||
local_def_map,
|
local_def_map,
|
||||||
@ -1116,19 +1128,19 @@ impl Resolver {
|
|||||||
owner: DefWithBodyId,
|
owner: DefWithBodyId,
|
||||||
expr_scopes: Arc<ExprScopes>,
|
expr_scopes: Arc<ExprScopes>,
|
||||||
scope_id: ScopeId,
|
scope_id: ScopeId,
|
||||||
) -> Resolver {
|
) -> Resolver<'db> {
|
||||||
self.push_scope(Scope::ExprScope(ExprScope { owner, expr_scopes, scope_id }))
|
self.push_scope(Scope::ExprScope(ExprScope { owner, expr_scopes, scope_id }))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ModuleItemMap {
|
impl<'db> ModuleItemMap<'db> {
|
||||||
fn resolve_path_in_value_ns(
|
fn resolve_path_in_value_ns(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn DefDatabase,
|
db: &'db dyn DefDatabase,
|
||||||
path: &ModPath,
|
path: &ModPath,
|
||||||
) -> Option<(ResolveValueResult, ResolvePathResultPrefixInfo)> {
|
) -> Option<(ResolveValueResult, ResolvePathResultPrefixInfo)> {
|
||||||
let (module_def, unresolved_idx, prefix_info) = self.def_map.resolve_path_locally(
|
let (module_def, unresolved_idx, prefix_info) = self.def_map.resolve_path_locally(
|
||||||
&self.local_def_map,
|
self.local_def_map,
|
||||||
db,
|
db,
|
||||||
self.module_id,
|
self.module_id,
|
||||||
path,
|
path,
|
||||||
@ -1167,7 +1179,7 @@ impl ModuleItemMap {
|
|||||||
) -> Option<(TypeNs, Option<usize>, Option<ImportOrExternCrate>, ResolvePathResultPrefixInfo)>
|
) -> Option<(TypeNs, Option<usize>, Option<ImportOrExternCrate>, ResolvePathResultPrefixInfo)>
|
||||||
{
|
{
|
||||||
let (module_def, idx, prefix_info) = self.def_map.resolve_path_locally(
|
let (module_def, idx, prefix_info) = self.def_map.resolve_path_locally(
|
||||||
&self.local_def_map,
|
self.local_def_map,
|
||||||
db,
|
db,
|
||||||
self.module_id,
|
self.module_id,
|
||||||
path,
|
path,
|
||||||
@ -1263,11 +1275,11 @@ impl ScopeNames {
|
|||||||
|
|
||||||
pub trait HasResolver: Copy {
|
pub trait HasResolver: Copy {
|
||||||
/// Builds a resolver for type references inside this def.
|
/// Builds a resolver for type references inside this def.
|
||||||
fn resolver(self, db: &dyn DefDatabase) -> Resolver;
|
fn resolver(self, db: &dyn DefDatabase) -> Resolver<'_>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HasResolver for ModuleId {
|
impl HasResolver for ModuleId {
|
||||||
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
|
fn resolver(self, db: &dyn DefDatabase) -> Resolver<'_> {
|
||||||
let (mut def_map, local_def_map) = self.local_def_map(db);
|
let (mut def_map, local_def_map) = self.local_def_map(db);
|
||||||
let mut module_id = self.local_id;
|
let mut module_id = self.local_id;
|
||||||
|
|
||||||
@ -1289,21 +1301,17 @@ impl HasResolver for ModuleId {
|
|||||||
}
|
}
|
||||||
let mut resolver = Resolver {
|
let mut resolver = Resolver {
|
||||||
scopes: Vec::with_capacity(modules.len()),
|
scopes: Vec::with_capacity(modules.len()),
|
||||||
module_scope: ModuleItemMap {
|
module_scope: ModuleItemMap { def_map, local_def_map, module_id },
|
||||||
def_map,
|
|
||||||
local_def_map: local_def_map.clone(),
|
|
||||||
module_id,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
for def_map in modules.into_iter().rev() {
|
for def_map in modules.into_iter().rev() {
|
||||||
resolver = resolver.push_block_scope(def_map, local_def_map.clone());
|
resolver = resolver.push_block_scope(def_map, local_def_map);
|
||||||
}
|
}
|
||||||
resolver
|
resolver
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HasResolver for CrateRootModuleId {
|
impl HasResolver for CrateRootModuleId {
|
||||||
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
|
fn resolver(self, db: &dyn DefDatabase) -> Resolver<'_> {
|
||||||
let (def_map, local_def_map) = self.local_def_map(db);
|
let (def_map, local_def_map) = self.local_def_map(db);
|
||||||
Resolver {
|
Resolver {
|
||||||
scopes: vec![],
|
scopes: vec![],
|
||||||
@ -1313,75 +1321,75 @@ impl HasResolver for CrateRootModuleId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl HasResolver for TraitId {
|
impl HasResolver for TraitId {
|
||||||
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
|
fn resolver(self, db: &dyn DefDatabase) -> Resolver<'_> {
|
||||||
lookup_resolver(db, self).push_generic_params_scope(db, self.into())
|
lookup_resolver(db, self).push_generic_params_scope(db, self.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HasResolver for TraitAliasId {
|
impl HasResolver for TraitAliasId {
|
||||||
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
|
fn resolver(self, db: &dyn DefDatabase) -> Resolver<'_> {
|
||||||
lookup_resolver(db, self).push_generic_params_scope(db, self.into())
|
lookup_resolver(db, self).push_generic_params_scope(db, self.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Into<AdtId> + Copy> HasResolver for T {
|
impl<T: Into<AdtId> + Copy> HasResolver for T {
|
||||||
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
|
fn resolver(self, db: &dyn DefDatabase) -> Resolver<'_> {
|
||||||
let def = self.into();
|
let def = self.into();
|
||||||
def.module(db).resolver(db).push_generic_params_scope(db, def.into())
|
def.module(db).resolver(db).push_generic_params_scope(db, def.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HasResolver for FunctionId {
|
impl HasResolver for FunctionId {
|
||||||
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
|
fn resolver(self, db: &dyn DefDatabase) -> Resolver<'_> {
|
||||||
lookup_resolver(db, self).push_generic_params_scope(db, self.into())
|
lookup_resolver(db, self).push_generic_params_scope(db, self.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HasResolver for ConstId {
|
impl HasResolver for ConstId {
|
||||||
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
|
fn resolver(self, db: &dyn DefDatabase) -> Resolver<'_> {
|
||||||
lookup_resolver(db, self)
|
lookup_resolver(db, self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HasResolver for StaticId {
|
impl HasResolver for StaticId {
|
||||||
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
|
fn resolver(self, db: &dyn DefDatabase) -> Resolver<'_> {
|
||||||
lookup_resolver(db, self)
|
lookup_resolver(db, self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HasResolver for TypeAliasId {
|
impl HasResolver for TypeAliasId {
|
||||||
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
|
fn resolver(self, db: &dyn DefDatabase) -> Resolver<'_> {
|
||||||
lookup_resolver(db, self).push_generic_params_scope(db, self.into())
|
lookup_resolver(db, self).push_generic_params_scope(db, self.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HasResolver for ImplId {
|
impl HasResolver for ImplId {
|
||||||
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
|
fn resolver(self, db: &dyn DefDatabase) -> Resolver<'_> {
|
||||||
self.lookup(db).container.resolver(db).push_generic_params_scope(db, self.into())
|
self.lookup(db).container.resolver(db).push_generic_params_scope(db, self.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HasResolver for ExternBlockId {
|
impl HasResolver for ExternBlockId {
|
||||||
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
|
fn resolver(self, db: &dyn DefDatabase) -> Resolver<'_> {
|
||||||
// Same as parent's
|
// Same as parent's
|
||||||
lookup_resolver(db, self)
|
lookup_resolver(db, self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HasResolver for ExternCrateId {
|
impl HasResolver for ExternCrateId {
|
||||||
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
|
fn resolver(self, db: &dyn DefDatabase) -> Resolver<'_> {
|
||||||
lookup_resolver(db, self)
|
lookup_resolver(db, self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HasResolver for UseId {
|
impl HasResolver for UseId {
|
||||||
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
|
fn resolver(self, db: &dyn DefDatabase) -> Resolver<'_> {
|
||||||
lookup_resolver(db, self)
|
lookup_resolver(db, self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HasResolver for DefWithBodyId {
|
impl HasResolver for DefWithBodyId {
|
||||||
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
|
fn resolver(self, db: &dyn DefDatabase) -> Resolver<'_> {
|
||||||
match self {
|
match self {
|
||||||
DefWithBodyId::ConstId(c) => c.resolver(db),
|
DefWithBodyId::ConstId(c) => c.resolver(db),
|
||||||
DefWithBodyId::FunctionId(f) => f.resolver(db),
|
DefWithBodyId::FunctionId(f) => f.resolver(db),
|
||||||
@ -1392,7 +1400,7 @@ impl HasResolver for DefWithBodyId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl HasResolver for ItemContainerId {
|
impl HasResolver for ItemContainerId {
|
||||||
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
|
fn resolver(self, db: &dyn DefDatabase) -> Resolver<'_> {
|
||||||
match self {
|
match self {
|
||||||
ItemContainerId::ModuleId(it) => it.resolver(db),
|
ItemContainerId::ModuleId(it) => it.resolver(db),
|
||||||
ItemContainerId::TraitId(it) => it.resolver(db),
|
ItemContainerId::TraitId(it) => it.resolver(db),
|
||||||
@ -1403,7 +1411,7 @@ impl HasResolver for ItemContainerId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl HasResolver for GenericDefId {
|
impl HasResolver for GenericDefId {
|
||||||
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
|
fn resolver(self, db: &dyn DefDatabase) -> Resolver<'_> {
|
||||||
match self {
|
match self {
|
||||||
GenericDefId::FunctionId(inner) => inner.resolver(db),
|
GenericDefId::FunctionId(inner) => inner.resolver(db),
|
||||||
GenericDefId::AdtId(adt) => adt.resolver(db),
|
GenericDefId::AdtId(adt) => adt.resolver(db),
|
||||||
@ -1418,13 +1426,13 @@ impl HasResolver for GenericDefId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl HasResolver for EnumVariantId {
|
impl HasResolver for EnumVariantId {
|
||||||
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
|
fn resolver(self, db: &dyn DefDatabase) -> Resolver<'_> {
|
||||||
self.lookup(db).parent.resolver(db)
|
self.lookup(db).parent.resolver(db)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HasResolver for VariantId {
|
impl HasResolver for VariantId {
|
||||||
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
|
fn resolver(self, db: &dyn DefDatabase) -> Resolver<'_> {
|
||||||
match self {
|
match self {
|
||||||
VariantId::EnumVariantId(it) => it.resolver(db),
|
VariantId::EnumVariantId(it) => it.resolver(db),
|
||||||
VariantId::StructId(it) => it.resolver(db),
|
VariantId::StructId(it) => it.resolver(db),
|
||||||
@ -1434,7 +1442,7 @@ impl HasResolver for VariantId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl HasResolver for MacroId {
|
impl HasResolver for MacroId {
|
||||||
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
|
fn resolver(self, db: &dyn DefDatabase) -> Resolver<'_> {
|
||||||
match self {
|
match self {
|
||||||
MacroId::Macro2Id(it) => it.resolver(db),
|
MacroId::Macro2Id(it) => it.resolver(db),
|
||||||
MacroId::MacroRulesId(it) => it.resolver(db),
|
MacroId::MacroRulesId(it) => it.resolver(db),
|
||||||
@ -1444,29 +1452,29 @@ impl HasResolver for MacroId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl HasResolver for Macro2Id {
|
impl HasResolver for Macro2Id {
|
||||||
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
|
fn resolver(self, db: &dyn DefDatabase) -> Resolver<'_> {
|
||||||
lookup_resolver(db, self)
|
lookup_resolver(db, self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HasResolver for ProcMacroId {
|
impl HasResolver for ProcMacroId {
|
||||||
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
|
fn resolver(self, db: &dyn DefDatabase) -> Resolver<'_> {
|
||||||
lookup_resolver(db, self)
|
lookup_resolver(db, self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HasResolver for MacroRulesId {
|
impl HasResolver for MacroRulesId {
|
||||||
fn resolver(self, db: &dyn DefDatabase) -> Resolver {
|
fn resolver(self, db: &dyn DefDatabase) -> Resolver<'_> {
|
||||||
lookup_resolver(db, self)
|
lookup_resolver(db, self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lookup_resolver<'db>(
|
fn lookup_resolver(
|
||||||
db: &(dyn DefDatabase + 'db),
|
db: &dyn DefDatabase,
|
||||||
lookup: impl Lookup<
|
lookup: impl Lookup<
|
||||||
Database = dyn DefDatabase,
|
Database = dyn DefDatabase,
|
||||||
Data = impl ItemTreeLoc<Container = impl HasResolver>,
|
Data = impl ItemTreeLoc<Container = impl HasResolver>,
|
||||||
>,
|
>,
|
||||||
) -> Resolver {
|
) -> Resolver<'_> {
|
||||||
lookup.lookup(db).container().resolver(db)
|
lookup.lookup(db).container().resolver(db)
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ use triomphe::Arc;
|
|||||||
use crate::{
|
use crate::{
|
||||||
LocalModuleId, Lookup, ModuleDefId, ModuleId,
|
LocalModuleId, Lookup, ModuleDefId, ModuleId,
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
nameres::{DefMap, ModuleSource},
|
nameres::{DefMap, ModuleSource, block_def_map, crate_def_map},
|
||||||
src::HasSource,
|
src::HasSource,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ impl TestDB {
|
|||||||
|
|
||||||
pub(crate) fn module_for_file(&self, file_id: FileId) -> ModuleId {
|
pub(crate) fn module_for_file(&self, file_id: FileId) -> ModuleId {
|
||||||
for &krate in self.relevant_crates(file_id).iter() {
|
for &krate in self.relevant_crates(file_id).iter() {
|
||||||
let crate_def_map = self.crate_def_map(krate);
|
let crate_def_map = crate_def_map(self, krate);
|
||||||
for (local_id, data) in crate_def_map.modules() {
|
for (local_id, data) in crate_def_map.modules() {
|
||||||
if data.origin.file_id().map(|file_id| file_id.file_id(self)) == Some(file_id) {
|
if data.origin.file_id().map(|file_id| file_id.file_id(self)) == Some(file_id) {
|
||||||
return crate_def_map.module_id(local_id);
|
return crate_def_map.module_id(local_id);
|
||||||
@ -146,16 +146,16 @@ impl TestDB {
|
|||||||
pub(crate) fn module_at_position(&self, position: FilePosition) -> ModuleId {
|
pub(crate) fn module_at_position(&self, position: FilePosition) -> ModuleId {
|
||||||
let file_module = self.module_for_file(position.file_id.file_id(self));
|
let file_module = self.module_for_file(position.file_id.file_id(self));
|
||||||
let mut def_map = file_module.def_map(self);
|
let mut def_map = file_module.def_map(self);
|
||||||
let module = self.mod_at_position(&def_map, position);
|
let module = self.mod_at_position(def_map, position);
|
||||||
|
|
||||||
def_map = match self.block_at_position(&def_map, position) {
|
def_map = match self.block_at_position(def_map, position) {
|
||||||
Some(it) => it,
|
Some(it) => it,
|
||||||
None => return def_map.module_id(module),
|
None => return def_map.module_id(module),
|
||||||
};
|
};
|
||||||
loop {
|
loop {
|
||||||
let new_map = self.block_at_position(&def_map, position);
|
let new_map = self.block_at_position(def_map, position);
|
||||||
match new_map {
|
match new_map {
|
||||||
Some(new_block) if !Arc::ptr_eq(&new_block, &def_map) => {
|
Some(new_block) if !std::ptr::eq(&new_block, &def_map) => {
|
||||||
def_map = new_block;
|
def_map = new_block;
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
@ -206,7 +206,7 @@ impl TestDB {
|
|||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
fn block_at_position(&self, def_map: &DefMap, position: FilePosition) -> Option<Arc<DefMap>> {
|
fn block_at_position(&self, def_map: &DefMap, position: FilePosition) -> Option<&DefMap> {
|
||||||
// Find the smallest (innermost) function in `def_map` containing the cursor.
|
// Find the smallest (innermost) function in `def_map` containing the cursor.
|
||||||
let mut size = None;
|
let mut size = None;
|
||||||
let mut fn_def = None;
|
let mut fn_def = None;
|
||||||
@ -263,7 +263,7 @@ impl TestDB {
|
|||||||
let mut containing_blocks =
|
let mut containing_blocks =
|
||||||
scopes.scope_chain(Some(scope)).filter_map(|scope| scopes.block(scope));
|
scopes.scope_chain(Some(scope)).filter_map(|scope| scopes.block(scope));
|
||||||
|
|
||||||
if let Some(block) = containing_blocks.next().map(|block| self.block_def_map(block)) {
|
if let Some(block) = containing_blocks.next().map(|block| block_def_map(self, block)) {
|
||||||
return Some(block);
|
return Some(block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ pub enum Visibility {
|
|||||||
impl Visibility {
|
impl Visibility {
|
||||||
pub fn resolve(
|
pub fn resolve(
|
||||||
db: &dyn DefDatabase,
|
db: &dyn DefDatabase,
|
||||||
resolver: &crate::resolver::Resolver,
|
resolver: &crate::resolver::Resolver<'_>,
|
||||||
raw_vis: &RawVisibility,
|
raw_vis: &RawVisibility,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
// we fall back to public visibility (i.e. fail open) if the path can't be resolved
|
// we fall back to public visibility (i.e. fail open) if the path can't be resolved
|
||||||
@ -50,7 +50,7 @@ impl Visibility {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let def_map = from_module.def_map(db);
|
let def_map = from_module.def_map(db);
|
||||||
Self::is_visible_from_def_map_(db, &def_map, to_module, from_module.local_id)
|
Self::is_visible_from_def_map_(db, def_map, to_module, from_module.local_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn is_visible_from_def_map(
|
pub(crate) fn is_visible_from_def_map(
|
||||||
@ -116,7 +116,7 @@ impl Visibility {
|
|||||||
match def_map.parent() {
|
match def_map.parent() {
|
||||||
Some(module) => {
|
Some(module) => {
|
||||||
parent_arc = module.def_map(db);
|
parent_arc = module.def_map(db);
|
||||||
def_map = &*parent_arc;
|
def_map = parent_arc;
|
||||||
from_module = module.local_id;
|
from_module = module.local_id;
|
||||||
}
|
}
|
||||||
// Reached the root module, nothing left to check.
|
// Reached the root module, nothing left to check.
|
||||||
@ -257,7 +257,7 @@ pub(crate) fn type_alias_visibility_query(db: &dyn DefDatabase, def: TypeAliasId
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn trait_vis(db: &dyn DefDatabase, resolver: &Resolver, trait_id: TraitId) -> Visibility {
|
fn trait_vis(db: &dyn DefDatabase, resolver: &Resolver<'_>, trait_id: TraitId) -> Visibility {
|
||||||
let ItemLoc { id: tree_id, .. } = trait_id.lookup(db);
|
let ItemLoc { id: tree_id, .. } = trait_id.lookup(db);
|
||||||
let item_tree = tree_id.item_tree(db);
|
let item_tree = tree_id.item_tree(db);
|
||||||
let tr_def = &item_tree[tree_id.value];
|
let tr_def = &item_tree[tree_id.value];
|
||||||
|
@ -91,7 +91,7 @@ impl From<MirEvalError> for ConstEvalError {
|
|||||||
|
|
||||||
pub(crate) fn path_to_const<'g>(
|
pub(crate) fn path_to_const<'g>(
|
||||||
db: &dyn HirDatabase,
|
db: &dyn HirDatabase,
|
||||||
resolver: &Resolver,
|
resolver: &Resolver<'_>,
|
||||||
path: &Path,
|
path: &Path,
|
||||||
mode: ParamLoweringMode,
|
mode: ParamLoweringMode,
|
||||||
args: impl FnOnce() -> &'g Generics,
|
args: impl FnOnce() -> &'g Generics,
|
||||||
|
@ -480,7 +480,7 @@ struct FilterMapNextChecker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl FilterMapNextChecker {
|
impl FilterMapNextChecker {
|
||||||
fn new(resolver: &hir_def::resolver::Resolver, db: &dyn HirDatabase) -> Self {
|
fn new(resolver: &hir_def::resolver::Resolver<'_>, db: &dyn HirDatabase) -> Self {
|
||||||
// Find and store the FunctionIds for Iterator::filter_map and Iterator::next
|
// Find and store the FunctionIds for Iterator::filter_map and Iterator::next
|
||||||
let (next_function_id, filter_map_function_id) = match LangItem::IteratorNext
|
let (next_function_id, filter_map_function_id) = match LangItem::IteratorNext
|
||||||
.resolve_function(db, resolver.krate())
|
.resolve_function(db, resolver.krate())
|
||||||
|
@ -73,7 +73,7 @@ pub(crate) struct MatchCheckCtx<'db> {
|
|||||||
|
|
||||||
impl<'db> MatchCheckCtx<'db> {
|
impl<'db> MatchCheckCtx<'db> {
|
||||||
pub(crate) fn new(module: ModuleId, body: DefWithBodyId, db: &'db dyn HirDatabase) -> Self {
|
pub(crate) fn new(module: ModuleId, body: DefWithBodyId, db: &'db dyn HirDatabase) -> Self {
|
||||||
let def_map = db.crate_def_map(module.krate());
|
let def_map = module.crate_def_map(db);
|
||||||
let exhaustive_patterns = def_map.is_unstable_feature_enabled(&sym::exhaustive_patterns);
|
let exhaustive_patterns = def_map.is_unstable_feature_enabled(&sym::exhaustive_patterns);
|
||||||
Self { module, body, db, exhaustive_patterns }
|
Self { module, body, db, exhaustive_patterns }
|
||||||
}
|
}
|
||||||
|
@ -131,28 +131,28 @@ pub fn unsafe_operations(
|
|||||||
visitor.walk_expr(current);
|
visitor.walk_expr(current);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct UnsafeVisitor<'a> {
|
struct UnsafeVisitor<'db> {
|
||||||
db: &'a dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
infer: &'a InferenceResult,
|
infer: &'db InferenceResult,
|
||||||
body: &'a Body,
|
body: &'db Body,
|
||||||
resolver: Resolver,
|
resolver: Resolver<'db>,
|
||||||
def: DefWithBodyId,
|
def: DefWithBodyId,
|
||||||
inside_unsafe_block: InsideUnsafeBlock,
|
inside_unsafe_block: InsideUnsafeBlock,
|
||||||
inside_assignment: bool,
|
inside_assignment: bool,
|
||||||
inside_union_destructure: bool,
|
inside_union_destructure: bool,
|
||||||
callback: &'a mut dyn FnMut(UnsafeDiagnostic),
|
callback: &'db mut dyn FnMut(UnsafeDiagnostic),
|
||||||
def_target_features: TargetFeatures,
|
def_target_features: TargetFeatures,
|
||||||
// FIXME: This needs to be the edition of the span of each call.
|
// FIXME: This needs to be the edition of the span of each call.
|
||||||
edition: Edition,
|
edition: Edition,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> UnsafeVisitor<'a> {
|
impl<'db> UnsafeVisitor<'db> {
|
||||||
fn new(
|
fn new(
|
||||||
db: &'a dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
infer: &'a InferenceResult,
|
infer: &'db InferenceResult,
|
||||||
body: &'a Body,
|
body: &'db Body,
|
||||||
def: DefWithBodyId,
|
def: DefWithBodyId,
|
||||||
unsafe_expr_cb: &'a mut dyn FnMut(UnsafeDiagnostic),
|
unsafe_expr_cb: &'db mut dyn FnMut(UnsafeDiagnostic),
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let resolver = def.resolver(db);
|
let resolver = def.resolver(db);
|
||||||
let def_target_features = match def {
|
let def_target_features = match def {
|
||||||
|
@ -9,8 +9,8 @@ use chalk_ir::{
|
|||||||
};
|
};
|
||||||
use chalk_solve::rust_ir::InlineBound;
|
use chalk_solve::rust_ir::InlineBound;
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
AssocItemId, ConstId, FunctionId, GenericDefId, HasModule, TraitId, TypeAliasId,
|
AssocItemId, ConstId, CrateRootModuleId, FunctionId, GenericDefId, HasModule, TraitId,
|
||||||
lang_item::LangItem, signatures::TraitFlags,
|
TypeAliasId, lang_item::LangItem, signatures::TraitFlags,
|
||||||
};
|
};
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
@ -343,7 +343,7 @@ where
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
AssocItemId::TypeAliasId(it) => {
|
AssocItemId::TypeAliasId(it) => {
|
||||||
let def_map = db.crate_def_map(trait_.krate(db));
|
let def_map = CrateRootModuleId::from(trait_.krate(db)).def_map(db);
|
||||||
if def_map.is_unstable_feature_enabled(&intern::sym::generic_associated_type_extended) {
|
if def_map.is_unstable_feature_enabled(&intern::sym::generic_associated_type_extended) {
|
||||||
ControlFlow::Continue(())
|
ControlFlow::Continue(())
|
||||||
} else {
|
} else {
|
||||||
|
@ -594,16 +594,16 @@ impl Index<BindingId> for InferenceResult {
|
|||||||
|
|
||||||
/// The inference context contains all information needed during type inference.
|
/// The inference context contains all information needed during type inference.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub(crate) struct InferenceContext<'a> {
|
pub(crate) struct InferenceContext<'db> {
|
||||||
pub(crate) db: &'a dyn HirDatabase,
|
pub(crate) db: &'db dyn HirDatabase,
|
||||||
pub(crate) owner: DefWithBodyId,
|
pub(crate) owner: DefWithBodyId,
|
||||||
pub(crate) body: &'a Body,
|
pub(crate) body: &'db Body,
|
||||||
/// Generally you should not resolve things via this resolver. Instead create a TyLoweringContext
|
/// Generally you should not resolve things via this resolver. Instead create a TyLoweringContext
|
||||||
/// and resolve the path via its methods. This will ensure proper error reporting.
|
/// and resolve the path via its methods. This will ensure proper error reporting.
|
||||||
pub(crate) resolver: Resolver,
|
pub(crate) resolver: Resolver<'db>,
|
||||||
generic_def: GenericDefId,
|
generic_def: GenericDefId,
|
||||||
generics: OnceCell<Generics>,
|
generics: OnceCell<Generics>,
|
||||||
table: unify::InferenceTable<'a>,
|
table: unify::InferenceTable<'db>,
|
||||||
/// The traits in scope, disregarding block modules. This is used for caching purposes.
|
/// The traits in scope, disregarding block modules. This is used for caching purposes.
|
||||||
traits_in_scope: FxHashSet<TraitId>,
|
traits_in_scope: FxHashSet<TraitId>,
|
||||||
pub(crate) result: InferenceResult,
|
pub(crate) result: InferenceResult,
|
||||||
@ -695,12 +695,12 @@ enum ImplTraitReplacingMode {
|
|||||||
TypeAlias,
|
TypeAlias,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> InferenceContext<'a> {
|
impl<'db> InferenceContext<'db> {
|
||||||
fn new(
|
fn new(
|
||||||
db: &'a dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
owner: DefWithBodyId,
|
owner: DefWithBodyId,
|
||||||
body: &'a Body,
|
body: &'db Body,
|
||||||
resolver: Resolver,
|
resolver: Resolver<'db>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let trait_env = db.trait_environment_for_body(owner);
|
let trait_env = db.trait_environment_for_body(owner);
|
||||||
InferenceContext {
|
InferenceContext {
|
||||||
|
@ -61,7 +61,7 @@ impl<'a> InferenceTyLoweringContext<'a> {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub(super) fn new(
|
pub(super) fn new(
|
||||||
db: &'a dyn HirDatabase,
|
db: &'a dyn HirDatabase,
|
||||||
resolver: &'a Resolver,
|
resolver: &'a Resolver<'_>,
|
||||||
store: &'a ExpressionStore,
|
store: &'a ExpressionStore,
|
||||||
diagnostics: &'a Diagnostics,
|
diagnostics: &'a Diagnostics,
|
||||||
source: InferenceTyDiagnosticSource,
|
source: InferenceTyDiagnosticSource,
|
||||||
|
@ -42,7 +42,6 @@ use hir_def::{
|
|||||||
use hir_expand::name::Name;
|
use hir_expand::name::Name;
|
||||||
use la_arena::{Arena, ArenaMap};
|
use la_arena::{Arena, ArenaMap};
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
use rustc_pattern_analysis::Captures;
|
|
||||||
use stdx::{impl_from, never};
|
use stdx::{impl_from, never};
|
||||||
use triomphe::{Arc, ThinArc};
|
use triomphe::{Arc, ThinArc};
|
||||||
|
|
||||||
@ -151,10 +150,10 @@ impl LifetimeElisionKind {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct TyLoweringContext<'a> {
|
pub struct TyLoweringContext<'db> {
|
||||||
pub db: &'a dyn HirDatabase,
|
pub db: &'db dyn HirDatabase,
|
||||||
resolver: &'a Resolver,
|
resolver: &'db Resolver<'db>,
|
||||||
store: &'a ExpressionStore,
|
store: &'db ExpressionStore,
|
||||||
def: GenericDefId,
|
def: GenericDefId,
|
||||||
generics: OnceCell<Generics>,
|
generics: OnceCell<Generics>,
|
||||||
in_binders: DebruijnIndex,
|
in_binders: DebruijnIndex,
|
||||||
@ -170,11 +169,11 @@ pub struct TyLoweringContext<'a> {
|
|||||||
lifetime_elision: LifetimeElisionKind,
|
lifetime_elision: LifetimeElisionKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> TyLoweringContext<'a> {
|
impl<'db> TyLoweringContext<'db> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
db: &'a dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
resolver: &'a Resolver,
|
resolver: &'db Resolver<'db>,
|
||||||
store: &'a ExpressionStore,
|
store: &'db ExpressionStore,
|
||||||
def: GenericDefId,
|
def: GenericDefId,
|
||||||
lifetime_elision: LifetimeElisionKind,
|
lifetime_elision: LifetimeElisionKind,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
@ -1176,13 +1175,13 @@ where
|
|||||||
|
|
||||||
/// Generate implicit `: Sized` predicates for all generics that has no `?Sized` bound.
|
/// Generate implicit `: Sized` predicates for all generics that has no `?Sized` bound.
|
||||||
/// Exception is Self of a trait def.
|
/// Exception is Self of a trait def.
|
||||||
fn implicitly_sized_clauses<'a, 'subst: 'a>(
|
fn implicitly_sized_clauses<'db, 'a, 'subst: 'a>(
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
def: GenericDefId,
|
def: GenericDefId,
|
||||||
explicitly_unsized_tys: &'a FxHashSet<Ty>,
|
explicitly_unsized_tys: &'a FxHashSet<Ty>,
|
||||||
substitution: &'subst Substitution,
|
substitution: &'subst Substitution,
|
||||||
resolver: &Resolver,
|
resolver: &Resolver<'db>,
|
||||||
) -> Option<impl Iterator<Item = WhereClause> + Captures<'a> + Captures<'subst>> {
|
) -> Option<impl Iterator<Item = WhereClause>> {
|
||||||
let sized_trait = LangItem::Sized.resolve_trait(db, resolver.krate()).map(to_chalk_trait_id)?;
|
let sized_trait = LangItem::Sized.resolve_trait(db, resolver.krate()).map(to_chalk_trait_id)?;
|
||||||
|
|
||||||
let trait_self_idx = trait_self_param_idx(db, def);
|
let trait_self_idx = trait_self_param_idx(db, def);
|
||||||
|
@ -10,7 +10,7 @@ use chalk_ir::{UniverseIndex, WithKind, cast::Cast};
|
|||||||
use hir_def::{
|
use hir_def::{
|
||||||
AssocItemId, BlockId, ConstId, FunctionId, HasModule, ImplId, ItemContainerId, Lookup,
|
AssocItemId, BlockId, ConstId, FunctionId, HasModule, ImplId, ItemContainerId, Lookup,
|
||||||
ModuleId, TraitId,
|
ModuleId, TraitId,
|
||||||
nameres::{DefMap, assoc::ImplItems},
|
nameres::{DefMap, assoc::ImplItems, block_def_map, crate_def_map},
|
||||||
signatures::{ConstFlags, EnumFlags, FnFlags, StructFlags, TraitFlags, TypeAliasFlags},
|
signatures::{ConstFlags, EnumFlags, FnFlags, StructFlags, TraitFlags, TypeAliasFlags},
|
||||||
};
|
};
|
||||||
use hir_expand::name::Name;
|
use hir_expand::name::Name;
|
||||||
@ -152,7 +152,7 @@ impl TraitImpls {
|
|||||||
let _p = tracing::info_span!("trait_impls_in_crate_query", ?krate).entered();
|
let _p = tracing::info_span!("trait_impls_in_crate_query", ?krate).entered();
|
||||||
let mut impls = FxHashMap::default();
|
let mut impls = FxHashMap::default();
|
||||||
|
|
||||||
Self::collect_def_map(db, &mut impls, &db.crate_def_map(krate));
|
Self::collect_def_map(db, &mut impls, crate_def_map(db, krate));
|
||||||
|
|
||||||
Arc::new(Self::finish(impls))
|
Arc::new(Self::finish(impls))
|
||||||
}
|
}
|
||||||
@ -164,7 +164,7 @@ impl TraitImpls {
|
|||||||
let _p = tracing::info_span!("trait_impls_in_block_query").entered();
|
let _p = tracing::info_span!("trait_impls_in_block_query").entered();
|
||||||
let mut impls = FxHashMap::default();
|
let mut impls = FxHashMap::default();
|
||||||
|
|
||||||
Self::collect_def_map(db, &mut impls, &db.block_def_map(block));
|
Self::collect_def_map(db, &mut impls, block_def_map(db, block));
|
||||||
|
|
||||||
if impls.is_empty() { None } else { Some(Arc::new(Self::finish(impls))) }
|
if impls.is_empty() { None } else { Some(Arc::new(Self::finish(impls))) }
|
||||||
}
|
}
|
||||||
@ -214,7 +214,7 @@ impl TraitImpls {
|
|||||||
for konst in module_data.scope.unnamed_consts() {
|
for konst in module_data.scope.unnamed_consts() {
|
||||||
let body = db.body(konst.into());
|
let body = db.body(konst.into());
|
||||||
for (_, block_def_map) in body.blocks(db) {
|
for (_, block_def_map) in body.blocks(db) {
|
||||||
Self::collect_def_map(db, map, &block_def_map);
|
Self::collect_def_map(db, map, block_def_map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -280,8 +280,8 @@ impl InherentImpls {
|
|||||||
let _p = tracing::info_span!("inherent_impls_in_crate_query", ?krate).entered();
|
let _p = tracing::info_span!("inherent_impls_in_crate_query", ?krate).entered();
|
||||||
let mut impls = Self { map: FxHashMap::default(), invalid_impls: Vec::default() };
|
let mut impls = Self { map: FxHashMap::default(), invalid_impls: Vec::default() };
|
||||||
|
|
||||||
let crate_def_map = db.crate_def_map(krate);
|
let crate_def_map = crate_def_map(db, krate);
|
||||||
impls.collect_def_map(db, &crate_def_map);
|
impls.collect_def_map(db, crate_def_map);
|
||||||
impls.shrink_to_fit();
|
impls.shrink_to_fit();
|
||||||
|
|
||||||
Arc::new(impls)
|
Arc::new(impls)
|
||||||
@ -294,8 +294,8 @@ impl InherentImpls {
|
|||||||
let _p = tracing::info_span!("inherent_impls_in_block_query").entered();
|
let _p = tracing::info_span!("inherent_impls_in_block_query").entered();
|
||||||
let mut impls = Self { map: FxHashMap::default(), invalid_impls: Vec::default() };
|
let mut impls = Self { map: FxHashMap::default(), invalid_impls: Vec::default() };
|
||||||
|
|
||||||
let block_def_map = db.block_def_map(block);
|
let block_def_map = block_def_map(db, block);
|
||||||
impls.collect_def_map(db, &block_def_map);
|
impls.collect_def_map(db, block_def_map);
|
||||||
impls.shrink_to_fit();
|
impls.shrink_to_fit();
|
||||||
|
|
||||||
if impls.map.is_empty() && impls.invalid_impls.is_empty() {
|
if impls.map.is_empty() && impls.invalid_impls.is_empty() {
|
||||||
@ -337,7 +337,7 @@ impl InherentImpls {
|
|||||||
for konst in module_data.scope.unnamed_consts() {
|
for konst in module_data.scope.unnamed_consts() {
|
||||||
let body = db.body(konst.into());
|
let body = db.body(konst.into());
|
||||||
for (_, block_def_map) in body.blocks(db) {
|
for (_, block_def_map) in body.blocks(db) {
|
||||||
self.collect_def_map(db, &block_def_map);
|
self.collect_def_map(db, block_def_map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1399,7 +1399,7 @@ fn iterate_inherent_methods(
|
|||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
block = db.block_def_map(block_id).parent().and_then(|module| module.containing_block());
|
block = block_def_map(db, block_id).parent().and_then(|module| module.containing_block());
|
||||||
}
|
}
|
||||||
|
|
||||||
for krate in def_crates {
|
for krate in def_crates {
|
||||||
|
@ -5,6 +5,7 @@ use std::cmp::{self, Ordering};
|
|||||||
|
|
||||||
use chalk_ir::TyKind;
|
use chalk_ir::TyKind;
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
|
CrateRootModuleId,
|
||||||
builtin_type::{BuiltinInt, BuiltinUint},
|
builtin_type::{BuiltinInt, BuiltinUint},
|
||||||
resolver::HasResolver,
|
resolver::HasResolver,
|
||||||
};
|
};
|
||||||
@ -153,7 +154,7 @@ impl Evaluator<'_> {
|
|||||||
) -> Result<Option<FunctionId>> {
|
) -> Result<Option<FunctionId>> {
|
||||||
// `PanicFmt` is redirected to `ConstPanicFmt`
|
// `PanicFmt` is redirected to `ConstPanicFmt`
|
||||||
if let Some(LangItem::PanicFmt) = self.db.lang_attr(def.into()) {
|
if let Some(LangItem::PanicFmt) = self.db.lang_attr(def.into()) {
|
||||||
let resolver = self.db.crate_def_map(self.crate_id).crate_root().resolver(self.db);
|
let resolver = CrateRootModuleId::from(self.crate_id).resolver(self.db);
|
||||||
|
|
||||||
let Some(const_panic_fmt) =
|
let Some(const_panic_fmt) =
|
||||||
LangItem::ConstPanicFmt.resolve_function(self.db, resolver.krate())
|
LangItem::ConstPanicFmt.resolve_function(self.db, resolver.krate())
|
||||||
|
@ -68,16 +68,16 @@ struct DropScope {
|
|||||||
locals: Vec<LocalId>,
|
locals: Vec<LocalId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MirLowerCtx<'a> {
|
struct MirLowerCtx<'db> {
|
||||||
result: MirBody,
|
result: MirBody,
|
||||||
owner: DefWithBodyId,
|
owner: DefWithBodyId,
|
||||||
current_loop_blocks: Option<LoopBlocks>,
|
current_loop_blocks: Option<LoopBlocks>,
|
||||||
labeled_loop_blocks: FxHashMap<LabelId, LoopBlocks>,
|
labeled_loop_blocks: FxHashMap<LabelId, LoopBlocks>,
|
||||||
discr_temp: Option<Place>,
|
discr_temp: Option<Place>,
|
||||||
db: &'a dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
body: &'a Body,
|
body: &'db Body,
|
||||||
infer: &'a InferenceResult,
|
infer: &'db InferenceResult,
|
||||||
resolver: Resolver,
|
resolver: Resolver<'db>,
|
||||||
drop_scopes: Vec<DropScope>,
|
drop_scopes: Vec<DropScope>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ use base_db::{
|
|||||||
SourceRoot, SourceRootId, SourceRootInput,
|
SourceRoot, SourceRootId, SourceRootInput,
|
||||||
};
|
};
|
||||||
|
|
||||||
use hir_def::{ModuleId, db::DefDatabase};
|
use hir_def::{ModuleId, db::DefDatabase, nameres::crate_def_map};
|
||||||
use hir_expand::EditionedFileId;
|
use hir_expand::EditionedFileId;
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use salsa::{AsDynDatabase, Durability};
|
use salsa::{AsDynDatabase, Durability};
|
||||||
@ -118,7 +118,7 @@ impl TestDB {
|
|||||||
pub(crate) fn module_for_file_opt(&self, file_id: impl Into<FileId>) -> Option<ModuleId> {
|
pub(crate) fn module_for_file_opt(&self, file_id: impl Into<FileId>) -> Option<ModuleId> {
|
||||||
let file_id = file_id.into();
|
let file_id = file_id.into();
|
||||||
for &krate in self.relevant_crates(file_id).iter() {
|
for &krate in self.relevant_crates(file_id).iter() {
|
||||||
let crate_def_map = self.crate_def_map(krate);
|
let crate_def_map = crate_def_map(self, krate);
|
||||||
for (local_id, data) in crate_def_map.modules() {
|
for (local_id, data) in crate_def_map.modules() {
|
||||||
if data.origin.file_id().map(|file_id| file_id.file_id(self)) == Some(file_id) {
|
if data.origin.file_id().map(|file_id| file_id.file_id(self)) == Some(file_id) {
|
||||||
return Some(crate_def_map.module_id(local_id));
|
return Some(crate_def_map.module_id(local_id));
|
||||||
@ -137,7 +137,7 @@ impl TestDB {
|
|||||||
) -> FxHashMap<EditionedFileId, Vec<(TextRange, String)>> {
|
) -> FxHashMap<EditionedFileId, Vec<(TextRange, String)>> {
|
||||||
let mut files = Vec::new();
|
let mut files = Vec::new();
|
||||||
for &krate in self.all_crates().iter() {
|
for &krate in self.all_crates().iter() {
|
||||||
let crate_def_map = self.crate_def_map(krate);
|
let crate_def_map = crate_def_map(self, krate);
|
||||||
for (module_id, _) in crate_def_map.modules() {
|
for (module_id, _) in crate_def_map.modules() {
|
||||||
let file_id = crate_def_map[module_id].origin.file_id();
|
let file_id = crate_def_map[module_id].origin.file_id();
|
||||||
files.extend(file_id)
|
files.extend(file_id)
|
||||||
|
@ -132,7 +132,7 @@ fn check_impl(
|
|||||||
None => continue,
|
None => continue,
|
||||||
};
|
};
|
||||||
let def_map = module.def_map(&db);
|
let def_map = module.def_map(&db);
|
||||||
visit_module(&db, &def_map, module.local_id, &mut |it| {
|
visit_module(&db, def_map, module.local_id, &mut |it| {
|
||||||
let def = match it {
|
let def = match it {
|
||||||
ModuleDefId::FunctionId(it) => it.into(),
|
ModuleDefId::FunctionId(it) => it.into(),
|
||||||
ModuleDefId::EnumVariantId(it) => it.into(),
|
ModuleDefId::EnumVariantId(it) => it.into(),
|
||||||
@ -391,7 +391,7 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String {
|
|||||||
let def_map = module.def_map(&db);
|
let def_map = module.def_map(&db);
|
||||||
|
|
||||||
let mut defs: Vec<(DefWithBodyId, Crate)> = Vec::new();
|
let mut defs: Vec<(DefWithBodyId, Crate)> = Vec::new();
|
||||||
visit_module(&db, &def_map, module.local_id, &mut |it| {
|
visit_module(&db, def_map, module.local_id, &mut |it| {
|
||||||
let def = match it {
|
let def = match it {
|
||||||
ModuleDefId::FunctionId(it) => it.into(),
|
ModuleDefId::FunctionId(it) => it.into(),
|
||||||
ModuleDefId::EnumVariantId(it) => it.into(),
|
ModuleDefId::EnumVariantId(it) => it.into(),
|
||||||
@ -504,7 +504,7 @@ pub(crate) fn visit_module(
|
|||||||
fn visit_body(db: &TestDB, body: &Body, cb: &mut dyn FnMut(ModuleDefId)) {
|
fn visit_body(db: &TestDB, body: &Body, cb: &mut dyn FnMut(ModuleDefId)) {
|
||||||
for (_, def_map) in body.blocks(db) {
|
for (_, def_map) in body.blocks(db) {
|
||||||
for (mod_id, _) in def_map.modules() {
|
for (mod_id, _) in def_map.modules() {
|
||||||
visit_module(db, &def_map, mod_id, cb);
|
visit_module(db, def_map, mod_id, cb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -570,7 +570,7 @@ fn salsa_bug() {
|
|||||||
|
|
||||||
let module = db.module_for_file(pos.file_id.file_id(&db));
|
let module = db.module_for_file(pos.file_id.file_id(&db));
|
||||||
let crate_def_map = module.def_map(&db);
|
let crate_def_map = module.def_map(&db);
|
||||||
visit_module(&db, &crate_def_map, module.local_id, &mut |def| {
|
visit_module(&db, crate_def_map, module.local_id, &mut |def| {
|
||||||
db.infer(match def {
|
db.infer(match def {
|
||||||
ModuleDefId::FunctionId(it) => it.into(),
|
ModuleDefId::FunctionId(it) => it.into(),
|
||||||
ModuleDefId::EnumVariantId(it) => it.into(),
|
ModuleDefId::EnumVariantId(it) => it.into(),
|
||||||
@ -609,7 +609,7 @@ fn salsa_bug() {
|
|||||||
|
|
||||||
let module = db.module_for_file(pos.file_id.file_id(&db));
|
let module = db.module_for_file(pos.file_id.file_id(&db));
|
||||||
let crate_def_map = module.def_map(&db);
|
let crate_def_map = module.def_map(&db);
|
||||||
visit_module(&db, &crate_def_map, module.local_id, &mut |def| {
|
visit_module(&db, crate_def_map, module.local_id, &mut |def| {
|
||||||
db.infer(match def {
|
db.infer(match def {
|
||||||
ModuleDefId::FunctionId(it) => it.into(),
|
ModuleDefId::FunctionId(it) => it.into(),
|
||||||
ModuleDefId::EnumVariantId(it) => it.into(),
|
ModuleDefId::EnumVariantId(it) => it.into(),
|
||||||
|
@ -20,7 +20,7 @@ fn check_closure_captures(#[rust_analyzer::rust_fixture] ra_fixture: &str, expec
|
|||||||
let def_map = module.def_map(&db);
|
let def_map = module.def_map(&db);
|
||||||
|
|
||||||
let mut defs = Vec::new();
|
let mut defs = Vec::new();
|
||||||
visit_module(&db, &def_map, module.local_id, &mut |it| defs.push(it));
|
visit_module(&db, def_map, module.local_id, &mut |it| defs.push(it));
|
||||||
|
|
||||||
let mut captures_info = Vec::new();
|
let mut captures_info = Vec::new();
|
||||||
for def in defs {
|
for def in defs {
|
||||||
|
@ -19,7 +19,7 @@ fn foo() -> i32 {
|
|||||||
let events = db.log_executed(|| {
|
let events = db.log_executed(|| {
|
||||||
let module = db.module_for_file(pos.file_id.file_id(&db));
|
let module = db.module_for_file(pos.file_id.file_id(&db));
|
||||||
let crate_def_map = module.def_map(&db);
|
let crate_def_map = module.def_map(&db);
|
||||||
visit_module(&db, &crate_def_map, module.local_id, &mut |def| {
|
visit_module(&db, crate_def_map, module.local_id, &mut |def| {
|
||||||
if let ModuleDefId::FunctionId(it) = def {
|
if let ModuleDefId::FunctionId(it) = def {
|
||||||
db.infer(it.into());
|
db.infer(it.into());
|
||||||
}
|
}
|
||||||
@ -41,7 +41,7 @@ fn foo() -> i32 {
|
|||||||
let events = db.log_executed(|| {
|
let events = db.log_executed(|| {
|
||||||
let module = db.module_for_file(pos.file_id.file_id(&db));
|
let module = db.module_for_file(pos.file_id.file_id(&db));
|
||||||
let crate_def_map = module.def_map(&db);
|
let crate_def_map = module.def_map(&db);
|
||||||
visit_module(&db, &crate_def_map, module.local_id, &mut |def| {
|
visit_module(&db, crate_def_map, module.local_id, &mut |def| {
|
||||||
if let ModuleDefId::FunctionId(it) = def {
|
if let ModuleDefId::FunctionId(it) = def {
|
||||||
db.infer(it.into());
|
db.infer(it.into());
|
||||||
}
|
}
|
||||||
@ -70,7 +70,7 @@ fn baz() -> i32 {
|
|||||||
let events = db.log_executed(|| {
|
let events = db.log_executed(|| {
|
||||||
let module = db.module_for_file(pos.file_id.file_id(&db));
|
let module = db.module_for_file(pos.file_id.file_id(&db));
|
||||||
let crate_def_map = module.def_map(&db);
|
let crate_def_map = module.def_map(&db);
|
||||||
visit_module(&db, &crate_def_map, module.local_id, &mut |def| {
|
visit_module(&db, crate_def_map, module.local_id, &mut |def| {
|
||||||
if let ModuleDefId::FunctionId(it) = def {
|
if let ModuleDefId::FunctionId(it) = def {
|
||||||
db.infer(it.into());
|
db.infer(it.into());
|
||||||
}
|
}
|
||||||
@ -97,7 +97,7 @@ fn baz() -> i32 {
|
|||||||
let events = db.log_executed(|| {
|
let events = db.log_executed(|| {
|
||||||
let module = db.module_for_file(pos.file_id.file_id(&db));
|
let module = db.module_for_file(pos.file_id.file_id(&db));
|
||||||
let crate_def_map = module.def_map(&db);
|
let crate_def_map = module.def_map(&db);
|
||||||
visit_module(&db, &crate_def_map, module.local_id, &mut |def| {
|
visit_module(&db, crate_def_map, module.local_id, &mut |def| {
|
||||||
if let ModuleDefId::FunctionId(it) = def {
|
if let ModuleDefId::FunctionId(it) = def {
|
||||||
db.infer(it.into());
|
db.infer(it.into());
|
||||||
}
|
}
|
||||||
|
@ -984,7 +984,7 @@ struct FixedPoint<T, U, V>(&'static FixedPoint<(), T, U>, V);
|
|||||||
let mut defs: Vec<GenericDefId> = Vec::new();
|
let mut defs: Vec<GenericDefId> = Vec::new();
|
||||||
let module = db.module_for_file_opt(file_id.file_id(&db)).unwrap();
|
let module = db.module_for_file_opt(file_id.file_id(&db)).unwrap();
|
||||||
let def_map = module.def_map(&db);
|
let def_map = module.def_map(&db);
|
||||||
crate::tests::visit_module(&db, &def_map, module.local_id, &mut |it| {
|
crate::tests::visit_module(&db, def_map, module.local_id, &mut |it| {
|
||||||
defs.push(match it {
|
defs.push(match it {
|
||||||
ModuleDefId::FunctionId(it) => it.into(),
|
ModuleDefId::FunctionId(it) => it.into(),
|
||||||
ModuleDefId::AdtId(it) => it.into(),
|
ModuleDefId::AdtId(it) => it.into(),
|
||||||
|
@ -160,7 +160,7 @@ fn resolve_doc_path_on_(
|
|||||||
|
|
||||||
fn resolve_assoc_or_field(
|
fn resolve_assoc_or_field(
|
||||||
db: &dyn HirDatabase,
|
db: &dyn HirDatabase,
|
||||||
resolver: Resolver,
|
resolver: Resolver<'_>,
|
||||||
path: ModPath,
|
path: ModPath,
|
||||||
name: Name,
|
name: Name,
|
||||||
ns: Option<Namespace>,
|
ns: Option<Namespace>,
|
||||||
@ -248,7 +248,7 @@ fn resolve_assoc_item(
|
|||||||
|
|
||||||
fn resolve_impl_trait_item(
|
fn resolve_impl_trait_item(
|
||||||
db: &dyn HirDatabase,
|
db: &dyn HirDatabase,
|
||||||
resolver: Resolver,
|
resolver: Resolver<'_>,
|
||||||
ty: &Type,
|
ty: &Type,
|
||||||
name: &Name,
|
name: &Name,
|
||||||
ns: Option<Namespace>,
|
ns: Option<Namespace>,
|
||||||
|
@ -119,7 +119,7 @@ pub use {
|
|||||||
find_path::PrefixKind,
|
find_path::PrefixKind,
|
||||||
import_map,
|
import_map,
|
||||||
lang_item::LangItem,
|
lang_item::LangItem,
|
||||||
nameres::{DefMap, ModuleSource},
|
nameres::{DefMap, ModuleSource, crate_def_map},
|
||||||
per_ns::Namespace,
|
per_ns::Namespace,
|
||||||
type_ref::{Mutability, TypeRef},
|
type_ref::{Mutability, TypeRef},
|
||||||
visibility::Visibility,
|
visibility::Visibility,
|
||||||
@ -227,7 +227,7 @@ impl Crate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn modules(self, db: &dyn HirDatabase) -> Vec<Module> {
|
pub fn modules(self, db: &dyn HirDatabase) -> Vec<Module> {
|
||||||
let def_map = db.crate_def_map(self.id);
|
let def_map = crate_def_map(db, self.id);
|
||||||
def_map.modules().map(|(id, _)| def_map.module_id(id).into()).collect()
|
def_map.modules().map(|(id, _)| def_map.module_id(id).into()).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -528,7 +528,7 @@ impl Module {
|
|||||||
/// might be missing `krate`. This can happen if a module's file is not included
|
/// might be missing `krate`. This can happen if a module's file is not included
|
||||||
/// in the module tree of any target in `Cargo.toml`.
|
/// in the module tree of any target in `Cargo.toml`.
|
||||||
pub fn crate_root(self, db: &dyn HirDatabase) -> Module {
|
pub fn crate_root(self, db: &dyn HirDatabase) -> Module {
|
||||||
let def_map = db.crate_def_map(self.id.krate());
|
let def_map = crate_def_map(db, self.id.krate());
|
||||||
Module { id: def_map.crate_root().into() }
|
Module { id: def_map.crate_root().into() }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2468,7 +2468,7 @@ impl Function {
|
|||||||
{
|
{
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let def_map = db.crate_def_map(HasModule::krate(&self.id, db));
|
let def_map = crate_def_map(db, HasModule::krate(&self.id, db));
|
||||||
def_map.fn_as_proc_macro(self.id).map(|id| Macro { id: id.into() })
|
def_map.fn_as_proc_macro(self.id).map(|id| Macro { id: id.into() })
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4015,8 +4015,7 @@ impl BuiltinAttr {
|
|||||||
if let builtin @ Some(_) = Self::builtin(name) {
|
if let builtin @ Some(_) = Self::builtin(name) {
|
||||||
return builtin;
|
return builtin;
|
||||||
}
|
}
|
||||||
let idx = db
|
let idx = crate_def_map(db, krate.id)
|
||||||
.crate_def_map(krate.id)
|
|
||||||
.registered_attrs()
|
.registered_attrs()
|
||||||
.iter()
|
.iter()
|
||||||
.position(|it| it.as_str() == name)? as u32;
|
.position(|it| it.as_str() == name)? as u32;
|
||||||
@ -4031,7 +4030,7 @@ impl BuiltinAttr {
|
|||||||
pub fn name(&self, db: &dyn HirDatabase) -> Name {
|
pub fn name(&self, db: &dyn HirDatabase) -> Name {
|
||||||
match self.krate {
|
match self.krate {
|
||||||
Some(krate) => Name::new_symbol_root(
|
Some(krate) => Name::new_symbol_root(
|
||||||
db.crate_def_map(krate).registered_attrs()[self.idx as usize].clone(),
|
crate_def_map(db, krate).registered_attrs()[self.idx as usize].clone(),
|
||||||
),
|
),
|
||||||
None => Name::new_symbol_root(Symbol::intern(
|
None => Name::new_symbol_root(Symbol::intern(
|
||||||
hir_expand::inert_attr_macro::INERT_ATTRIBUTES[self.idx as usize].name,
|
hir_expand::inert_attr_macro::INERT_ATTRIBUTES[self.idx as usize].name,
|
||||||
@ -4059,14 +4058,14 @@ impl ToolModule {
|
|||||||
pub(crate) fn by_name(db: &dyn HirDatabase, krate: Crate, name: &str) -> Option<Self> {
|
pub(crate) fn by_name(db: &dyn HirDatabase, krate: Crate, name: &str) -> Option<Self> {
|
||||||
let krate = krate.id;
|
let krate = krate.id;
|
||||||
let idx =
|
let idx =
|
||||||
db.crate_def_map(krate).registered_tools().iter().position(|it| it.as_str() == name)?
|
crate_def_map(db, krate).registered_tools().iter().position(|it| it.as_str() == name)?
|
||||||
as u32;
|
as u32;
|
||||||
Some(ToolModule { krate, idx })
|
Some(ToolModule { krate, idx })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn name(&self, db: &dyn HirDatabase) -> Name {
|
pub fn name(&self, db: &dyn HirDatabase) -> Name {
|
||||||
Name::new_symbol_root(
|
Name::new_symbol_root(
|
||||||
db.crate_def_map(self.krate).registered_tools()[self.idx as usize].clone(),
|
crate_def_map(db, self.krate).registered_tools()[self.idx as usize].clone(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4488,7 +4487,7 @@ impl Impl {
|
|||||||
MacroCallKind::Derive { ast_id, derive_attr_index, derive_index, .. } => {
|
MacroCallKind::Derive { ast_id, derive_attr_index, derive_index, .. } => {
|
||||||
let module_id = self.id.lookup(db).container;
|
let module_id = self.id.lookup(db).container;
|
||||||
(
|
(
|
||||||
db.crate_def_map(module_id.krate())[module_id.local_id]
|
crate_def_map(db, module_id.krate())[module_id.local_id]
|
||||||
.scope
|
.scope
|
||||||
.derive_macro_invoc(ast_id, derive_attr_index)?,
|
.derive_macro_invoc(ast_id, derive_attr_index)?,
|
||||||
derive_index,
|
derive_index,
|
||||||
@ -4530,7 +4529,7 @@ pub struct TraitRef {
|
|||||||
impl TraitRef {
|
impl TraitRef {
|
||||||
pub(crate) fn new_with_resolver(
|
pub(crate) fn new_with_resolver(
|
||||||
db: &dyn HirDatabase,
|
db: &dyn HirDatabase,
|
||||||
resolver: &Resolver,
|
resolver: &Resolver<'_>,
|
||||||
trait_ref: hir_ty::TraitRef,
|
trait_ref: hir_ty::TraitRef,
|
||||||
) -> TraitRef {
|
) -> TraitRef {
|
||||||
let env = resolver
|
let env = resolver
|
||||||
@ -4752,13 +4751,13 @@ pub struct Type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Type {
|
impl Type {
|
||||||
pub(crate) fn new_with_resolver(db: &dyn HirDatabase, resolver: &Resolver, ty: Ty) -> Type {
|
pub(crate) fn new_with_resolver(db: &dyn HirDatabase, resolver: &Resolver<'_>, ty: Ty) -> Type {
|
||||||
Type::new_with_resolver_inner(db, resolver, ty)
|
Type::new_with_resolver_inner(db, resolver, ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn new_with_resolver_inner(
|
pub(crate) fn new_with_resolver_inner(
|
||||||
db: &dyn HirDatabase,
|
db: &dyn HirDatabase,
|
||||||
resolver: &Resolver,
|
resolver: &Resolver<'_>,
|
||||||
ty: Ty,
|
ty: Ty,
|
||||||
) -> Type {
|
) -> Type {
|
||||||
let environment = resolver
|
let environment = resolver
|
||||||
@ -6400,7 +6399,7 @@ pub fn resolve_absolute_path<'a, I: Iterator<Item = Symbol> + Clone + 'a>(
|
|||||||
})
|
})
|
||||||
.filter_map(|&krate| {
|
.filter_map(|&krate| {
|
||||||
let segments = segments.clone();
|
let segments = segments.clone();
|
||||||
let mut def_map = db.crate_def_map(krate);
|
let mut def_map = crate_def_map(db, krate);
|
||||||
let mut module = &def_map[DefMap::ROOT];
|
let mut module = &def_map[DefMap::ROOT];
|
||||||
let mut segments = segments.with_position().peekable();
|
let mut segments = segments.with_position().peekable();
|
||||||
while let Some((_, segment)) = segments.next_if(|&(position, _)| {
|
while let Some((_, segment)) = segments.next_if(|&(position, _)| {
|
||||||
|
@ -15,7 +15,7 @@ use hir_def::{
|
|||||||
DefWithBodyId, FunctionId, MacroId, StructId, TraitId, VariantId,
|
DefWithBodyId, FunctionId, MacroId, StructId, TraitId, VariantId,
|
||||||
expr_store::{Body, ExprOrPatSource, path::Path},
|
expr_store::{Body, ExprOrPatSource, path::Path},
|
||||||
hir::{BindingId, Expr, ExprId, ExprOrPatId, Pat},
|
hir::{BindingId, Expr, ExprId, ExprOrPatId, Pat},
|
||||||
nameres::ModuleOrigin,
|
nameres::{ModuleOrigin, crate_def_map},
|
||||||
resolver::{self, HasResolver, Resolver, TypeNs},
|
resolver::{self, HasResolver, Resolver, TypeNs},
|
||||||
type_ref::Mutability,
|
type_ref::Mutability,
|
||||||
};
|
};
|
||||||
@ -341,7 +341,7 @@ impl<'db> SemanticsImpl<'db> {
|
|||||||
match file_id {
|
match file_id {
|
||||||
HirFileId::FileId(file_id) => {
|
HirFileId::FileId(file_id) => {
|
||||||
let module = self.file_to_module_defs(file_id.file_id(self.db)).next()?;
|
let module = self.file_to_module_defs(file_id.file_id(self.db)).next()?;
|
||||||
let def_map = self.db.crate_def_map(module.krate().id);
|
let def_map = crate_def_map(self.db, module.krate().id);
|
||||||
match def_map[module.id.local_id].origin {
|
match def_map[module.id.local_id].origin {
|
||||||
ModuleOrigin::CrateRoot { .. } => None,
|
ModuleOrigin::CrateRoot { .. } => None,
|
||||||
ModuleOrigin::File { declaration, declaration_tree_id, .. } => {
|
ModuleOrigin::File { declaration, declaration_tree_id, .. } => {
|
||||||
@ -1711,13 +1711,13 @@ impl<'db> SemanticsImpl<'db> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns none if the file of the node is not part of a crate.
|
/// Returns none if the file of the node is not part of a crate.
|
||||||
fn analyze(&self, node: &SyntaxNode) -> Option<SourceAnalyzer> {
|
fn analyze(&self, node: &SyntaxNode) -> Option<SourceAnalyzer<'db>> {
|
||||||
let node = self.find_file(node);
|
let node = self.find_file(node);
|
||||||
self.analyze_impl(node, None, true)
|
self.analyze_impl(node, None, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns none if the file of the node is not part of a crate.
|
/// Returns none if the file of the node is not part of a crate.
|
||||||
fn analyze_no_infer(&self, node: &SyntaxNode) -> Option<SourceAnalyzer> {
|
fn analyze_no_infer(&self, node: &SyntaxNode) -> Option<SourceAnalyzer<'db>> {
|
||||||
let node = self.find_file(node);
|
let node = self.find_file(node);
|
||||||
self.analyze_impl(node, None, false)
|
self.analyze_impl(node, None, false)
|
||||||
}
|
}
|
||||||
@ -1726,7 +1726,7 @@ impl<'db> SemanticsImpl<'db> {
|
|||||||
&self,
|
&self,
|
||||||
node: &SyntaxNode,
|
node: &SyntaxNode,
|
||||||
offset: TextSize,
|
offset: TextSize,
|
||||||
) -> Option<SourceAnalyzer> {
|
) -> Option<SourceAnalyzer<'db>> {
|
||||||
let node = self.find_file(node);
|
let node = self.find_file(node);
|
||||||
self.analyze_impl(node, Some(offset), false)
|
self.analyze_impl(node, Some(offset), false)
|
||||||
}
|
}
|
||||||
@ -1737,7 +1737,7 @@ impl<'db> SemanticsImpl<'db> {
|
|||||||
offset: Option<TextSize>,
|
offset: Option<TextSize>,
|
||||||
// replace this, just make the inference result a `LazyCell`
|
// replace this, just make the inference result a `LazyCell`
|
||||||
infer_body: bool,
|
infer_body: bool,
|
||||||
) -> Option<SourceAnalyzer> {
|
) -> Option<SourceAnalyzer<'db>> {
|
||||||
let _p = tracing::info_span!("SemanticsImpl::analyze_impl").entered();
|
let _p = tracing::info_span!("SemanticsImpl::analyze_impl").entered();
|
||||||
|
|
||||||
let container = self.with_ctx(|ctx| ctx.find_container(node))?;
|
let container = self.with_ctx(|ctx| ctx.find_container(node))?;
|
||||||
@ -1984,13 +1984,13 @@ fn find_root(node: &SyntaxNode) -> SyntaxNode {
|
|||||||
/// Note that if you are wondering "what does this specific existing name mean?",
|
/// Note that if you are wondering "what does this specific existing name mean?",
|
||||||
/// you'd better use the `resolve_` family of methods.
|
/// you'd better use the `resolve_` family of methods.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct SemanticsScope<'a> {
|
pub struct SemanticsScope<'db> {
|
||||||
pub db: &'a dyn HirDatabase,
|
pub db: &'db dyn HirDatabase,
|
||||||
file_id: HirFileId,
|
file_id: HirFileId,
|
||||||
resolver: Resolver,
|
resolver: Resolver<'db>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SemanticsScope<'_> {
|
impl<'db> SemanticsScope<'db> {
|
||||||
pub fn module(&self) -> Module {
|
pub fn module(&self) -> Module {
|
||||||
Module { id: self.resolver.module() }
|
Module { id: self.resolver.module() }
|
||||||
}
|
}
|
||||||
@ -2006,7 +2006,7 @@ impl SemanticsScope<'_> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn resolver(&self) -> &Resolver {
|
pub(crate) fn resolver(&self) -> &Resolver<'db> {
|
||||||
&self.resolver
|
&self.resolver
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2133,7 +2133,7 @@ impl ops::Deref for VisibleTraits {
|
|||||||
struct RenameConflictsVisitor<'a> {
|
struct RenameConflictsVisitor<'a> {
|
||||||
db: &'a dyn HirDatabase,
|
db: &'a dyn HirDatabase,
|
||||||
owner: DefWithBodyId,
|
owner: DefWithBodyId,
|
||||||
resolver: Resolver,
|
resolver: Resolver<'a>,
|
||||||
body: &'a Body,
|
body: &'a Body,
|
||||||
to_be_renamed: BindingId,
|
to_be_renamed: BindingId,
|
||||||
new_name: Symbol,
|
new_name: Symbol,
|
||||||
|
@ -96,6 +96,7 @@ use hir_def::{
|
|||||||
keys::{self, Key},
|
keys::{self, Key},
|
||||||
},
|
},
|
||||||
hir::{BindingId, Expr, LabelId},
|
hir::{BindingId, Expr, LabelId},
|
||||||
|
nameres::{block_def_map, crate_def_map},
|
||||||
};
|
};
|
||||||
use hir_expand::{
|
use hir_expand::{
|
||||||
EditionedFileId, ExpansionInfo, HirFileId, InMacroFile, MacroCallId, attrs::AttrId,
|
EditionedFileId, ExpansionInfo, HirFileId, InMacroFile, MacroCallId, attrs::AttrId,
|
||||||
@ -180,7 +181,7 @@ impl SourceToDefCtx<'_, '_> {
|
|||||||
|
|
||||||
for &crate_id in self.db.relevant_crates(file).iter() {
|
for &crate_id in self.db.relevant_crates(file).iter() {
|
||||||
// Note: `mod` declarations in block modules cannot be supported here
|
// Note: `mod` declarations in block modules cannot be supported here
|
||||||
let crate_def_map = self.db.crate_def_map(crate_id);
|
let crate_def_map = crate_def_map(self.db, crate_id);
|
||||||
let n_mods = mods.len();
|
let n_mods = mods.len();
|
||||||
let modules = |file| {
|
let modules = |file| {
|
||||||
crate_def_map
|
crate_def_map
|
||||||
@ -226,7 +227,7 @@ impl SourceToDefCtx<'_, '_> {
|
|||||||
let parent_module = match parent_declaration {
|
let parent_module = match parent_declaration {
|
||||||
Some(Either::Right(parent_block)) => self
|
Some(Either::Right(parent_block)) => self
|
||||||
.block_to_def(parent_block.as_ref())
|
.block_to_def(parent_block.as_ref())
|
||||||
.map(|block| self.db.block_def_map(block).root_module_id()),
|
.map(|block| block_def_map(self.db, block).root_module_id()),
|
||||||
Some(Either::Left(parent_declaration)) => {
|
Some(Either::Left(parent_declaration)) => {
|
||||||
self.module_to_def(parent_declaration.as_ref())
|
self.module_to_def(parent_declaration.as_ref())
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ use hir_def::{
|
|||||||
},
|
},
|
||||||
hir::{BindingId, Expr, ExprId, ExprOrPatId, Pat},
|
hir::{BindingId, Expr, ExprId, ExprOrPatId, Pat},
|
||||||
lang_item::LangItem,
|
lang_item::LangItem,
|
||||||
nameres::MacroSubNs,
|
nameres::{MacroSubNs, crate_def_map},
|
||||||
resolver::{HasResolver, Resolver, TypeNs, ValueNs, resolver_for_scope},
|
resolver::{HasResolver, Resolver, TypeNs, ValueNs, resolver_for_scope},
|
||||||
type_ref::{Mutability, TypeRefId},
|
type_ref::{Mutability, TypeRefId},
|
||||||
};
|
};
|
||||||
@ -57,9 +57,9 @@ use triomphe::Arc;
|
|||||||
/// `SourceAnalyzer` is a convenience wrapper which exposes HIR API in terms of
|
/// `SourceAnalyzer` is a convenience wrapper which exposes HIR API in terms of
|
||||||
/// original source files. It should not be used inside the HIR itself.
|
/// original source files. It should not be used inside the HIR itself.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct SourceAnalyzer {
|
pub(crate) struct SourceAnalyzer<'db> {
|
||||||
pub(crate) file_id: HirFileId,
|
pub(crate) file_id: HirFileId,
|
||||||
pub(crate) resolver: Resolver,
|
pub(crate) resolver: Resolver<'db>,
|
||||||
pub(crate) body_or_sig: Option<BodyOrSig>,
|
pub(crate) body_or_sig: Option<BodyOrSig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,32 +85,32 @@ pub(crate) enum BodyOrSig {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SourceAnalyzer {
|
impl<'db> SourceAnalyzer<'db> {
|
||||||
pub(crate) fn new_for_body(
|
pub(crate) fn new_for_body(
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
def: DefWithBodyId,
|
def: DefWithBodyId,
|
||||||
node: InFile<&SyntaxNode>,
|
node: InFile<&SyntaxNode>,
|
||||||
offset: Option<TextSize>,
|
offset: Option<TextSize>,
|
||||||
) -> SourceAnalyzer {
|
) -> SourceAnalyzer<'db> {
|
||||||
Self::new_for_body_(db, def, node, offset, Some(db.infer(def)))
|
Self::new_for_body_(db, def, node, offset, Some(db.infer(def)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn new_for_body_no_infer(
|
pub(crate) fn new_for_body_no_infer(
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
def: DefWithBodyId,
|
def: DefWithBodyId,
|
||||||
node: InFile<&SyntaxNode>,
|
node: InFile<&SyntaxNode>,
|
||||||
offset: Option<TextSize>,
|
offset: Option<TextSize>,
|
||||||
) -> SourceAnalyzer {
|
) -> SourceAnalyzer<'db> {
|
||||||
Self::new_for_body_(db, def, node, offset, None)
|
Self::new_for_body_(db, def, node, offset, None)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn new_for_body_(
|
pub(crate) fn new_for_body_(
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
def: DefWithBodyId,
|
def: DefWithBodyId,
|
||||||
node @ InFile { file_id, .. }: InFile<&SyntaxNode>,
|
node @ InFile { file_id, .. }: InFile<&SyntaxNode>,
|
||||||
offset: Option<TextSize>,
|
offset: Option<TextSize>,
|
||||||
infer: Option<Arc<InferenceResult>>,
|
infer: Option<Arc<InferenceResult>>,
|
||||||
) -> SourceAnalyzer {
|
) -> SourceAnalyzer<'db> {
|
||||||
let (body, source_map) = db.body_with_source_map(def);
|
let (body, source_map) = db.body_with_source_map(def);
|
||||||
let scopes = db.expr_scopes(def);
|
let scopes = db.expr_scopes(def);
|
||||||
let scope = match offset {
|
let scope = match offset {
|
||||||
@ -134,11 +134,11 @@ impl SourceAnalyzer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn new_generic_def(
|
pub(crate) fn new_generic_def(
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
def: GenericDefId,
|
def: GenericDefId,
|
||||||
InFile { file_id, .. }: InFile<&SyntaxNode>,
|
InFile { file_id, .. }: InFile<&SyntaxNode>,
|
||||||
_offset: Option<TextSize>,
|
_offset: Option<TextSize>,
|
||||||
) -> SourceAnalyzer {
|
) -> SourceAnalyzer<'db> {
|
||||||
let (_params, store, source_map) = db.generic_params_and_store_and_source_map(def);
|
let (_params, store, source_map) = db.generic_params_and_store_and_source_map(def);
|
||||||
let resolver = def.resolver(db);
|
let resolver = def.resolver(db);
|
||||||
SourceAnalyzer {
|
SourceAnalyzer {
|
||||||
@ -149,11 +149,11 @@ impl SourceAnalyzer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn new_variant_body(
|
pub(crate) fn new_variant_body(
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
def: VariantId,
|
def: VariantId,
|
||||||
InFile { file_id, .. }: InFile<&SyntaxNode>,
|
InFile { file_id, .. }: InFile<&SyntaxNode>,
|
||||||
_offset: Option<TextSize>,
|
_offset: Option<TextSize>,
|
||||||
) -> SourceAnalyzer {
|
) -> SourceAnalyzer<'db> {
|
||||||
let (fields, source_map) = db.variant_fields_with_source_map(def);
|
let (fields, source_map) = db.variant_fields_with_source_map(def);
|
||||||
let resolver = def.resolver(db);
|
let resolver = def.resolver(db);
|
||||||
SourceAnalyzer {
|
SourceAnalyzer {
|
||||||
@ -168,9 +168,9 @@ impl SourceAnalyzer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn new_for_resolver(
|
pub(crate) fn new_for_resolver(
|
||||||
resolver: Resolver,
|
resolver: Resolver<'db>,
|
||||||
node: InFile<&SyntaxNode>,
|
node: InFile<&SyntaxNode>,
|
||||||
) -> SourceAnalyzer {
|
) -> SourceAnalyzer<'db> {
|
||||||
SourceAnalyzer { resolver, body_or_sig: None, file_id: node.file_id }
|
SourceAnalyzer { resolver, body_or_sig: None, file_id: node.file_id }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,7 +220,7 @@ impl SourceAnalyzer {
|
|||||||
self.store_sm()?.expansion(node)
|
self.store_sm()?.expansion(node)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn trait_environment(&self, db: &dyn HirDatabase) -> Arc<TraitEnvironment> {
|
fn trait_environment(&self, db: &'db dyn HirDatabase) -> Arc<TraitEnvironment> {
|
||||||
self.body_().map(|(def, ..)| def).map_or_else(
|
self.body_().map(|(def, ..)| def).map_or_else(
|
||||||
|| TraitEnvironment::empty(self.resolver.krate()),
|
|| TraitEnvironment::empty(self.resolver.krate()),
|
||||||
|def| db.trait_environment_for_body(def),
|
|def| db.trait_environment_for_body(def),
|
||||||
@ -259,7 +259,7 @@ impl SourceAnalyzer {
|
|||||||
infer.expr_adjustments.get(&expr_id).map(|v| &**v)
|
infer.expr_adjustments.get(&expr_id).map(|v| &**v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn type_of_type(&self, db: &dyn HirDatabase, ty: &ast::Type) -> Option<Type> {
|
pub(crate) fn type_of_type(&self, db: &'db dyn HirDatabase, ty: &ast::Type) -> Option<Type> {
|
||||||
let type_ref = self.type_id(ty)?;
|
let type_ref = self.type_id(ty)?;
|
||||||
let ty = TyLoweringContext::new(
|
let ty = TyLoweringContext::new(
|
||||||
db,
|
db,
|
||||||
@ -277,7 +277,7 @@ impl SourceAnalyzer {
|
|||||||
|
|
||||||
pub(crate) fn type_of_expr(
|
pub(crate) fn type_of_expr(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
expr: &ast::Expr,
|
expr: &ast::Expr,
|
||||||
) -> Option<(Type, Option<Type>)> {
|
) -> Option<(Type, Option<Type>)> {
|
||||||
let expr_id = self.expr_id(expr.clone())?;
|
let expr_id = self.expr_id(expr.clone())?;
|
||||||
@ -293,7 +293,7 @@ impl SourceAnalyzer {
|
|||||||
|
|
||||||
pub(crate) fn type_of_pat(
|
pub(crate) fn type_of_pat(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
pat: &ast::Pat,
|
pat: &ast::Pat,
|
||||||
) -> Option<(Type, Option<Type>)> {
|
) -> Option<(Type, Option<Type>)> {
|
||||||
let expr_or_pat_id = self.pat_id(pat)?;
|
let expr_or_pat_id = self.pat_id(pat)?;
|
||||||
@ -316,7 +316,7 @@ impl SourceAnalyzer {
|
|||||||
|
|
||||||
pub(crate) fn type_of_binding_in_pat(
|
pub(crate) fn type_of_binding_in_pat(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
pat: &ast::IdentPat,
|
pat: &ast::IdentPat,
|
||||||
) -> Option<Type> {
|
) -> Option<Type> {
|
||||||
let binding_id = self.binding_id_of_pat(pat)?;
|
let binding_id = self.binding_id_of_pat(pat)?;
|
||||||
@ -328,7 +328,7 @@ impl SourceAnalyzer {
|
|||||||
|
|
||||||
pub(crate) fn type_of_self(
|
pub(crate) fn type_of_self(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
_param: &ast::SelfParam,
|
_param: &ast::SelfParam,
|
||||||
) -> Option<Type> {
|
) -> Option<Type> {
|
||||||
let binding = self.body()?.self_param?;
|
let binding = self.body()?.self_param?;
|
||||||
@ -338,7 +338,7 @@ impl SourceAnalyzer {
|
|||||||
|
|
||||||
pub(crate) fn binding_mode_of_pat(
|
pub(crate) fn binding_mode_of_pat(
|
||||||
&self,
|
&self,
|
||||||
_db: &dyn HirDatabase,
|
_db: &'db dyn HirDatabase,
|
||||||
pat: &ast::IdentPat,
|
pat: &ast::IdentPat,
|
||||||
) -> Option<BindingMode> {
|
) -> Option<BindingMode> {
|
||||||
let id = self.pat_id(&pat.clone().into())?;
|
let id = self.pat_id(&pat.clone().into())?;
|
||||||
@ -353,7 +353,7 @@ impl SourceAnalyzer {
|
|||||||
}
|
}
|
||||||
pub(crate) fn pattern_adjustments(
|
pub(crate) fn pattern_adjustments(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
pat: &ast::Pat,
|
pat: &ast::Pat,
|
||||||
) -> Option<SmallVec<[Type; 1]>> {
|
) -> Option<SmallVec<[Type; 1]>> {
|
||||||
let pat_id = self.pat_id(pat)?;
|
let pat_id = self.pat_id(pat)?;
|
||||||
@ -370,7 +370,7 @@ impl SourceAnalyzer {
|
|||||||
|
|
||||||
pub(crate) fn resolve_method_call_as_callable(
|
pub(crate) fn resolve_method_call_as_callable(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
call: &ast::MethodCallExpr,
|
call: &ast::MethodCallExpr,
|
||||||
) -> Option<Callable> {
|
) -> Option<Callable> {
|
||||||
let expr_id = self.expr_id(call.clone().into())?.as_expr()?;
|
let expr_id = self.expr_id(call.clone().into())?.as_expr()?;
|
||||||
@ -384,7 +384,7 @@ impl SourceAnalyzer {
|
|||||||
|
|
||||||
pub(crate) fn resolve_method_call(
|
pub(crate) fn resolve_method_call(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
call: &ast::MethodCallExpr,
|
call: &ast::MethodCallExpr,
|
||||||
) -> Option<Function> {
|
) -> Option<Function> {
|
||||||
let expr_id = self.expr_id(call.clone().into())?.as_expr()?;
|
let expr_id = self.expr_id(call.clone().into())?.as_expr()?;
|
||||||
@ -395,7 +395,7 @@ impl SourceAnalyzer {
|
|||||||
|
|
||||||
pub(crate) fn resolve_method_call_fallback(
|
pub(crate) fn resolve_method_call_fallback(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
call: &ast::MethodCallExpr,
|
call: &ast::MethodCallExpr,
|
||||||
) -> Option<(Either<Function, Field>, Option<GenericSubstitution>)> {
|
) -> Option<(Either<Function, Field>, Option<GenericSubstitution>)> {
|
||||||
let expr_id = self.expr_id(call.clone().into())?.as_expr()?;
|
let expr_id = self.expr_id(call.clone().into())?.as_expr()?;
|
||||||
@ -419,7 +419,7 @@ impl SourceAnalyzer {
|
|||||||
|
|
||||||
pub(crate) fn resolve_expr_as_callable(
|
pub(crate) fn resolve_expr_as_callable(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
call: &ast::Expr,
|
call: &ast::Expr,
|
||||||
) -> Option<Callable> {
|
) -> Option<Callable> {
|
||||||
let (orig, adjusted) = self.type_of_expr(db, &call.clone())?;
|
let (orig, adjusted) = self.type_of_expr(db, &call.clone())?;
|
||||||
@ -441,7 +441,7 @@ impl SourceAnalyzer {
|
|||||||
&self,
|
&self,
|
||||||
field_expr: ExprId,
|
field_expr: ExprId,
|
||||||
infer: &InferenceResult,
|
infer: &InferenceResult,
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
) -> Option<GenericSubstitution> {
|
) -> Option<GenericSubstitution> {
|
||||||
let body = self.store()?;
|
let body = self.store()?;
|
||||||
if let Expr::Field { expr: object_expr, name: _ } = body[field_expr] {
|
if let Expr::Field { expr: object_expr, name: _ } = body[field_expr] {
|
||||||
@ -457,7 +457,7 @@ impl SourceAnalyzer {
|
|||||||
|
|
||||||
pub(crate) fn resolve_field_fallback(
|
pub(crate) fn resolve_field_fallback(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
field: &ast::FieldExpr,
|
field: &ast::FieldExpr,
|
||||||
) -> Option<(Either<Either<Field, TupleField>, Function>, Option<GenericSubstitution>)> {
|
) -> Option<(Either<Either<Field, TupleField>, Function>, Option<GenericSubstitution>)> {
|
||||||
let (def, ..) = self.body_()?;
|
let (def, ..) = self.body_()?;
|
||||||
@ -490,7 +490,7 @@ impl SourceAnalyzer {
|
|||||||
|
|
||||||
pub(crate) fn resolve_range_pat(
|
pub(crate) fn resolve_range_pat(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
range_pat: &ast::RangePat,
|
range_pat: &ast::RangePat,
|
||||||
) -> Option<StructId> {
|
) -> Option<StructId> {
|
||||||
let path: ModPath = match (range_pat.op_kind()?, range_pat.start(), range_pat.end()) {
|
let path: ModPath = match (range_pat.op_kind()?, range_pat.start(), range_pat.end()) {
|
||||||
@ -509,7 +509,7 @@ impl SourceAnalyzer {
|
|||||||
|
|
||||||
pub(crate) fn resolve_range_expr(
|
pub(crate) fn resolve_range_expr(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
range_expr: &ast::RangeExpr,
|
range_expr: &ast::RangeExpr,
|
||||||
) -> Option<StructId> {
|
) -> Option<StructId> {
|
||||||
let path: ModPath = match (range_expr.op_kind()?, range_expr.start(), range_expr.end()) {
|
let path: ModPath = match (range_expr.op_kind()?, range_expr.start(), range_expr.end()) {
|
||||||
@ -529,7 +529,7 @@ impl SourceAnalyzer {
|
|||||||
|
|
||||||
pub(crate) fn resolve_await_to_poll(
|
pub(crate) fn resolve_await_to_poll(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
await_expr: &ast::AwaitExpr,
|
await_expr: &ast::AwaitExpr,
|
||||||
) -> Option<FunctionId> {
|
) -> Option<FunctionId> {
|
||||||
let mut ty = self.ty_of_expr(await_expr.expr()?)?.clone();
|
let mut ty = self.ty_of_expr(await_expr.expr()?)?.clone();
|
||||||
@ -566,7 +566,7 @@ impl SourceAnalyzer {
|
|||||||
|
|
||||||
pub(crate) fn resolve_prefix_expr(
|
pub(crate) fn resolve_prefix_expr(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
prefix_expr: &ast::PrefixExpr,
|
prefix_expr: &ast::PrefixExpr,
|
||||||
) -> Option<FunctionId> {
|
) -> Option<FunctionId> {
|
||||||
let (op_trait, op_fn) = match prefix_expr.op_kind()? {
|
let (op_trait, op_fn) = match prefix_expr.op_kind()? {
|
||||||
@ -608,7 +608,7 @@ impl SourceAnalyzer {
|
|||||||
|
|
||||||
pub(crate) fn resolve_index_expr(
|
pub(crate) fn resolve_index_expr(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
index_expr: &ast::IndexExpr,
|
index_expr: &ast::IndexExpr,
|
||||||
) -> Option<FunctionId> {
|
) -> Option<FunctionId> {
|
||||||
let base_ty = self.ty_of_expr(index_expr.base()?)?;
|
let base_ty = self.ty_of_expr(index_expr.base()?)?;
|
||||||
@ -640,7 +640,7 @@ impl SourceAnalyzer {
|
|||||||
|
|
||||||
pub(crate) fn resolve_bin_expr(
|
pub(crate) fn resolve_bin_expr(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
binop_expr: &ast::BinExpr,
|
binop_expr: &ast::BinExpr,
|
||||||
) -> Option<FunctionId> {
|
) -> Option<FunctionId> {
|
||||||
let op = binop_expr.op_kind()?;
|
let op = binop_expr.op_kind()?;
|
||||||
@ -661,7 +661,7 @@ impl SourceAnalyzer {
|
|||||||
|
|
||||||
pub(crate) fn resolve_try_expr(
|
pub(crate) fn resolve_try_expr(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
try_expr: &ast::TryExpr,
|
try_expr: &ast::TryExpr,
|
||||||
) -> Option<FunctionId> {
|
) -> Option<FunctionId> {
|
||||||
let ty = self.ty_of_expr(try_expr.expr()?)?;
|
let ty = self.ty_of_expr(try_expr.expr()?)?;
|
||||||
@ -680,7 +680,7 @@ impl SourceAnalyzer {
|
|||||||
|
|
||||||
pub(crate) fn resolve_record_field(
|
pub(crate) fn resolve_record_field(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
field: &ast::RecordExprField,
|
field: &ast::RecordExprField,
|
||||||
) -> Option<(Field, Option<Local>, Type, GenericSubstitution)> {
|
) -> Option<(Field, Option<Local>, Type, GenericSubstitution)> {
|
||||||
let record_expr = ast::RecordExpr::cast(field.syntax().parent().and_then(|p| p.parent())?)?;
|
let record_expr = ast::RecordExpr::cast(field.syntax().parent().and_then(|p| p.parent())?)?;
|
||||||
@ -724,7 +724,7 @@ impl SourceAnalyzer {
|
|||||||
|
|
||||||
pub(crate) fn resolve_record_pat_field(
|
pub(crate) fn resolve_record_pat_field(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
field: &ast::RecordPatField,
|
field: &ast::RecordPatField,
|
||||||
) -> Option<(Field, Type, GenericSubstitution)> {
|
) -> Option<(Field, Type, GenericSubstitution)> {
|
||||||
let field_name = field.field_name()?.as_name();
|
let field_name = field.field_name()?.as_name();
|
||||||
@ -745,14 +745,14 @@ impl SourceAnalyzer {
|
|||||||
|
|
||||||
pub(crate) fn resolve_macro_call(
|
pub(crate) fn resolve_macro_call(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
macro_call: InFile<&ast::MacroCall>,
|
macro_call: InFile<&ast::MacroCall>,
|
||||||
) -> Option<Macro> {
|
) -> Option<Macro> {
|
||||||
let bs = self.store_sm()?;
|
let bs = self.store_sm()?;
|
||||||
bs.expansion(macro_call).and_then(|it| {
|
bs.expansion(macro_call).and_then(|it| {
|
||||||
// FIXME: Block def maps
|
// FIXME: Block def maps
|
||||||
let def = it.lookup(db).def;
|
let def = it.lookup(db).def;
|
||||||
db.crate_def_map(def.krate)
|
crate_def_map(db, def.krate)
|
||||||
.macro_def_to_macro_id
|
.macro_def_to_macro_id
|
||||||
.get(&def.kind.erased_ast_id())
|
.get(&def.kind.erased_ast_id())
|
||||||
.map(|it| (*it).into())
|
.map(|it| (*it).into())
|
||||||
@ -761,7 +761,7 @@ impl SourceAnalyzer {
|
|||||||
|
|
||||||
pub(crate) fn resolve_bind_pat_to_const(
|
pub(crate) fn resolve_bind_pat_to_const(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
pat: &ast::IdentPat,
|
pat: &ast::IdentPat,
|
||||||
) -> Option<ModuleDef> {
|
) -> Option<ModuleDef> {
|
||||||
let expr_or_pat_id = self.pat_id(&pat.clone().into())?;
|
let expr_or_pat_id = self.pat_id(&pat.clone().into())?;
|
||||||
@ -795,7 +795,7 @@ impl SourceAnalyzer {
|
|||||||
|
|
||||||
pub(crate) fn resolve_offset_of_field(
|
pub(crate) fn resolve_offset_of_field(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
name_ref: &ast::NameRef,
|
name_ref: &ast::NameRef,
|
||||||
) -> Option<(Either<crate::Variant, crate::Field>, GenericSubstitution)> {
|
) -> Option<(Either<crate::Variant, crate::Field>, GenericSubstitution)> {
|
||||||
let offset_of_expr = ast::OffsetOfExpr::cast(name_ref.syntax().parent()?)?;
|
let offset_of_expr = ast::OffsetOfExpr::cast(name_ref.syntax().parent()?)?;
|
||||||
@ -867,7 +867,7 @@ impl SourceAnalyzer {
|
|||||||
|
|
||||||
pub(crate) fn resolve_path(
|
pub(crate) fn resolve_path(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
path: &ast::Path,
|
path: &ast::Path,
|
||||||
) -> Option<(PathResolution, Option<GenericSubstitution>)> {
|
) -> Option<(PathResolution, Option<GenericSubstitution>)> {
|
||||||
let parent = path.syntax().parent();
|
let parent = path.syntax().parent();
|
||||||
@ -1211,7 +1211,7 @@ impl SourceAnalyzer {
|
|||||||
|
|
||||||
pub(crate) fn record_literal_missing_fields(
|
pub(crate) fn record_literal_missing_fields(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
literal: &ast::RecordExpr,
|
literal: &ast::RecordExpr,
|
||||||
) -> Option<Vec<(Field, Type)>> {
|
) -> Option<Vec<(Field, Type)>> {
|
||||||
let body = self.store()?;
|
let body = self.store()?;
|
||||||
@ -1234,7 +1234,7 @@ impl SourceAnalyzer {
|
|||||||
|
|
||||||
pub(crate) fn record_pattern_missing_fields(
|
pub(crate) fn record_pattern_missing_fields(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
pattern: &ast::RecordPat,
|
pattern: &ast::RecordPat,
|
||||||
) -> Option<Vec<(Field, Type)>> {
|
) -> Option<Vec<(Field, Type)>> {
|
||||||
let body = self.store()?;
|
let body = self.store()?;
|
||||||
@ -1251,7 +1251,7 @@ impl SourceAnalyzer {
|
|||||||
|
|
||||||
fn missing_fields(
|
fn missing_fields(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
substs: &Substitution,
|
substs: &Substitution,
|
||||||
variant: VariantId,
|
variant: VariantId,
|
||||||
missing_fields: Vec<LocalFieldId>,
|
missing_fields: Vec<LocalFieldId>,
|
||||||
@ -1270,7 +1270,7 @@ impl SourceAnalyzer {
|
|||||||
|
|
||||||
pub(crate) fn expand(
|
pub(crate) fn expand(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
macro_call: InFile<&ast::MacroCall>,
|
macro_call: InFile<&ast::MacroCall>,
|
||||||
) -> Option<MacroCallId> {
|
) -> Option<MacroCallId> {
|
||||||
self.store_sm().and_then(|bs| bs.expansion(macro_call)).or_else(|| {
|
self.store_sm().and_then(|bs| bs.expansion(macro_call)).or_else(|| {
|
||||||
@ -1288,7 +1288,7 @@ impl SourceAnalyzer {
|
|||||||
|
|
||||||
pub(crate) fn is_unsafe_macro_call_expr(
|
pub(crate) fn is_unsafe_macro_call_expr(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
macro_expr: InFile<&ast::MacroExpr>,
|
macro_expr: InFile<&ast::MacroExpr>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if let Some((def, body, sm, Some(infer))) = self.body_() {
|
if let Some((def, body, sm, Some(infer))) = self.body_() {
|
||||||
@ -1313,7 +1313,7 @@ impl SourceAnalyzer {
|
|||||||
|
|
||||||
pub(crate) fn resolve_offset_in_format_args(
|
pub(crate) fn resolve_offset_in_format_args(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
format_args: InFile<&ast::FormatArgsExpr>,
|
format_args: InFile<&ast::FormatArgsExpr>,
|
||||||
offset: TextSize,
|
offset: TextSize,
|
||||||
) -> Option<(TextRange, Option<PathResolution>)> {
|
) -> Option<(TextRange, Option<PathResolution>)> {
|
||||||
@ -1384,7 +1384,7 @@ impl SourceAnalyzer {
|
|||||||
|
|
||||||
fn resolve_impl_method_or_trait_def(
|
fn resolve_impl_method_or_trait_def(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
func: FunctionId,
|
func: FunctionId,
|
||||||
substs: Substitution,
|
substs: Substitution,
|
||||||
) -> FunctionId {
|
) -> FunctionId {
|
||||||
@ -1393,7 +1393,7 @@ impl SourceAnalyzer {
|
|||||||
|
|
||||||
fn resolve_impl_method_or_trait_def_with_subst(
|
fn resolve_impl_method_or_trait_def_with_subst(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
func: FunctionId,
|
func: FunctionId,
|
||||||
substs: Substitution,
|
substs: Substitution,
|
||||||
) -> (FunctionId, Substitution) {
|
) -> (FunctionId, Substitution) {
|
||||||
@ -1407,7 +1407,7 @@ impl SourceAnalyzer {
|
|||||||
|
|
||||||
fn resolve_impl_const_or_trait_def_with_subst(
|
fn resolve_impl_const_or_trait_def_with_subst(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
const_id: ConstId,
|
const_id: ConstId,
|
||||||
subs: Substitution,
|
subs: Substitution,
|
||||||
) -> (ConstId, Substitution) {
|
) -> (ConstId, Substitution) {
|
||||||
@ -1421,7 +1421,7 @@ impl SourceAnalyzer {
|
|||||||
|
|
||||||
fn lang_trait_fn(
|
fn lang_trait_fn(
|
||||||
&self,
|
&self,
|
||||||
db: &dyn HirDatabase,
|
db: &'db dyn HirDatabase,
|
||||||
lang_trait: LangItem,
|
lang_trait: LangItem,
|
||||||
method_name: &Name,
|
method_name: &Name,
|
||||||
) -> Option<(TraitId, FunctionId)> {
|
) -> Option<(TraitId, FunctionId)> {
|
||||||
@ -1527,7 +1527,7 @@ fn adjust(
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) fn resolve_hir_path(
|
pub(crate) fn resolve_hir_path(
|
||||||
db: &dyn HirDatabase,
|
db: &dyn HirDatabase,
|
||||||
resolver: &Resolver,
|
resolver: &Resolver<'_>,
|
||||||
path: &Path,
|
path: &Path,
|
||||||
hygiene: HygieneId,
|
hygiene: HygieneId,
|
||||||
store: Option<&ExpressionStore>,
|
store: Option<&ExpressionStore>,
|
||||||
@ -1538,7 +1538,7 @@ pub(crate) fn resolve_hir_path(
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) fn resolve_hir_path_as_attr_macro(
|
pub(crate) fn resolve_hir_path_as_attr_macro(
|
||||||
db: &dyn HirDatabase,
|
db: &dyn HirDatabase,
|
||||||
resolver: &Resolver,
|
resolver: &Resolver<'_>,
|
||||||
path: &Path,
|
path: &Path,
|
||||||
) -> Option<Macro> {
|
) -> Option<Macro> {
|
||||||
resolver
|
resolver
|
||||||
@ -1549,7 +1549,7 @@ pub(crate) fn resolve_hir_path_as_attr_macro(
|
|||||||
|
|
||||||
fn resolve_hir_path_(
|
fn resolve_hir_path_(
|
||||||
db: &dyn HirDatabase,
|
db: &dyn HirDatabase,
|
||||||
resolver: &Resolver,
|
resolver: &Resolver<'_>,
|
||||||
path: &Path,
|
path: &Path,
|
||||||
prefer_value_ns: bool,
|
prefer_value_ns: bool,
|
||||||
hygiene: HygieneId,
|
hygiene: HygieneId,
|
||||||
@ -1642,7 +1642,7 @@ fn resolve_hir_path_(
|
|||||||
|
|
||||||
fn resolve_hir_value_path(
|
fn resolve_hir_value_path(
|
||||||
db: &dyn HirDatabase,
|
db: &dyn HirDatabase,
|
||||||
resolver: &Resolver,
|
resolver: &Resolver<'_>,
|
||||||
body_owner: Option<DefWithBodyId>,
|
body_owner: Option<DefWithBodyId>,
|
||||||
path: &Path,
|
path: &Path,
|
||||||
hygiene: HygieneId,
|
hygiene: HygieneId,
|
||||||
@ -1680,7 +1680,7 @@ fn resolve_hir_value_path(
|
|||||||
/// then we know that `foo` in `my::foo::Bar` refers to the module, not the function.
|
/// then we know that `foo` in `my::foo::Bar` refers to the module, not the function.
|
||||||
fn resolve_hir_path_qualifier(
|
fn resolve_hir_path_qualifier(
|
||||||
db: &dyn HirDatabase,
|
db: &dyn HirDatabase,
|
||||||
resolver: &Resolver,
|
resolver: &Resolver<'_>,
|
||||||
path: &Path,
|
path: &Path,
|
||||||
store: &ExpressionStore,
|
store: &ExpressionStore,
|
||||||
) -> Option<PathResolution> {
|
) -> Option<PathResolution> {
|
||||||
|
@ -73,7 +73,7 @@ pub fn parallel_prime_caches(
|
|||||||
.send(ParallelPrimeCacheWorkerProgress::BeginCrate { crate_id, crate_name })?;
|
.send(ParallelPrimeCacheWorkerProgress::BeginCrate { crate_id, crate_name })?;
|
||||||
|
|
||||||
let cancelled = Cancelled::catch(|| match kind {
|
let cancelled = Cancelled::catch(|| match kind {
|
||||||
PrimingPhase::DefMap => _ = db.crate_def_map(crate_id),
|
PrimingPhase::DefMap => _ = hir::crate_def_map(&db, crate_id),
|
||||||
PrimingPhase::ImportMap => _ = db.import_map(crate_id),
|
PrimingPhase::ImportMap => _ = db.import_map(crate_id),
|
||||||
PrimingPhase::CrateSymbols => _ = db.crate_symbols(crate_id.into()),
|
PrimingPhase::CrateSymbols => _ = db.crate_symbols(crate_id.into()),
|
||||||
});
|
});
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
use std::iter;
|
use std::iter;
|
||||||
|
|
||||||
use hir::{DefMap, InFile, ModuleSource, db::DefDatabase};
|
use hir::crate_def_map;
|
||||||
|
use hir::{DefMap, InFile, ModuleSource};
|
||||||
use ide_db::base_db::RootQueryDb;
|
use ide_db::base_db::RootQueryDb;
|
||||||
use ide_db::text_edit::TextEdit;
|
use ide_db::text_edit::TextEdit;
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
@ -101,7 +102,8 @@ fn fixes(
|
|||||||
// check crate roots, i.e. main.rs, lib.rs, ...
|
// check crate roots, i.e. main.rs, lib.rs, ...
|
||||||
let relevant_crates = db.relevant_crates(file_id);
|
let relevant_crates = db.relevant_crates(file_id);
|
||||||
'crates: for &krate in &*relevant_crates {
|
'crates: for &krate in &*relevant_crates {
|
||||||
let crate_def_map = ctx.sema.db.crate_def_map(krate);
|
// FIXME: This shouldnt need to access the crate def map directly
|
||||||
|
let crate_def_map = crate_def_map(ctx.sema.db, krate);
|
||||||
|
|
||||||
let root_module = &crate_def_map[DefMap::ROOT];
|
let root_module = &crate_def_map[DefMap::ROOT];
|
||||||
let Some(root_file_id) = root_module.origin.file_id() else { continue };
|
let Some(root_file_id) = root_module.origin.file_id() else { continue };
|
||||||
@ -156,7 +158,7 @@ fn fixes(
|
|||||||
stack.pop();
|
stack.pop();
|
||||||
let relevant_crates = db.relevant_crates(parent_id);
|
let relevant_crates = db.relevant_crates(parent_id);
|
||||||
'crates: for &krate in relevant_crates.iter() {
|
'crates: for &krate in relevant_crates.iter() {
|
||||||
let crate_def_map = ctx.sema.db.crate_def_map(krate);
|
let crate_def_map = crate_def_map(ctx.sema.db, krate);
|
||||||
let Some((_, module)) = crate_def_map.modules().find(|(_, module)| {
|
let Some((_, module)) = crate_def_map.modules().find(|(_, module)| {
|
||||||
module.origin.file_id().map(|file_id| file_id.file_id(ctx.sema.db)) == Some(parent_id)
|
module.origin.file_id().map(|file_id| file_id.file_id(ctx.sema.db)) == Some(parent_id)
|
||||||
&& !module.origin.is_inline()
|
&& !module.origin.is_inline()
|
||||||
|
@ -62,7 +62,7 @@ use std::panic::{AssertUnwindSafe, UnwindSafe};
|
|||||||
|
|
||||||
use cfg::CfgOptions;
|
use cfg::CfgOptions;
|
||||||
use fetch_crates::CrateInfo;
|
use fetch_crates::CrateInfo;
|
||||||
use hir::{ChangeWithProcMacros, EditionedFileId, sym};
|
use hir::{ChangeWithProcMacros, EditionedFileId, crate_def_map, sym};
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
FxHashMap, FxIndexSet, LineIndexDatabase,
|
FxHashMap, FxIndexSet, LineIndexDatabase,
|
||||||
base_db::{
|
base_db::{
|
||||||
@ -627,7 +627,7 @@ impl Analysis {
|
|||||||
|
|
||||||
/// Returns true if this crate has `no_std` or `no_core` specified.
|
/// Returns true if this crate has `no_std` or `no_core` specified.
|
||||||
pub fn is_crate_no_std(&self, crate_id: Crate) -> Cancellable<bool> {
|
pub fn is_crate_no_std(&self, crate_id: Crate) -> Cancellable<bool> {
|
||||||
self.with_db(|db| hir::db::DefDatabase::crate_def_map(db, crate_id).is_no_std())
|
self.with_db(|db| crate_def_map(db, crate_id).is_no_std())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the root file of the given crate.
|
/// Returns the root file of the given crate.
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use hir::{Semantics, db::DefDatabase};
|
use hir::{Semantics, crate_def_map};
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
FileId, FilePosition, RootDatabase,
|
FileId, FilePosition, RootDatabase,
|
||||||
base_db::{Crate, RootQueryDb},
|
base_db::{Crate, RootQueryDb},
|
||||||
@ -58,7 +58,7 @@ pub(crate) fn crates_for(db: &RootDatabase, file_id: FileId) -> Vec<Crate> {
|
|||||||
.iter()
|
.iter()
|
||||||
.copied()
|
.copied()
|
||||||
.filter(|&crate_id| {
|
.filter(|&crate_id| {
|
||||||
db.crate_def_map(crate_id).modules_for_file(db, file_id).next().is_some()
|
crate_def_map(db, crate_id).modules_for_file(db, file_id).next().is_some()
|
||||||
})
|
})
|
||||||
.sorted()
|
.sorted()
|
||||||
.collect()
|
.collect()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user