This commit is contained in:
Lukas Wirth 2021-08-16 18:29:16 +02:00
parent 0336e9b25f
commit 6523a09562
2 changed files with 14 additions and 14 deletions

View File

@ -20,17 +20,17 @@
pub trait ChildBySource { pub trait ChildBySource {
fn child_by_source(&self, db: &dyn DefDatabase, file_id: HirFileId) -> DynMap { fn child_by_source(&self, db: &dyn DefDatabase, file_id: HirFileId) -> DynMap {
let mut res = DynMap::default(); let mut res = DynMap::default();
self.child_by_source_to(db, file_id, &mut res); self.child_by_source_to(db, &mut res, file_id);
res res
} }
fn child_by_source_to(&self, db: &dyn DefDatabase, file_id: HirFileId, map: &mut DynMap); fn child_by_source_to(&self, db: &dyn DefDatabase, map: &mut DynMap, file_id: HirFileId);
} }
impl ChildBySource for TraitId { impl ChildBySource for TraitId {
fn child_by_source_to(&self, db: &dyn DefDatabase, file_id: HirFileId, res: &mut DynMap) { fn child_by_source_to(&self, db: &dyn DefDatabase, res: &mut DynMap, file_id: HirFileId) {
let data = db.trait_data(*self); let data = db.trait_data(*self);
for &(_, item) in data.items.iter() { for (_name, item) in data.items.iter() {
match item { match *item {
AssocItemId::FunctionId(func) => { AssocItemId::FunctionId(func) => {
let loc = func.lookup(db); let loc = func.lookup(db);
if loc.id.file_id() == file_id { if loc.id.file_id() == file_id {
@ -58,7 +58,7 @@ fn child_by_source_to(&self, db: &dyn DefDatabase, file_id: HirFileId, res: &mut
} }
impl ChildBySource for ImplId { impl ChildBySource for ImplId {
fn child_by_source_to(&self, db: &dyn DefDatabase, file_id: HirFileId, res: &mut DynMap) { fn child_by_source_to(&self, db: &dyn DefDatabase, res: &mut DynMap, file_id: HirFileId) {
let data = db.impl_data(*self); let data = db.impl_data(*self);
for &item in data.items.iter() { for &item in data.items.iter() {
match item { match item {
@ -89,15 +89,15 @@ fn child_by_source_to(&self, db: &dyn DefDatabase, file_id: HirFileId, res: &mut
} }
impl ChildBySource for ModuleId { impl ChildBySource for ModuleId {
fn child_by_source_to(&self, db: &dyn DefDatabase, file_id: HirFileId, res: &mut DynMap) { fn child_by_source_to(&self, db: &dyn DefDatabase, res: &mut DynMap, file_id: HirFileId) {
let def_map = self.def_map(db); let def_map = self.def_map(db);
let module_data = &def_map[self.local_id]; let module_data = &def_map[self.local_id];
module_data.scope.child_by_source_to(db, file_id, res); module_data.scope.child_by_source_to(db, res, file_id);
} }
} }
impl ChildBySource for ItemScope { impl ChildBySource for ItemScope {
fn child_by_source_to(&self, db: &dyn DefDatabase, file_id: HirFileId, res: &mut DynMap) { fn child_by_source_to(&self, db: &dyn DefDatabase, res: &mut DynMap, file_id: HirFileId) {
self.declarations().for_each(|item| add_module_def(db, file_id, res, item)); self.declarations().for_each(|item| add_module_def(db, file_id, res, item));
self.unnamed_consts().for_each(|konst| { self.unnamed_consts().for_each(|konst| {
let src = konst.lookup(db).source(db); let src = konst.lookup(db).source(db);
@ -188,7 +188,7 @@ fn add_impl(db: &dyn DefDatabase, file_id: HirFileId, map: &mut DynMap, imp: Imp
} }
impl ChildBySource for VariantId { impl ChildBySource for VariantId {
fn child_by_source_to(&self, db: &dyn DefDatabase, _: HirFileId, res: &mut DynMap) { fn child_by_source_to(&self, db: &dyn DefDatabase, res: &mut DynMap, _: HirFileId) {
let arena_map = self.child_source(db); let arena_map = self.child_source(db);
let arena_map = arena_map.as_ref(); let arena_map = arena_map.as_ref();
let parent = *self; let parent = *self;
@ -207,7 +207,7 @@ fn child_by_source_to(&self, db: &dyn DefDatabase, _: HirFileId, res: &mut DynMa
} }
impl ChildBySource for EnumId { impl ChildBySource for EnumId {
fn child_by_source_to(&self, db: &dyn DefDatabase, _: HirFileId, res: &mut DynMap) { fn child_by_source_to(&self, db: &dyn DefDatabase, res: &mut DynMap, _: HirFileId) {
let arena_map = self.child_source(db); let arena_map = self.child_source(db);
let arena_map = arena_map.as_ref(); let arena_map = arena_map.as_ref();
for (local_id, source) in arena_map.value.iter() { for (local_id, source) in arena_map.value.iter() {
@ -218,12 +218,12 @@ fn child_by_source_to(&self, db: &dyn DefDatabase, _: HirFileId, res: &mut DynMa
} }
impl ChildBySource for DefWithBodyId { impl ChildBySource for DefWithBodyId {
fn child_by_source_to(&self, db: &dyn DefDatabase, file_id: HirFileId, res: &mut DynMap) { fn child_by_source_to(&self, db: &dyn DefDatabase, res: &mut DynMap, file_id: HirFileId) {
let body = db.body(*self); let body = db.body(*self);
for (_, def_map) in body.blocks(db) { for (_, def_map) in body.blocks(db) {
// All block expressions are merged into the same map, because they logically all add // All block expressions are merged into the same map, because they logically all add
// inner items to the containing `DefWithBodyId`. // inner items to the containing `DefWithBodyId`.
def_map[def_map.root()].scope.child_by_source_to(db, file_id, res); def_map[def_map.root()].scope.child_by_source_to(db, res, file_id);
} }
} }
} }

View File

@ -438,7 +438,7 @@ fn child_source(
} }
impl ChildBySource for GenericDefId { impl ChildBySource for GenericDefId {
fn child_by_source_to(&self, db: &dyn DefDatabase, _: HirFileId, res: &mut DynMap) { fn child_by_source_to(&self, db: &dyn DefDatabase, res: &mut DynMap, _: HirFileId) {
let (_, sm) = GenericParams::new(db, *self); let (_, sm) = GenericParams::new(db, *self);
let sm = sm.as_ref(); let sm = sm.as_ref();