From 41c7448e1242de8fadf7c46efd3171368b5ff92e Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 30 Mar 2021 02:08:33 +0200 Subject: Accurately classify assoc. types in paths --- crates/ide_db/src/defs.rs | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'crates/ide_db') diff --git a/crates/ide_db/src/defs.rs b/crates/ide_db/src/defs.rs index 0d9808d24..de0dc2a40 100644 --- a/crates/ide_db/src/defs.rs +++ b/crates/ide_db/src/defs.rs @@ -330,25 +330,30 @@ impl NameRefClass { } } - if ast::AssocTypeArg::cast(parent.clone()).is_some() { - // `Trait` - // ^^^^^ - let path = name_ref.syntax().ancestors().find_map(ast::Path::cast)?; - let resolved = sema.resolve_path(&path)?; - if let PathResolution::Def(ModuleDef::Trait(tr)) = resolved { - if let Some(ty) = tr - .items(sema.db) - .iter() - .filter_map(|assoc| match assoc { - hir::AssocItem::TypeAlias(it) => Some(*it), - _ => None, - }) - .find(|alias| &alias.name(sema.db).to_string() == &name_ref.text()) - { - return Some(NameRefClass::Definition(Definition::ModuleDef( - ModuleDef::TypeAlias(ty), - ))); + if let Some(assoc_type_arg) = ast::AssocTypeArg::cast(parent.clone()) { + if assoc_type_arg.name_ref().as_ref() == Some(name_ref) { + // `Trait` + // ^^^^^ + let path = name_ref.syntax().ancestors().find_map(ast::Path::cast)?; + let resolved = sema.resolve_path(&path)?; + if let PathResolution::Def(ModuleDef::Trait(tr)) = resolved { + // FIXME: resolve in supertraits + if let Some(ty) = tr + .items(sema.db) + .iter() + .filter_map(|assoc| match assoc { + hir::AssocItem::TypeAlias(it) => Some(*it), + _ => None, + }) + .find(|alias| &alias.name(sema.db).to_string() == &name_ref.text()) + { + return Some(NameRefClass::Definition(Definition::ModuleDef( + ModuleDef::TypeAlias(ty), + ))); + } } + + return None; } } -- cgit v1.2.3