aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-11-11 14:36:27 +0000
committerAleksey Kladov <[email protected]>2019-11-11 14:36:27 +0000
commitc5a18c44e5211282c22b9ca7aae8700ee8ca1817 (patch)
tree1b0f7c7b0f430d4174ca05e5464b3af98128bafe /crates/ra_hir
parentff609cc49715571324b72d2bda60d56878466640 (diff)
Introduce hir::GenericParam
Unlike existing hir::GenericParams, this is a global ID.
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/code_model.rs8
-rw-r--r--crates/ra_hir/src/lib.rs4
-rw-r--r--crates/ra_hir/src/source_binder.rs11
3 files changed, 16 insertions, 7 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 09c4e97fa..5a0bd0c19 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -23,7 +23,7 @@ use crate::{
23 adt::VariantDef, 23 adt::VariantDef,
24 db::{AstDatabase, DefDatabase, HirDatabase}, 24 db::{AstDatabase, DefDatabase, HirDatabase},
25 expr::{validation::ExprValidator, BindingAnnotation, Body, BodySourceMap, Pat, PatId}, 25 expr::{validation::ExprValidator, BindingAnnotation, Body, BodySourceMap, Pat, PatId},
26 generics::HasGenericParams, 26 generics::{GenericDef, HasGenericParams},
27 ids::{ 27 ids::{
28 AstItemDef, ConstId, EnumId, FunctionId, MacroDefId, StaticId, StructId, TraitId, 28 AstItemDef, ConstId, EnumId, FunctionId, MacroDefId, StaticId, StructId, TraitId,
29 TypeAliasId, 29 TypeAliasId,
@@ -1121,3 +1121,9 @@ impl Local {
1121 src.map(|ast| ast.map(|it| it.cast().unwrap().to_node(&root), |it| it.to_node(&root))) 1121 src.map(|ast| ast.map(|it| it.cast().unwrap().to_node(&root), |it| it.to_node(&root)))
1122 } 1122 }
1123} 1123}
1124
1125#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1126pub struct GenericParam {
1127 pub(crate) parent: GenericDef,
1128 pub(crate) idx: u32,
1129}
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 125c4b289..92d71b9e8 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -65,8 +65,8 @@ pub use crate::{
65 docs::{DocDef, Docs, Documentation}, 65 docs::{DocDef, Docs, Documentation},
66 src::{HasBodySource, HasSource}, 66 src::{HasBodySource, HasSource},
67 Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum, 67 Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum,
68 EnumVariant, FieldSource, FnData, Function, HasBody, Local, MacroDef, Module, ModuleDef, 68 EnumVariant, FieldSource, FnData, Function, GenericParam, HasBody, Local, MacroDef, Module,
69 ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, 69 ModuleDef, ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union,
70 }, 70 },
71 expr::ExprScopes, 71 expr::ExprScopes,
72 from_source::FromSource, 72 from_source::FromSource,
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index c5fdf3bab..fe4211819 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -28,8 +28,8 @@ use crate::{
28 ids::LocationCtx, 28 ids::LocationCtx,
29 resolve::{ScopeDef, TypeNs, ValueNs}, 29 resolve::{ScopeDef, TypeNs, ValueNs},
30 ty::method_resolution::{self, implements_trait}, 30 ty::method_resolution::{self, implements_trait},
31 AssocItem, Const, DefWithBody, Either, Enum, FromSource, Function, HasBody, HirFileId, Local, 31 AssocItem, Const, DefWithBody, Either, Enum, FromSource, Function, GenericParam, HasBody,
32 MacroDef, Module, Name, Path, Resolver, Static, Struct, Ty, 32 HirFileId, Local, MacroDef, Module, Name, Path, Resolver, Static, Struct, Ty,
33}; 33};
34 34
35fn try_get_resolver_for_node( 35fn try_get_resolver_for_node(
@@ -107,7 +107,7 @@ pub enum PathResolution {
107 /// A local binding (only value namespace) 107 /// A local binding (only value namespace)
108 Local(Local), 108 Local(Local),
109 /// A generic parameter 109 /// A generic parameter
110 GenericParam(u32), 110 GenericParam(GenericParam),
111 SelfType(crate::ImplBlock), 111 SelfType(crate::ImplBlock),
112 Macro(MacroDef), 112 Macro(MacroDef),
113 AssocItem(crate::AssocItem), 113 AssocItem(crate::AssocItem),
@@ -227,7 +227,10 @@ impl SourceAnalyzer {
227 ) -> Option<PathResolution> { 227 ) -> Option<PathResolution> {
228 let types = self.resolver.resolve_path_in_type_ns_fully(db, &path).map(|ty| match ty { 228 let types = self.resolver.resolve_path_in_type_ns_fully(db, &path).map(|ty| match ty {
229 TypeNs::SelfType(it) => PathResolution::SelfType(it), 229 TypeNs::SelfType(it) => PathResolution::SelfType(it),
230 TypeNs::GenericParam(it) => PathResolution::GenericParam(it), 230 TypeNs::GenericParam(idx) => PathResolution::GenericParam(GenericParam {
231 parent: self.resolver.generic_def().unwrap(),
232 idx,
233 }),
231 TypeNs::AdtSelfType(it) | TypeNs::Adt(it) => PathResolution::Def(it.into()), 234 TypeNs::AdtSelfType(it) | TypeNs::Adt(it) => PathResolution::Def(it.into()),
232 TypeNs::EnumVariant(it) => PathResolution::Def(it.into()), 235 TypeNs::EnumVariant(it) => PathResolution::Def(it.into()),
233 TypeNs::TypeAlias(it) => PathResolution::Def(it.into()), 236 TypeNs::TypeAlias(it) => PathResolution::Def(it.into()),