From 8c4919c9fdfb2333fd798cd7d531f4264c939322 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 11 Jul 2020 12:45:30 +0200 Subject: Fix goto definition for type alias type parameters closes https://github.com/rust-analyzer/rust-analyzer/issues/5042 --- crates/ra_hir/src/semantics/source_to_def.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'crates/ra_hir/src/semantics') diff --git a/crates/ra_hir/src/semantics/source_to_def.rs b/crates/ra_hir/src/semantics/source_to_def.rs index 8af64fdc1..0e1d92fb3 100644 --- a/crates/ra_hir/src/semantics/source_to_def.rs +++ b/crates/ra_hir/src/semantics/source_to_def.rs @@ -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), } } -- cgit v1.2.3 From 693ac892f2db5db1ce7cf86db7bf6207b3515c42 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 13 Jul 2020 16:16:53 +0200 Subject: Don't copy-paste `impl_froms` into every crate --- crates/ra_hir/src/semantics/source_to_def.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir/src/semantics') diff --git a/crates/ra_hir/src/semantics/source_to_def.rs b/crates/ra_hir/src/semantics/source_to_def.rs index 0e1d92fb3..42e5a1bdb 100644 --- a/crates/ra_hir/src/semantics/source_to_def.rs +++ b/crates/ra_hir/src/semantics/source_to_def.rs @@ -16,6 +16,7 @@ use ra_syntax::{ match_ast, AstNode, SyntaxNode, }; use rustc_hash::FxHashMap; +use stdx::impl_from; use crate::{db::HirDatabase, InFile, MacroDefId}; @@ -255,8 +256,7 @@ pub(crate) enum ChildContainer { /// here the children generic parameters, and not, eg enum variants. GenericDefId(GenericDefId), } -impl_froms! { - ChildContainer: +impl_from! { DefWithBodyId, ModuleId, TraitId, @@ -265,6 +265,7 @@ impl_froms! { VariantId, TypeAliasId, GenericDefId + for ChildContainer } impl ChildContainer { -- cgit v1.2.3 From 1142112c70b705f59b7d559d9d72cdc831865158 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 14:51:08 +0200 Subject: Rename FnDef -> Fn --- crates/ra_hir/src/semantics/source_to_def.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'crates/ra_hir/src/semantics') diff --git a/crates/ra_hir/src/semantics/source_to_def.rs b/crates/ra_hir/src/semantics/source_to_def.rs index 42e5a1bdb..4118de2e2 100644 --- a/crates/ra_hir/src/semantics/source_to_def.rs +++ b/crates/ra_hir/src/semantics/source_to_def.rs @@ -71,7 +71,7 @@ impl SourceToDefCtx<'_, '_> { pub(super) fn impl_to_def(&mut self, src: InFile) -> Option { self.to_def(src, keys::IMPL) } - pub(super) fn fn_to_def(&mut self, src: InFile) -> Option { + pub(super) fn fn_to_def(&mut self, src: InFile) -> Option { self.to_def(src, keys::FUNCTION) } pub(super) fn struct_to_def(&mut self, src: InFile) -> Option { @@ -171,7 +171,7 @@ impl SourceToDefCtx<'_, '_> { let def = self.impl_to_def(container.with_value(it))?; def.into() }, - ast::FnDef(it) => { + ast::Fn(it) => { let def = self.fn_to_def(container.with_value(it))?; DefWithBodyId::from(def).into() }, @@ -213,7 +213,7 @@ impl SourceToDefCtx<'_, '_> { for container in src.cloned().ancestors_with_macros(self.db.upcast()).skip(1) { let res: GenericDefId = match_ast! { match (container.value) { - ast::FnDef(it) => self.fn_to_def(container.with_value(it))?.into(), + ast::Fn(it) => self.fn_to_def(container.with_value(it))?.into(), ast::StructDef(it) => self.struct_to_def(container.with_value(it))?.into(), ast::EnumDef(it) => self.enum_to_def(container.with_value(it))?.into(), ast::TraitDef(it) => self.trait_to_def(container.with_value(it))?.into(), @@ -233,7 +233,7 @@ impl SourceToDefCtx<'_, '_> { match (container.value) { ast::ConstDef(it) => self.const_to_def(container.with_value(it))?.into(), ast::StaticDef(it) => self.static_to_def(container.with_value(it))?.into(), - ast::FnDef(it) => self.fn_to_def(container.with_value(it))?.into(), + ast::Fn(it) => self.fn_to_def(container.with_value(it))?.into(), _ => continue, } }; -- cgit v1.2.3 From eb2f8063444b11257111f4f8ade990ec810e0361 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 15:25:46 +0200 Subject: Rename TypeAliasDef -> TypeAlias --- crates/ra_hir/src/semantics/source_to_def.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'crates/ra_hir/src/semantics') diff --git a/crates/ra_hir/src/semantics/source_to_def.rs b/crates/ra_hir/src/semantics/source_to_def.rs index 4118de2e2..d23a1974b 100644 --- a/crates/ra_hir/src/semantics/source_to_def.rs +++ b/crates/ra_hir/src/semantics/source_to_def.rs @@ -89,10 +89,7 @@ impl SourceToDefCtx<'_, '_> { pub(super) fn const_to_def(&mut self, src: InFile) -> Option { self.to_def(src, keys::CONST) } - pub(super) fn type_alias_to_def( - &mut self, - src: InFile, - ) -> Option { + pub(super) fn type_alias_to_def(&mut self, src: InFile) -> Option { self.to_def(src, keys::TYPE_ALIAS) } pub(super) fn record_field_to_def( @@ -195,7 +192,7 @@ impl SourceToDefCtx<'_, '_> { let def = self.const_to_def(container.with_value(it))?; DefWithBodyId::from(def).into() }, - ast::TypeAliasDef(it) => { + ast::TypeAlias(it) => { let def = self.type_alias_to_def(container.with_value(it))?; def.into() }, @@ -217,7 +214,7 @@ impl SourceToDefCtx<'_, '_> { ast::StructDef(it) => self.struct_to_def(container.with_value(it))?.into(), ast::EnumDef(it) => self.enum_to_def(container.with_value(it))?.into(), ast::TraitDef(it) => self.trait_to_def(container.with_value(it))?.into(), - ast::TypeAliasDef(it) => self.type_alias_to_def(container.with_value(it))?.into(), + ast::TypeAlias(it) => self.type_alias_to_def(container.with_value(it))?.into(), ast::ImplDef(it) => self.impl_to_def(container.with_value(it))?.into(), _ => continue, } -- cgit v1.2.3 From 0a9e3ccc262fbcbd4cdaab30384f8cb71584544b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 16:49:13 +0200 Subject: Rename FieldDef -> Field --- crates/ra_hir/src/semantics/source_to_def.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'crates/ra_hir/src/semantics') diff --git a/crates/ra_hir/src/semantics/source_to_def.rs b/crates/ra_hir/src/semantics/source_to_def.rs index d23a1974b..4f90f588e 100644 --- a/crates/ra_hir/src/semantics/source_to_def.rs +++ b/crates/ra_hir/src/semantics/source_to_def.rs @@ -92,16 +92,10 @@ impl SourceToDefCtx<'_, '_> { pub(super) fn type_alias_to_def(&mut self, src: InFile) -> Option { self.to_def(src, keys::TYPE_ALIAS) } - pub(super) fn record_field_to_def( - &mut self, - src: InFile, - ) -> Option { + pub(super) fn record_field_to_def(&mut self, src: InFile) -> Option { self.to_def(src, keys::RECORD_FIELD) } - pub(super) fn tuple_field_to_def( - &mut self, - src: InFile, - ) -> Option { + pub(super) fn tuple_field_to_def(&mut self, src: InFile) -> Option { self.to_def(src, keys::TUPLE_FIELD) } pub(super) fn enum_variant_to_def( -- cgit v1.2.3 From 1ae4721c9cfea746fce59a816b1c266bf373d6cf Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 17:36:46 +0200 Subject: Finalize union grammar --- crates/ra_hir/src/semantics/source_to_def.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir/src/semantics') diff --git a/crates/ra_hir/src/semantics/source_to_def.rs b/crates/ra_hir/src/semantics/source_to_def.rs index 4f90f588e..0093a8671 100644 --- a/crates/ra_hir/src/semantics/source_to_def.rs +++ b/crates/ra_hir/src/semantics/source_to_def.rs @@ -80,7 +80,7 @@ impl SourceToDefCtx<'_, '_> { pub(super) fn enum_to_def(&mut self, src: InFile) -> Option { self.to_def(src, keys::ENUM) } - pub(super) fn union_to_def(&mut self, src: InFile) -> Option { + pub(super) fn union_to_def(&mut self, src: InFile) -> Option { self.to_def(src, keys::UNION) } pub(super) fn static_to_def(&mut self, src: InFile) -> Option { @@ -174,7 +174,7 @@ impl SourceToDefCtx<'_, '_> { let def = self.enum_to_def(container.with_value(it))?; def.into() }, - ast::UnionDef(it) => { + ast::Union(it) => { let def = self.union_to_def(container.with_value(it))?; VariantId::from(def).into() }, -- cgit v1.2.3 From 216a5344c8ef3c3e430d2761dc8b1a7b60250a15 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 17:50:40 +0200 Subject: Rename StructDef -> Struct --- crates/ra_hir/src/semantics/source_to_def.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir/src/semantics') diff --git a/crates/ra_hir/src/semantics/source_to_def.rs b/crates/ra_hir/src/semantics/source_to_def.rs index 0093a8671..75b773352 100644 --- a/crates/ra_hir/src/semantics/source_to_def.rs +++ b/crates/ra_hir/src/semantics/source_to_def.rs @@ -74,7 +74,7 @@ impl SourceToDefCtx<'_, '_> { pub(super) fn fn_to_def(&mut self, src: InFile) -> Option { self.to_def(src, keys::FUNCTION) } - pub(super) fn struct_to_def(&mut self, src: InFile) -> Option { + pub(super) fn struct_to_def(&mut self, src: InFile) -> Option { self.to_def(src, keys::STRUCT) } pub(super) fn enum_to_def(&mut self, src: InFile) -> Option { @@ -166,7 +166,7 @@ impl SourceToDefCtx<'_, '_> { let def = self.fn_to_def(container.with_value(it))?; DefWithBodyId::from(def).into() }, - ast::StructDef(it) => { + ast::Struct(it) => { let def = self.struct_to_def(container.with_value(it))?; VariantId::from(def).into() }, @@ -205,7 +205,7 @@ impl SourceToDefCtx<'_, '_> { let res: GenericDefId = match_ast! { match (container.value) { ast::Fn(it) => self.fn_to_def(container.with_value(it))?.into(), - ast::StructDef(it) => self.struct_to_def(container.with_value(it))?.into(), + ast::Struct(it) => self.struct_to_def(container.with_value(it))?.into(), ast::EnumDef(it) => self.enum_to_def(container.with_value(it))?.into(), ast::TraitDef(it) => self.trait_to_def(container.with_value(it))?.into(), ast::TypeAlias(it) => self.type_alias_to_def(container.with_value(it))?.into(), -- cgit v1.2.3 From 609680ef97dbf82c07b6b06e21aa366423892304 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 17:52:53 +0200 Subject: Rename EnumDef -> Enum --- crates/ra_hir/src/semantics/source_to_def.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir/src/semantics') diff --git a/crates/ra_hir/src/semantics/source_to_def.rs b/crates/ra_hir/src/semantics/source_to_def.rs index 75b773352..9f81b952f 100644 --- a/crates/ra_hir/src/semantics/source_to_def.rs +++ b/crates/ra_hir/src/semantics/source_to_def.rs @@ -77,7 +77,7 @@ impl SourceToDefCtx<'_, '_> { pub(super) fn struct_to_def(&mut self, src: InFile) -> Option { self.to_def(src, keys::STRUCT) } - pub(super) fn enum_to_def(&mut self, src: InFile) -> Option { + pub(super) fn enum_to_def(&mut self, src: InFile) -> Option { self.to_def(src, keys::ENUM) } pub(super) fn union_to_def(&mut self, src: InFile) -> Option { @@ -170,7 +170,7 @@ impl SourceToDefCtx<'_, '_> { let def = self.struct_to_def(container.with_value(it))?; VariantId::from(def).into() }, - ast::EnumDef(it) => { + ast::Enum(it) => { let def = self.enum_to_def(container.with_value(it))?; def.into() }, @@ -206,7 +206,7 @@ impl SourceToDefCtx<'_, '_> { match (container.value) { ast::Fn(it) => self.fn_to_def(container.with_value(it))?.into(), ast::Struct(it) => self.struct_to_def(container.with_value(it))?.into(), - ast::EnumDef(it) => self.enum_to_def(container.with_value(it))?.into(), + ast::Enum(it) => self.enum_to_def(container.with_value(it))?.into(), ast::TraitDef(it) => self.trait_to_def(container.with_value(it))?.into(), ast::TypeAlias(it) => self.type_alias_to_def(container.with_value(it))?.into(), ast::ImplDef(it) => self.impl_to_def(container.with_value(it))?.into(), -- cgit v1.2.3 From 1766aae145c6925a33e427f2fe6ef2a56c301665 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 17:56:53 +0200 Subject: Rename EnumVariant -> Variant --- crates/ra_hir/src/semantics/source_to_def.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir/src/semantics') diff --git a/crates/ra_hir/src/semantics/source_to_def.rs b/crates/ra_hir/src/semantics/source_to_def.rs index 9f81b952f..b85a12680 100644 --- a/crates/ra_hir/src/semantics/source_to_def.rs +++ b/crates/ra_hir/src/semantics/source_to_def.rs @@ -100,9 +100,9 @@ impl SourceToDefCtx<'_, '_> { } pub(super) fn enum_variant_to_def( &mut self, - src: InFile, + src: InFile, ) -> Option { - self.to_def(src, keys::ENUM_VARIANT) + self.to_def(src, keys::VARIANT) } pub(super) fn bind_pat_to_def( &mut self, -- cgit v1.2.3 From 3cd4112bdc924c132cb0eab9d064511a215421ec Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 18:02:20 +0200 Subject: Finalize const&static grammar --- crates/ra_hir/src/semantics/source_to_def.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'crates/ra_hir/src/semantics') diff --git a/crates/ra_hir/src/semantics/source_to_def.rs b/crates/ra_hir/src/semantics/source_to_def.rs index b85a12680..782a03f9e 100644 --- a/crates/ra_hir/src/semantics/source_to_def.rs +++ b/crates/ra_hir/src/semantics/source_to_def.rs @@ -83,10 +83,10 @@ impl SourceToDefCtx<'_, '_> { pub(super) fn union_to_def(&mut self, src: InFile) -> Option { self.to_def(src, keys::UNION) } - pub(super) fn static_to_def(&mut self, src: InFile) -> Option { + pub(super) fn static_to_def(&mut self, src: InFile) -> Option { self.to_def(src, keys::STATIC) } - pub(super) fn const_to_def(&mut self, src: InFile) -> Option { + pub(super) fn const_to_def(&mut self, src: InFile) -> Option { self.to_def(src, keys::CONST) } pub(super) fn type_alias_to_def(&mut self, src: InFile) -> Option { @@ -178,11 +178,11 @@ impl SourceToDefCtx<'_, '_> { let def = self.union_to_def(container.with_value(it))?; VariantId::from(def).into() }, - ast::StaticDef(it) => { + ast::Static(it) => { let def = self.static_to_def(container.with_value(it))?; DefWithBodyId::from(def).into() }, - ast::ConstDef(it) => { + ast::Const(it) => { let def = self.const_to_def(container.with_value(it))?; DefWithBodyId::from(def).into() }, @@ -222,8 +222,8 @@ impl SourceToDefCtx<'_, '_> { for container in src.cloned().ancestors_with_macros(self.db.upcast()).skip(1) { let res: DefWithBodyId = match_ast! { match (container.value) { - ast::ConstDef(it) => self.const_to_def(container.with_value(it))?.into(), - ast::StaticDef(it) => self.static_to_def(container.with_value(it))?.into(), + ast::Const(it) => self.const_to_def(container.with_value(it))?.into(), + ast::Static(it) => self.static_to_def(container.with_value(it))?.into(), ast::Fn(it) => self.fn_to_def(container.with_value(it))?.into(), _ => continue, } -- cgit v1.2.3 From c83467796b6c7365ea4f41900d74444384a9e618 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 18:17:28 +0200 Subject: Finalize Trait grammar --- crates/ra_hir/src/semantics/source_to_def.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir/src/semantics') diff --git a/crates/ra_hir/src/semantics/source_to_def.rs b/crates/ra_hir/src/semantics/source_to_def.rs index 782a03f9e..ae41d3ddf 100644 --- a/crates/ra_hir/src/semantics/source_to_def.rs +++ b/crates/ra_hir/src/semantics/source_to_def.rs @@ -65,7 +65,7 @@ impl SourceToDefCtx<'_, '_> { Some(ModuleId { krate: parent_module.krate, local_id: child_id }) } - pub(super) fn trait_to_def(&mut self, src: InFile) -> Option { + pub(super) fn trait_to_def(&mut self, src: InFile) -> Option { self.to_def(src, keys::TRAIT) } pub(super) fn impl_to_def(&mut self, src: InFile) -> Option { @@ -154,7 +154,7 @@ impl SourceToDefCtx<'_, '_> { let def = self.module_to_def(container.with_value(it))?; def.into() }, - ast::TraitDef(it) => { + ast::Trait(it) => { let def = self.trait_to_def(container.with_value(it))?; def.into() }, @@ -207,7 +207,7 @@ impl SourceToDefCtx<'_, '_> { ast::Fn(it) => self.fn_to_def(container.with_value(it))?.into(), ast::Struct(it) => self.struct_to_def(container.with_value(it))?.into(), ast::Enum(it) => self.enum_to_def(container.with_value(it))?.into(), - ast::TraitDef(it) => self.trait_to_def(container.with_value(it))?.into(), + ast::Trait(it) => self.trait_to_def(container.with_value(it))?.into(), ast::TypeAlias(it) => self.type_alias_to_def(container.with_value(it))?.into(), ast::ImplDef(it) => self.impl_to_def(container.with_value(it))?.into(), _ => continue, -- cgit v1.2.3 From c5798c4d75aa807aec47208a49101bdec3affcca Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 18:28:28 +0200 Subject: Finalize impl Grammar --- crates/ra_hir/src/semantics/source_to_def.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir/src/semantics') diff --git a/crates/ra_hir/src/semantics/source_to_def.rs b/crates/ra_hir/src/semantics/source_to_def.rs index ae41d3ddf..d1994e2e7 100644 --- a/crates/ra_hir/src/semantics/source_to_def.rs +++ b/crates/ra_hir/src/semantics/source_to_def.rs @@ -68,7 +68,7 @@ impl SourceToDefCtx<'_, '_> { pub(super) fn trait_to_def(&mut self, src: InFile) -> Option { self.to_def(src, keys::TRAIT) } - pub(super) fn impl_to_def(&mut self, src: InFile) -> Option { + pub(super) fn impl_to_def(&mut self, src: InFile) -> Option { self.to_def(src, keys::IMPL) } pub(super) fn fn_to_def(&mut self, src: InFile) -> Option { @@ -158,7 +158,7 @@ impl SourceToDefCtx<'_, '_> { let def = self.trait_to_def(container.with_value(it))?; def.into() }, - ast::ImplDef(it) => { + ast::Impl(it) => { let def = self.impl_to_def(container.with_value(it))?; def.into() }, @@ -209,7 +209,7 @@ impl SourceToDefCtx<'_, '_> { ast::Enum(it) => self.enum_to_def(container.with_value(it))?.into(), ast::Trait(it) => self.trait_to_def(container.with_value(it))?.into(), ast::TypeAlias(it) => self.type_alias_to_def(container.with_value(it))?.into(), - ast::ImplDef(it) => self.impl_to_def(container.with_value(it))?.into(), + ast::Impl(it) => self.impl_to_def(container.with_value(it))?.into(), _ => continue, } }; -- cgit v1.2.3