5311: Fix goto definition for type alias type parameters r=matklad a=matklad

closes https://github.com/rust-analyzer/rust-analyzer/issues/5042



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-07-11 10:46:25 +00:00 committed by GitHub
commit ba48c6548c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 0 deletions

View file

@ -485,6 +485,7 @@ impl<'db> SemanticsImpl<'db> {
ChildContainer::ModuleId(it) => it.resolver(self.db.upcast()),
ChildContainer::EnumId(it) => it.resolver(self.db.upcast()),
ChildContainer::VariantId(it) => it.resolver(self.db.upcast()),
ChildContainer::TypeAliasId(it) => it.resolver(self.db.upcast()),
ChildContainer::GenericDefId(it) => it.resolver(self.db.upcast()),
};
SourceAnalyzer::new_for_resolver(resolver, src)

View file

@ -194,6 +194,10 @@ impl SourceToDefCtx<'_, '_> {
let def = self.const_to_def(container.with_value(it))?;
DefWithBodyId::from(def).into()
},
ast::TypeAliasDef(it) => {
let def = self.type_alias_to_def(container.with_value(it))?;
def.into()
},
_ => continue,
}
};
@ -246,6 +250,7 @@ pub(crate) enum ChildContainer {
ImplId(ImplId),
EnumId(EnumId),
VariantId(VariantId),
TypeAliasId(TypeAliasId),
/// XXX: this might be the same def as, for example an `EnumId`. However,
/// here the children generic parameters, and not, eg enum variants.
GenericDefId(GenericDefId),
@ -258,6 +263,7 @@ impl_froms! {
ImplId,
EnumId,
VariantId,
TypeAliasId,
GenericDefId
}
@ -271,6 +277,7 @@ impl ChildContainer {
ChildContainer::ImplId(it) => it.child_by_source(db),
ChildContainer::EnumId(it) => it.child_by_source(db),
ChildContainer::VariantId(it) => it.child_by_source(db),
ChildContainer::TypeAliasId(_) => DynMap::default(),
ChildContainer::GenericDefId(it) => it.child_by_source(db),
}
}

View file

@ -856,4 +856,14 @@ impl Foo {
"#,
);
}
#[test]
fn goto_def_for_type_alias_generic_parameter() {
check(
r#"
type Alias<T> = T<|>;
//^
"#,
)
}
}