Skip to content

Commit 04e9349

Browse files
committed
Auto merge of #12198 - jonas-schievink:ide-resolve-supertrait-assoc-types, r=jonas-schievink
fix: Resolve assoc. types of supertraits in the IDE layer Fixes #12166
2 parents c42cb9a + 7e45915 commit 04e9349

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

crates/hir/src/lib.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use hir_def::{
5454
};
5555
use hir_expand::{name::name, MacroCallKind};
5656
use hir_ty::{
57-
autoderef,
57+
all_super_traits, autoderef,
5858
consteval::{unknown_const_as_generic, ComputedExpr, ConstEvalError, ConstExt},
5959
diagnostics::BodyValidationDiagnostic,
6060
method_resolution::{self, TyFingerprint},
@@ -1676,6 +1676,11 @@ impl Trait {
16761676
db.trait_data(self.id).items.iter().map(|(_name, it)| (*it).into()).collect()
16771677
}
16781678

1679+
pub fn items_with_supertraits(self, db: &dyn HirDatabase) -> Vec<AssocItem> {
1680+
let traits = all_super_traits(db.upcast(), self.into());
1681+
traits.iter().flat_map(|tr| Trait::from(*tr).items(db)).collect()
1682+
}
1683+
16791684
pub fn is_auto(self, db: &dyn HirDatabase) -> bool {
16801685
db.trait_data(self.id).is_auto
16811686
}

crates/ide-db/src/defs.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,8 @@ impl NameRefClass {
386386
let containing_path = name_ref.syntax().ancestors().find_map(ast::Path::cast)?;
387387
let resolved = sema.resolve_path(&containing_path)?;
388388
if let PathResolution::Def(ModuleDef::Trait(tr)) = resolved {
389-
// FIXME: resolve in supertraits
390389
if let Some(ty) = tr
391-
.items(sema.db)
390+
.items_with_supertraits(sema.db)
392391
.iter()
393392
.filter_map(|&assoc| match assoc {
394393
hir::AssocItem::TypeAlias(it) => Some(it),

crates/ide/src/goto_definition.rs

+16
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,22 @@ fn f() -> impl Iterator<Item$0 = u8> {}
10121012
);
10131013
}
10141014

1015+
#[test]
1016+
fn goto_def_for_super_assoc_ty_in_path() {
1017+
check(
1018+
r#"
1019+
trait Super {
1020+
type Item;
1021+
//^^^^
1022+
}
1023+
1024+
trait Sub: Super {}
1025+
1026+
fn f() -> impl Sub<Item$0 = u8> {}
1027+
"#,
1028+
);
1029+
}
1030+
10151031
#[test]
10161032
fn unknown_assoc_ty() {
10171033
check_unresolved(

0 commit comments

Comments
 (0)