mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-28 10:39:45 +00:00
Preserve impl assoc names in ImplData
This commit is contained in:
parent
76c1a376c3
commit
0480ebef75
10 changed files with 78 additions and 89 deletions
|
|
@ -775,29 +775,16 @@ impl Module {
|
|||
AssocItemId::ConstId(id) => !db.const_data(id).has_body,
|
||||
AssocItemId::TypeAliasId(it) => db.type_alias_data(it).type_ref.is_none(),
|
||||
});
|
||||
impl_assoc_items_scratch.extend(db.impl_data(impl_def.id).items.iter().filter_map(
|
||||
|&item| {
|
||||
Some((
|
||||
item,
|
||||
match item {
|
||||
AssocItemId::FunctionId(it) => db.function_data(it).name.clone(),
|
||||
AssocItemId::ConstId(it) => {
|
||||
db.const_data(it).name.as_ref()?.clone()
|
||||
}
|
||||
AssocItemId::TypeAliasId(it) => db.type_alias_data(it).name.clone(),
|
||||
},
|
||||
))
|
||||
},
|
||||
));
|
||||
impl_assoc_items_scratch.extend(db.impl_data(impl_def.id).items.iter().cloned());
|
||||
|
||||
let redundant = impl_assoc_items_scratch
|
||||
.iter()
|
||||
.filter(|(id, name)| {
|
||||
.filter(|(name, id)| {
|
||||
!items.iter().any(|(impl_name, impl_item)| {
|
||||
discriminant(impl_item) == discriminant(id) && impl_name == name
|
||||
})
|
||||
})
|
||||
.map(|(item, name)| (name.clone(), AssocItem::from(*item)));
|
||||
.map(|(name, item)| (name.clone(), AssocItem::from(*item)));
|
||||
for (name, assoc_item) in redundant {
|
||||
acc.push(
|
||||
TraitImplRedundantAssocItems {
|
||||
|
|
@ -812,7 +799,7 @@ impl Module {
|
|||
|
||||
let missing: Vec<_> = required_items
|
||||
.filter(|(name, id)| {
|
||||
!impl_assoc_items_scratch.iter().any(|(impl_item, impl_name)| {
|
||||
!impl_assoc_items_scratch.iter().any(|(impl_name, impl_item)| {
|
||||
discriminant(impl_item) == discriminant(id) && impl_name == name
|
||||
})
|
||||
})
|
||||
|
|
@ -844,7 +831,7 @@ impl Module {
|
|||
source_map,
|
||||
);
|
||||
|
||||
for &item in db.impl_data(impl_def.id).items.iter() {
|
||||
for &(_, item) in db.impl_data(impl_def.id).items.iter() {
|
||||
AssocItem::from(item).diagnostics(db, acc, style_lints);
|
||||
}
|
||||
}
|
||||
|
|
@ -4307,7 +4294,7 @@ impl Impl {
|
|||
}
|
||||
|
||||
pub fn items(self, db: &dyn HirDatabase) -> Vec<AssocItem> {
|
||||
db.impl_data(self.id).items.iter().map(|&it| it.into()).collect()
|
||||
db.impl_data(self.id).items.iter().map(|&(_, it)| it.into()).collect()
|
||||
}
|
||||
|
||||
pub fn is_negative(self, db: &dyn HirDatabase) -> bool {
|
||||
|
|
@ -5165,7 +5152,7 @@ impl Type {
|
|||
let impls = db.inherent_impls_in_crate(krate);
|
||||
|
||||
for impl_def in impls.for_self_ty(&self.ty) {
|
||||
for &item in db.impl_data(*impl_def).items.iter() {
|
||||
for &(_, item) in db.impl_data(*impl_def).items.iter() {
|
||||
if callback(item) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ impl ChildBySource for ImplId {
|
|||
res[keys::ATTR_MACRO_CALL].insert(ast_id.to_ptr(db.upcast()), call_id);
|
||||
},
|
||||
);
|
||||
data.items.iter().for_each(|&item| {
|
||||
data.items.iter().for_each(|&(_, item)| {
|
||||
add_assoc_item(db, res, file_id, item);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ use hir_ty::{
|
|||
db::HirDatabase,
|
||||
display::{hir_display_with_types_map, HirDisplay},
|
||||
};
|
||||
use intern::Symbol;
|
||||
use rustc_hash::FxHashMap;
|
||||
use span::Edition;
|
||||
use syntax::{ast::HasName, AstNode, AstPtr, SmolStr, SyntaxNode, SyntaxNodePtr, ToSmolStr};
|
||||
|
|
@ -27,7 +28,7 @@ pub type FxIndexSet<T> = indexmap::IndexSet<T, std::hash::BuildHasherDefault<rus
|
|||
/// possible.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct FileSymbol {
|
||||
pub name: SmolStr,
|
||||
pub name: Symbol,
|
||||
pub def: ModuleDef,
|
||||
pub loc: DeclarationLocation,
|
||||
pub container_name: Option<SmolStr>,
|
||||
|
|
@ -110,38 +111,38 @@ impl<'a> SymbolCollector<'a> {
|
|||
}
|
||||
|
||||
fn collect_from_module(&mut self, module_id: ModuleId) {
|
||||
let push_decl = |this: &mut Self, def| {
|
||||
let push_decl = |this: &mut Self, def, name| {
|
||||
match def {
|
||||
ModuleDefId::ModuleId(id) => this.push_module(id),
|
||||
ModuleDefId::ModuleId(id) => this.push_module(id, name),
|
||||
ModuleDefId::FunctionId(id) => {
|
||||
this.push_decl(id, false);
|
||||
this.push_decl(id, name, false);
|
||||
this.collect_from_body(id);
|
||||
}
|
||||
ModuleDefId::AdtId(AdtId::StructId(id)) => this.push_decl(id, false),
|
||||
ModuleDefId::AdtId(AdtId::EnumId(id)) => this.push_decl(id, false),
|
||||
ModuleDefId::AdtId(AdtId::UnionId(id)) => this.push_decl(id, false),
|
||||
ModuleDefId::AdtId(AdtId::StructId(id)) => this.push_decl(id, name, false),
|
||||
ModuleDefId::AdtId(AdtId::EnumId(id)) => this.push_decl(id, name, false),
|
||||
ModuleDefId::AdtId(AdtId::UnionId(id)) => this.push_decl(id, name, false),
|
||||
ModuleDefId::ConstId(id) => {
|
||||
this.push_decl(id, false);
|
||||
this.push_decl(id, name, false);
|
||||
this.collect_from_body(id);
|
||||
}
|
||||
ModuleDefId::StaticId(id) => {
|
||||
this.push_decl(id, false);
|
||||
this.push_decl(id, name, false);
|
||||
this.collect_from_body(id);
|
||||
}
|
||||
ModuleDefId::TraitId(id) => {
|
||||
this.push_decl(id, false);
|
||||
this.push_decl(id, name, false);
|
||||
this.collect_from_trait(id);
|
||||
}
|
||||
ModuleDefId::TraitAliasId(id) => {
|
||||
this.push_decl(id, false);
|
||||
this.push_decl(id, name, false);
|
||||
}
|
||||
ModuleDefId::TypeAliasId(id) => {
|
||||
this.push_decl(id, false);
|
||||
this.push_decl(id, name, false);
|
||||
}
|
||||
ModuleDefId::MacroId(id) => match id {
|
||||
MacroId::Macro2Id(id) => this.push_decl(id, false),
|
||||
MacroId::MacroRulesId(id) => this.push_decl(id, false),
|
||||
MacroId::ProcMacroId(id) => this.push_decl(id, false),
|
||||
MacroId::Macro2Id(id) => this.push_decl(id, name, false),
|
||||
MacroId::MacroRulesId(id) => this.push_decl(id, name, false),
|
||||
MacroId::ProcMacroId(id) => this.push_decl(id, name, false),
|
||||
},
|
||||
// Don't index these.
|
||||
ModuleDefId::BuiltinType(_) => {}
|
||||
|
|
@ -172,7 +173,7 @@ impl<'a> SymbolCollector<'a> {
|
|||
name_ptr,
|
||||
};
|
||||
this.symbols.insert(FileSymbol {
|
||||
name: name.as_str().into(),
|
||||
name: name.symbol().clone(),
|
||||
def: def.into(),
|
||||
container_name: this.current_container_name.clone(),
|
||||
loc: dec_loc,
|
||||
|
|
@ -201,7 +202,7 @@ impl<'a> SymbolCollector<'a> {
|
|||
name_ptr,
|
||||
};
|
||||
this.symbols.insert(FileSymbol {
|
||||
name: name.as_str().into(),
|
||||
name: name.symbol().clone(),
|
||||
def: def.into(),
|
||||
container_name: this.current_container_name.clone(),
|
||||
loc: dec_loc,
|
||||
|
|
@ -242,7 +243,7 @@ impl<'a> SymbolCollector<'a> {
|
|||
continue;
|
||||
}
|
||||
// self is a declaration
|
||||
push_decl(self, def)
|
||||
push_decl(self, def, name)
|
||||
}
|
||||
|
||||
for (name, Item { def, vis, import }) in scope.macros() {
|
||||
|
|
@ -253,7 +254,7 @@ impl<'a> SymbolCollector<'a> {
|
|||
continue;
|
||||
}
|
||||
// self is a declaration
|
||||
push_decl(self, def.into())
|
||||
push_decl(self, def.into(), name)
|
||||
}
|
||||
|
||||
for (name, Item { def, vis, import }) in scope.values() {
|
||||
|
|
@ -264,20 +265,20 @@ impl<'a> SymbolCollector<'a> {
|
|||
continue;
|
||||
}
|
||||
// self is a declaration
|
||||
push_decl(self, def)
|
||||
push_decl(self, def, name)
|
||||
}
|
||||
|
||||
for const_id in scope.unnamed_consts() {
|
||||
self.collect_from_body(const_id);
|
||||
}
|
||||
|
||||
for (_, id) in scope.legacy_macros() {
|
||||
for (name, id) in scope.legacy_macros() {
|
||||
for &id in id {
|
||||
if id.module(self.db.upcast()) == module_id {
|
||||
match id {
|
||||
MacroId::Macro2Id(id) => self.push_decl(id, false),
|
||||
MacroId::MacroRulesId(id) => self.push_decl(id, false),
|
||||
MacroId::ProcMacroId(id) => self.push_decl(id, false),
|
||||
MacroId::Macro2Id(id) => self.push_decl(id, name, false),
|
||||
MacroId::MacroRulesId(id) => self.push_decl(id, name, false),
|
||||
MacroId::ProcMacroId(id) => self.push_decl(id, name, false),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -307,8 +308,8 @@ impl<'a> SymbolCollector<'a> {
|
|||
.to_smolstr(),
|
||||
);
|
||||
self.with_container_name(impl_name, |s| {
|
||||
for &assoc_item_id in impl_data.items.iter() {
|
||||
s.push_assoc_item(assoc_item_id)
|
||||
for &(ref name, assoc_item_id) in &impl_data.items {
|
||||
s.push_assoc_item(assoc_item_id, name)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -316,8 +317,8 @@ impl<'a> SymbolCollector<'a> {
|
|||
fn collect_from_trait(&mut self, trait_id: TraitId) {
|
||||
let trait_data = self.db.trait_data(trait_id);
|
||||
self.with_container_name(Some(trait_data.name.as_str().into()), |s| {
|
||||
for &(_, assoc_item_id) in &trait_data.items {
|
||||
s.push_assoc_item(assoc_item_id);
|
||||
for &(ref name, assoc_item_id) in &trait_data.items {
|
||||
s.push_assoc_item(assoc_item_id, name);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -350,15 +351,15 @@ impl<'a> SymbolCollector<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn push_assoc_item(&mut self, assoc_item_id: AssocItemId) {
|
||||
fn push_assoc_item(&mut self, assoc_item_id: AssocItemId, name: &Name) {
|
||||
match assoc_item_id {
|
||||
AssocItemId::FunctionId(id) => self.push_decl(id, true),
|
||||
AssocItemId::ConstId(id) => self.push_decl(id, true),
|
||||
AssocItemId::TypeAliasId(id) => self.push_decl(id, true),
|
||||
AssocItemId::FunctionId(id) => self.push_decl(id, name, true),
|
||||
AssocItemId::ConstId(id) => self.push_decl(id, name, true),
|
||||
AssocItemId::TypeAliasId(id) => self.push_decl(id, name, true),
|
||||
}
|
||||
}
|
||||
|
||||
fn push_decl<'db, L>(&mut self, id: L, is_assoc: bool)
|
||||
fn push_decl<'db, L>(&mut self, id: L, name: &Name, is_assoc: bool)
|
||||
where
|
||||
L: Lookup<Database<'db> = dyn DefDatabase + 'db> + Into<ModuleDefId>,
|
||||
<L as Lookup>::Data: HasSource,
|
||||
|
|
@ -377,7 +378,7 @@ impl<'a> SymbolCollector<'a> {
|
|||
if let Some(attrs) = def.attrs(self.db) {
|
||||
for alias in attrs.doc_aliases() {
|
||||
self.symbols.insert(FileSymbol {
|
||||
name: alias.as_str().into(),
|
||||
name: alias.clone(),
|
||||
def,
|
||||
loc: dec_loc.clone(),
|
||||
container_name: self.current_container_name.clone(),
|
||||
|
|
@ -388,7 +389,7 @@ impl<'a> SymbolCollector<'a> {
|
|||
}
|
||||
|
||||
self.symbols.insert(FileSymbol {
|
||||
name: name_node.text().into(),
|
||||
name: name.symbol().clone(),
|
||||
def,
|
||||
container_name: self.current_container_name.clone(),
|
||||
loc: dec_loc,
|
||||
|
|
@ -397,7 +398,7 @@ impl<'a> SymbolCollector<'a> {
|
|||
});
|
||||
}
|
||||
|
||||
fn push_module(&mut self, module_id: ModuleId) {
|
||||
fn push_module(&mut self, module_id: ModuleId, name: &Name) {
|
||||
let def_map = module_id.def_map(self.db.upcast());
|
||||
let module_data = &def_map[module_id.local_id];
|
||||
let Some(declaration) = module_data.origin.declaration() else { return };
|
||||
|
|
@ -414,7 +415,7 @@ impl<'a> SymbolCollector<'a> {
|
|||
if let Some(attrs) = def.attrs(self.db) {
|
||||
for alias in attrs.doc_aliases() {
|
||||
self.symbols.insert(FileSymbol {
|
||||
name: alias.as_str().into(),
|
||||
name: alias.clone(),
|
||||
def,
|
||||
loc: dec_loc.clone(),
|
||||
container_name: self.current_container_name.clone(),
|
||||
|
|
@ -425,7 +426,7 @@ impl<'a> SymbolCollector<'a> {
|
|||
}
|
||||
|
||||
self.symbols.insert(FileSymbol {
|
||||
name: name_node.text().into(),
|
||||
name: name.symbol().clone(),
|
||||
def: ModuleDef::Module(module_id.into()),
|
||||
container_name: self.current_container_name.clone(),
|
||||
loc: dec_loc,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue