diff options
| -rw-r--r-- | crates/hir/src/lib.rs | 7 | ||||
| -rw-r--r-- | crates/ide-db/src/defs.rs | 3 | ||||
| -rw-r--r-- | crates/ide/src/goto_definition.rs | 16 |
3 files changed, 23 insertions, 3 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 496b4168c02..39f88937d6e 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -54,7 +54,7 @@ use hir_def::{ }; use hir_expand::{name::name, MacroCallKind}; use hir_ty::{ - autoderef, + all_super_traits, autoderef, consteval::{unknown_const_as_generic, ComputedExpr, ConstEvalError, ConstExt}, diagnostics::BodyValidationDiagnostic, method_resolution::{self, TyFingerprint}, @@ -1676,6 +1676,11 @@ impl Trait { db.trait_data(self.id).items.iter().map(|(_name, it)| (*it).into()).collect() } + pub fn items_with_supertraits(self, db: &dyn HirDatabase) -> Vec<AssocItem> { + let traits = all_super_traits(db.upcast(), self.into()); + traits.iter().flat_map(|tr| Trait::from(*tr).items(db)).collect() + } + pub fn is_auto(self, db: &dyn HirDatabase) -> bool { db.trait_data(self.id).is_auto } diff --git a/crates/ide-db/src/defs.rs b/crates/ide-db/src/defs.rs index 34b557e21ea..bea6f24523d 100644 --- a/crates/ide-db/src/defs.rs +++ b/crates/ide-db/src/defs.rs @@ -386,9 +386,8 @@ impl NameRefClass { let containing_path = name_ref.syntax().ancestors().find_map(ast::Path::cast)?; let resolved = sema.resolve_path(&containing_path)?; if let PathResolution::Def(ModuleDef::Trait(tr)) = resolved { - // FIXME: resolve in supertraits if let Some(ty) = tr - .items(sema.db) + .items_with_supertraits(sema.db) .iter() .filter_map(|&assoc| match assoc { hir::AssocItem::TypeAlias(it) => Some(it), diff --git a/crates/ide/src/goto_definition.rs b/crates/ide/src/goto_definition.rs index 3d22ed9c167..30f48819e6b 100644 --- a/crates/ide/src/goto_definition.rs +++ b/crates/ide/src/goto_definition.rs @@ -1013,6 +1013,22 @@ fn f() -> impl Iterator<Item$0 = u8> {} } #[test] + fn goto_def_for_super_assoc_ty_in_path() { + check( + r#" +trait Super { + type Item; + //^^^^ +} + +trait Sub: Super {} + +fn f() -> impl Sub<Item$0 = u8> {} +"#, + ); + } + + #[test] fn unknown_assoc_ty() { check_unresolved( r#" |
