Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/data.rs')
| -rw-r--r-- | crates/hir-def/src/data.rs | 52 |
1 files changed, 41 insertions, 11 deletions
diff --git a/crates/hir-def/src/data.rs b/crates/hir-def/src/data.rs index f2d8318f7d..bb2e9a5b29 100644 --- a/crates/hir-def/src/data.rs +++ b/crates/hir-def/src/data.rs @@ -15,8 +15,8 @@ use crate::{ type_ref::{TraitRef, TypeBound, TypeRef}, visibility::RawVisibility, AssocItemId, AstIdWithPath, ConstId, ConstLoc, FunctionId, FunctionLoc, HasModule, ImplId, - Intern, ItemContainerId, Lookup, Macro2Id, MacroRulesId, ModuleId, ProcMacroId, StaticId, - TraitId, TypeAliasId, TypeAliasLoc, + InheritedVisibilityLoc, Intern, ItemContainerId, Lookup, Macro2Id, MacroRulesId, ModuleId, + ProcMacroId, StaticId, TraitId, TypeAliasId, TypeAliasLoc, }; #[derive(Debug, Clone, PartialEq, Eq)] @@ -41,6 +41,12 @@ impl FunctionData { let item_tree = loc.id.item_tree(db); let func = &item_tree[loc.id.value]; + let visibility = if let Some(inherited_vis) = loc.inherited_visibility { + inherited_vis.tree_id.item_tree(db)[inherited_vis.raw_visibility_id].clone() + } else { + item_tree[func.visibility].clone() + }; + let enabled_params = func .params .clone() @@ -93,7 +99,7 @@ impl FunctionData { ret_type: func.ret_type.clone(), async_ret_type: func.async_ret_type.clone(), attrs: item_tree.attrs(db, krate, ModItem::from(loc.id.value).into()), - visibility: item_tree[func.visibility].clone(), + visibility, abi: func.abi.clone(), legacy_const_generics_indices, flags, @@ -171,11 +177,16 @@ impl TypeAliasData { let loc = typ.lookup(db); let item_tree = loc.id.item_tree(db); let typ = &item_tree[loc.id.value]; + let visibility = if let Some(inherited_vis) = loc.inherited_visibility { + inherited_vis.tree_id.item_tree(db)[inherited_vis.raw_visibility_id].clone() + } else { + item_tree[typ.visibility].clone() + }; Arc::new(TypeAliasData { name: typ.name.clone(), type_ref: typ.type_ref.clone(), - visibility: item_tree[typ.visibility].clone(), + visibility, is_extern: matches!(loc.container, ItemContainerId::ExternBlockId(_)), bounds: typ.bounds.to_vec(), }) @@ -221,6 +232,7 @@ impl TraitData { module_id, tr_loc.id.file_id(), ItemContainerId::TraitId(tr), + Some(InheritedVisibilityLoc::new(tr_def.visibility, tr_loc.id.tree_id())), ); collector.collect(tr_loc.id.tree_id(), &tr_def.items); @@ -288,6 +300,7 @@ impl ImplData { module_id, impl_loc.id.file_id(), ItemContainerId::ImplId(id), + None, ); collector.collect(impl_loc.id.tree_id(), &impl_def.items); @@ -385,11 +398,16 @@ impl ConstData { let loc = konst.lookup(db); let item_tree = loc.id.item_tree(db); let konst = &item_tree[loc.id.value]; + let visibility = if let Some(inherited_vis) = loc.inherited_visibility { + inherited_vis.tree_id.item_tree(db)[inherited_vis.raw_visibility_id].clone() + } else { + item_tree[konst.visibility].clone() + }; Arc::new(ConstData { name: konst.name.clone(), type_ref: konst.type_ref.clone(), - visibility: item_tree[konst.visibility].clone(), + visibility, }) } } @@ -428,6 +446,8 @@ struct AssocItemCollector<'a> { items: Vec<(Name, AssocItemId)>, attr_calls: Vec<(AstId<ast::Item>, MacroCallId)>, + + inherited_visibility: Option<InheritedVisibilityLoc>, } impl<'a> AssocItemCollector<'a> { @@ -436,6 +456,7 @@ impl<'a> AssocItemCollector<'a> { module_id: ModuleId, file_id: HirFileId, container: ItemContainerId, + inherited_visibility: Option<InheritedVisibilityLoc>, ) -> Self { Self { db, @@ -446,6 +467,8 @@ impl<'a> AssocItemCollector<'a> { items: Vec::new(), attr_calls: Vec::new(), + + inherited_visibility, } } @@ -488,9 +511,12 @@ impl<'a> AssocItemCollector<'a> { match item { AssocItem::Function(id) => { let item = &item_tree[id]; - let def = - FunctionLoc { container: self.container, id: ItemTreeId::new(tree_id, id) } - .intern(self.db); + let def = FunctionLoc { + container: self.container, + id: ItemTreeId::new(tree_id, id), + inherited_visibility: self.inherited_visibility, + } + .intern(self.db); self.items.push((item.name.clone(), def.into())); } AssocItem::Const(id) => { @@ -499,9 +525,12 @@ impl<'a> AssocItemCollector<'a> { Some(name) => name, None => continue, }; - let def = - ConstLoc { container: self.container, id: ItemTreeId::new(tree_id, id) } - .intern(self.db); + let def = ConstLoc { + container: self.container, + id: ItemTreeId::new(tree_id, id), + inherited_visibility: self.inherited_visibility, + } + .intern(self.db); self.items.push((name, def.into())); } AssocItem::TypeAlias(id) => { @@ -509,6 +538,7 @@ impl<'a> AssocItemCollector<'a> { let def = TypeAliasLoc { container: self.container, id: ItemTreeId::new(tree_id, id), + inherited_visibility: self.inherited_visibility, } .intern(self.db); self.items.push((item.name.clone(), def.into())); |