diff options
author | Aleksey Kladov <[email protected]> | 2019-12-07 19:09:53 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-12-07 19:25:48 +0000 |
commit | 88c5b1282a5770097c6c768b24bedfc3a6944e08 (patch) | |
tree | 913c24e889f3db8044b4b9f11bc3969e7eb02e34 | |
parent | f4f8b8147426b0096d4b5126e487caaa13d13c27 (diff) |
Rename GenericParam -> TypeParam
We don't have LifetimeParam yet, but they are planned!
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 16 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model/src.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir/src/from_source.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir/src/source_binder.rs | 10 | ||||
-rw-r--r-- | crates/ra_hir_def/src/generics.rs | 28 | ||||
-rw-r--r-- | crates/ra_hir_def/src/keys.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir_def/src/resolver.rs | 18 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/utils.rs | 26 | ||||
-rw-r--r-- | crates/ra_ide/src/display/navigation_target.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide/src/goto_definition.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide/src/hover.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide/src/references.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide/src/references/classify.rs | 8 | ||||
-rw-r--r-- | crates/ra_ide/src/references/name_definition.rs | 6 | ||||
-rw-r--r-- | crates/ra_ide/src/snapshots/rainbow_highlighting.html | 1 | ||||
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting.rs | 3 |
18 files changed, 77 insertions, 79 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 0295eb948..4578a0ba8 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -15,9 +15,9 @@ use hir_def::{ | |||
15 | per_ns::PerNs, | 15 | per_ns::PerNs, |
16 | resolver::HasResolver, | 16 | resolver::HasResolver, |
17 | type_ref::{Mutability, TypeRef}, | 17 | type_ref::{Mutability, TypeRef}, |
18 | AdtId, AstItemDef, ConstId, ContainerId, DefWithBodyId, EnumId, FunctionId, GenericParamId, | 18 | AdtId, AstItemDef, ConstId, ContainerId, DefWithBodyId, EnumId, FunctionId, HasModule, ImplId, |
19 | HasModule, ImplId, LocalEnumVariantId, LocalImportId, LocalModuleId, LocalStructFieldId, | 19 | LocalEnumVariantId, LocalImportId, LocalModuleId, LocalStructFieldId, Lookup, ModuleId, |
20 | Lookup, ModuleId, StaticId, StructId, TraitId, TypeAliasId, UnionId, | 20 | StaticId, StructId, TraitId, TypeAliasId, TypeParamId, UnionId, |
21 | }; | 21 | }; |
22 | use hir_expand::{ | 22 | use hir_expand::{ |
23 | diagnostics::DiagnosticSink, | 23 | diagnostics::DiagnosticSink, |
@@ -856,14 +856,14 @@ impl Local { | |||
856 | } | 856 | } |
857 | 857 | ||
858 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | 858 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
859 | pub struct GenericParam { | 859 | pub struct TypeParam { |
860 | pub(crate) id: GenericParamId, | 860 | pub(crate) id: TypeParamId, |
861 | } | 861 | } |
862 | 862 | ||
863 | impl GenericParam { | 863 | impl TypeParam { |
864 | pub fn name(self, db: &impl HirDatabase) -> Name { | 864 | pub fn name(self, db: &impl HirDatabase) -> Name { |
865 | let params = db.generic_params(self.id.parent); | 865 | let params = db.generic_params(self.id.parent); |
866 | params.params[self.id.local_id].name.clone() | 866 | params.types[self.id.local_id].name.clone() |
867 | } | 867 | } |
868 | 868 | ||
869 | pub fn module(self, db: &impl HirDatabase) -> Module { | 869 | pub fn module(self, db: &impl HirDatabase) -> Module { |
@@ -1111,7 +1111,7 @@ impl HirDisplay for Type { | |||
1111 | pub enum ScopeDef { | 1111 | pub enum ScopeDef { |
1112 | ModuleDef(ModuleDef), | 1112 | ModuleDef(ModuleDef), |
1113 | MacroDef(MacroDef), | 1113 | MacroDef(MacroDef), |
1114 | GenericParam(GenericParam), | 1114 | GenericParam(TypeParam), |
1115 | ImplSelfType(ImplBlock), | 1115 | ImplSelfType(ImplBlock), |
1116 | AdtSelfType(Adt), | 1116 | AdtSelfType(Adt), |
1117 | Local(Local), | 1117 | Local(Local), |
diff --git a/crates/ra_hir/src/code_model/src.rs b/crates/ra_hir/src/code_model/src.rs index 8f04ebd23..b09582f93 100644 --- a/crates/ra_hir/src/code_model/src.rs +++ b/crates/ra_hir/src/code_model/src.rs | |||
@@ -9,8 +9,8 @@ use hir_def::{ | |||
9 | use ra_syntax::ast; | 9 | use ra_syntax::ast; |
10 | 10 | ||
11 | use crate::{ | 11 | use crate::{ |
12 | db::DefDatabase, Const, Enum, EnumVariant, FieldSource, Function, GenericParam, ImplBlock, | 12 | db::DefDatabase, Const, Enum, EnumVariant, FieldSource, Function, ImplBlock, Import, MacroDef, |
13 | Import, MacroDef, Module, Static, Struct, StructField, Trait, TypeAlias, Union, | 13 | Module, Static, Struct, StructField, Trait, TypeAlias, TypeParam, Union, |
14 | }; | 14 | }; |
15 | 15 | ||
16 | pub use hir_expand::InFile; | 16 | pub use hir_expand::InFile; |
@@ -130,7 +130,7 @@ impl HasSource for Import { | |||
130 | } | 130 | } |
131 | } | 131 | } |
132 | 132 | ||
133 | impl HasSource for GenericParam { | 133 | impl HasSource for TypeParam { |
134 | type Ast = Either<ast::TraitDef, ast::TypeParam>; | 134 | type Ast = Either<ast::TraitDef, ast::TypeParam>; |
135 | fn source(self, db: &impl DefDatabase) -> InFile<Self::Ast> { | 135 | fn source(self, db: &impl DefDatabase) -> InFile<Self::Ast> { |
136 | let child_source = self.id.parent.child_source(db); | 136 | let child_source = self.id.parent.child_source(db); |
diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs index 686ab1d79..68e59fc1e 100644 --- a/crates/ra_hir/src/from_source.rs +++ b/crates/ra_hir/src/from_source.rs | |||
@@ -11,8 +11,8 @@ use ra_syntax::{ | |||
11 | 11 | ||
12 | use crate::{ | 12 | use crate::{ |
13 | db::{AstDatabase, DefDatabase, HirDatabase}, | 13 | db::{AstDatabase, DefDatabase, HirDatabase}, |
14 | Const, DefWithBody, Enum, EnumVariant, FieldSource, Function, GenericParam, ImplBlock, InFile, | 14 | Const, DefWithBody, Enum, EnumVariant, FieldSource, Function, ImplBlock, InFile, Local, |
15 | Local, MacroDef, Module, Static, Struct, StructField, Trait, TypeAlias, Union, | 15 | MacroDef, Module, Static, Struct, StructField, Trait, TypeAlias, TypeParam, Union, |
16 | }; | 16 | }; |
17 | 17 | ||
18 | pub trait FromSource: Sized { | 18 | pub trait FromSource: Sized { |
@@ -177,7 +177,7 @@ impl Local { | |||
177 | } | 177 | } |
178 | } | 178 | } |
179 | 179 | ||
180 | impl GenericParam { | 180 | impl TypeParam { |
181 | pub fn from_source(db: &impl HirDatabase, src: InFile<ast::TypeParam>) -> Option<Self> { | 181 | pub fn from_source(db: &impl HirDatabase, src: InFile<ast::TypeParam>) -> Option<Self> { |
182 | let file_id = src.file_id; | 182 | let file_id = src.file_id; |
183 | let parent: GenericDefId = src.value.syntax().ancestors().find_map(|it| { | 183 | let parent: GenericDefId = src.value.syntax().ancestors().find_map(|it| { |
@@ -190,7 +190,7 @@ impl GenericParam { | |||
190 | Some(res) | 190 | Some(res) |
191 | })?; | 191 | })?; |
192 | let &id = parent.child_by_source(db)[keys::TYPE_PARAM].get(&src)?; | 192 | let &id = parent.child_by_source(db)[keys::TYPE_PARAM].get(&src)?; |
193 | Some(GenericParam { id }) | 193 | Some(TypeParam { id }) |
194 | } | 194 | } |
195 | } | 195 | } |
196 | 196 | ||
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index f12e4ca3f..9eb34b5dc 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -42,9 +42,9 @@ pub mod from_source; | |||
42 | pub use crate::{ | 42 | pub use crate::{ |
43 | code_model::{ | 43 | code_model::{ |
44 | src::HasSource, Adt, AssocItem, AttrDef, Const, Container, Crate, CrateDependency, | 44 | src::HasSource, Adt, AssocItem, AttrDef, Const, Container, Crate, CrateDependency, |
45 | DefWithBody, Docs, Enum, EnumVariant, FieldSource, Function, GenericDef, GenericParam, | 45 | DefWithBody, Docs, Enum, EnumVariant, FieldSource, Function, GenericDef, HasAttrs, |
46 | HasAttrs, ImplBlock, Import, Local, MacroDef, Module, ModuleDef, ScopeDef, Static, Struct, | 46 | ImplBlock, Import, Local, MacroDef, Module, ModuleDef, ScopeDef, Static, Struct, |
47 | StructField, Trait, Type, TypeAlias, Union, VariantDef, | 47 | StructField, Trait, Type, TypeAlias, TypeParam, Union, VariantDef, |
48 | }, | 48 | }, |
49 | from_source::FromSource, | 49 | from_source::FromSource, |
50 | source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer}, | 50 | source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer}, |
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 2957e496c..b80aaeb90 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs | |||
@@ -36,8 +36,8 @@ use crate::{ | |||
36 | method_resolution::{self, implements_trait}, | 36 | method_resolution::{self, implements_trait}, |
37 | InEnvironment, TraitEnvironment, Ty, | 37 | InEnvironment, TraitEnvironment, Ty, |
38 | }, | 38 | }, |
39 | Adt, AssocItem, Const, DefWithBody, Enum, EnumVariant, FromSource, Function, GenericParam, | 39 | Adt, AssocItem, Const, DefWithBody, Enum, EnumVariant, FromSource, Function, ImplBlock, Local, |
40 | ImplBlock, Local, MacroDef, Name, Path, ScopeDef, Static, Struct, Trait, Type, TypeAlias, | 40 | MacroDef, Name, Path, ScopeDef, Static, Struct, Trait, Type, TypeAlias, TypeParam, |
41 | }; | 41 | }; |
42 | 42 | ||
43 | fn try_get_resolver_for_node(db: &impl HirDatabase, node: InFile<&SyntaxNode>) -> Option<Resolver> { | 43 | fn try_get_resolver_for_node(db: &impl HirDatabase, node: InFile<&SyntaxNode>) -> Option<Resolver> { |
@@ -112,7 +112,7 @@ pub enum PathResolution { | |||
112 | /// A local binding (only value namespace) | 112 | /// A local binding (only value namespace) |
113 | Local(Local), | 113 | Local(Local), |
114 | /// A generic parameter | 114 | /// A generic parameter |
115 | GenericParam(GenericParam), | 115 | TypeParam(TypeParam), |
116 | SelfType(crate::ImplBlock), | 116 | SelfType(crate::ImplBlock), |
117 | Macro(MacroDef), | 117 | Macro(MacroDef), |
118 | AssocItem(crate::AssocItem), | 118 | AssocItem(crate::AssocItem), |
@@ -266,7 +266,7 @@ impl SourceAnalyzer { | |||
266 | ) -> Option<PathResolution> { | 266 | ) -> Option<PathResolution> { |
267 | let types = self.resolver.resolve_path_in_type_ns_fully(db, &path).map(|ty| match ty { | 267 | let types = self.resolver.resolve_path_in_type_ns_fully(db, &path).map(|ty| match ty { |
268 | TypeNs::SelfType(it) => PathResolution::SelfType(it.into()), | 268 | TypeNs::SelfType(it) => PathResolution::SelfType(it.into()), |
269 | TypeNs::GenericParam(id) => PathResolution::GenericParam(GenericParam { id }), | 269 | TypeNs::GenericParam(id) => PathResolution::TypeParam(TypeParam { id }), |
270 | TypeNs::AdtSelfType(it) | TypeNs::AdtId(it) => { | 270 | TypeNs::AdtSelfType(it) | TypeNs::AdtId(it) => { |
271 | PathResolution::Def(Adt::from(it).into()) | 271 | PathResolution::Def(Adt::from(it).into()) |
272 | } | 272 | } |
@@ -338,7 +338,7 @@ impl SourceAnalyzer { | |||
338 | resolver::ScopeDef::PerNs(it) => it.into(), | 338 | resolver::ScopeDef::PerNs(it) => it.into(), |
339 | resolver::ScopeDef::ImplSelfType(it) => ScopeDef::ImplSelfType(it.into()), | 339 | resolver::ScopeDef::ImplSelfType(it) => ScopeDef::ImplSelfType(it.into()), |
340 | resolver::ScopeDef::AdtSelfType(it) => ScopeDef::AdtSelfType(it.into()), | 340 | resolver::ScopeDef::AdtSelfType(it) => ScopeDef::AdtSelfType(it.into()), |
341 | resolver::ScopeDef::GenericParam(id) => ScopeDef::GenericParam(GenericParam { id }), | 341 | resolver::ScopeDef::GenericParam(id) => ScopeDef::GenericParam(TypeParam { id }), |
342 | resolver::ScopeDef::Local(pat_id) => { | 342 | resolver::ScopeDef::Local(pat_id) => { |
343 | let parent = self.resolver.body_owner().unwrap().into(); | 343 | let parent = self.resolver.body_owner().unwrap().into(); |
344 | ScopeDef::Local(Local { parent, pat_id }) | 344 | ScopeDef::Local(Local { parent, pat_id }) |
diff --git a/crates/ra_hir_def/src/generics.rs b/crates/ra_hir_def/src/generics.rs index 159f9034b..976cf72d0 100644 --- a/crates/ra_hir_def/src/generics.rs +++ b/crates/ra_hir_def/src/generics.rs | |||
@@ -21,12 +21,12 @@ use crate::{ | |||
21 | src::HasChildSource, | 21 | src::HasChildSource, |
22 | src::HasSource, | 22 | src::HasSource, |
23 | type_ref::{TypeBound, TypeRef}, | 23 | type_ref::{TypeBound, TypeRef}, |
24 | AdtId, AstItemDef, GenericDefId, GenericParamId, LocalGenericParamId, Lookup, | 24 | AdtId, AstItemDef, GenericDefId, LocalTypeParamId, Lookup, TypeParamId, |
25 | }; | 25 | }; |
26 | 26 | ||
27 | /// Data about a generic parameter (to a function, struct, impl, ...). | 27 | /// Data about a generic parameter (to a function, struct, impl, ...). |
28 | #[derive(Clone, PartialEq, Eq, Debug)] | 28 | #[derive(Clone, PartialEq, Eq, Debug)] |
29 | pub struct GenericParamData { | 29 | pub struct TypeParamData { |
30 | pub name: Name, | 30 | pub name: Name, |
31 | pub default: Option<TypeRef>, | 31 | pub default: Option<TypeRef>, |
32 | } | 32 | } |
@@ -34,7 +34,8 @@ pub struct GenericParamData { | |||
34 | /// Data about the generic parameters of a function, struct, impl, etc. | 34 | /// Data about the generic parameters of a function, struct, impl, etc. |
35 | #[derive(Clone, PartialEq, Eq, Debug)] | 35 | #[derive(Clone, PartialEq, Eq, Debug)] |
36 | pub struct GenericParams { | 36 | pub struct GenericParams { |
37 | pub params: Arena<LocalGenericParamId, GenericParamData>, | 37 | pub types: Arena<LocalTypeParamId, TypeParamData>, |
38 | // lifetimes: Arena<LocalLifetimeParamId, LifetimeParamData>, | ||
38 | pub where_predicates: Vec<WherePredicate>, | 39 | pub where_predicates: Vec<WherePredicate>, |
39 | } | 40 | } |
40 | 41 | ||
@@ -48,7 +49,7 @@ pub struct WherePredicate { | |||
48 | pub bound: TypeBound, | 49 | pub bound: TypeBound, |
49 | } | 50 | } |
50 | 51 | ||
51 | type SourceMap = ArenaMap<LocalGenericParamId, Either<ast::TraitDef, ast::TypeParam>>; | 52 | type SourceMap = ArenaMap<LocalTypeParamId, Either<ast::TraitDef, ast::TypeParam>>; |
52 | 53 | ||
53 | impl GenericParams { | 54 | impl GenericParams { |
54 | pub(crate) fn generic_params_query( | 55 | pub(crate) fn generic_params_query( |
@@ -60,7 +61,7 @@ impl GenericParams { | |||
60 | } | 61 | } |
61 | 62 | ||
62 | fn new(db: &impl DefDatabase, def: GenericDefId) -> (GenericParams, InFile<SourceMap>) { | 63 | fn new(db: &impl DefDatabase, def: GenericDefId) -> (GenericParams, InFile<SourceMap>) { |
63 | let mut generics = GenericParams { params: Arena::default(), where_predicates: Vec::new() }; | 64 | let mut generics = GenericParams { types: Arena::default(), where_predicates: Vec::new() }; |
64 | let mut sm = ArenaMap::default(); | 65 | let mut sm = ArenaMap::default(); |
65 | // FIXME: add `: Sized` bound for everything except for `Self` in traits | 66 | // FIXME: add `: Sized` bound for everything except for `Self` in traits |
66 | let file_id = match def { | 67 | let file_id = match def { |
@@ -88,9 +89,8 @@ impl GenericParams { | |||
88 | let src = it.source(db); | 89 | let src = it.source(db); |
89 | 90 | ||
90 | // traits get the Self type as an implicit first type parameter | 91 | // traits get the Self type as an implicit first type parameter |
91 | let self_param_id = generics | 92 | let self_param_id = |
92 | .params | 93 | generics.types.alloc(TypeParamData { name: name::SELF_TYPE, default: None }); |
93 | .alloc(GenericParamData { name: name::SELF_TYPE, default: None }); | ||
94 | sm.insert(self_param_id, Either::Left(src.value.clone())); | 94 | sm.insert(self_param_id, Either::Left(src.value.clone())); |
95 | // add super traits as bounds on Self | 95 | // add super traits as bounds on Self |
96 | // i.e., trait Foo: Bar is equivalent to trait Foo where Self: Bar | 96 | // i.e., trait Foo: Bar is equivalent to trait Foo where Self: Bar |
@@ -142,8 +142,8 @@ impl GenericParams { | |||
142 | let name = type_param.name().map_or_else(Name::missing, |it| it.as_name()); | 142 | let name = type_param.name().map_or_else(Name::missing, |it| it.as_name()); |
143 | // FIXME: Use `Path::from_src` | 143 | // FIXME: Use `Path::from_src` |
144 | let default = type_param.default_type().map(TypeRef::from_ast); | 144 | let default = type_param.default_type().map(TypeRef::from_ast); |
145 | let param = GenericParamData { name: name.clone(), default }; | 145 | let param = TypeParamData { name: name.clone(), default }; |
146 | let param_id = self.params.alloc(param); | 146 | let param_id = self.types.alloc(param); |
147 | sm.insert(param_id, Either::Right(type_param.clone())); | 147 | sm.insert(param_id, Either::Right(type_param.clone())); |
148 | 148 | ||
149 | let type_ref = TypeRef::Path(name.into()); | 149 | let type_ref = TypeRef::Path(name.into()); |
@@ -173,13 +173,13 @@ impl GenericParams { | |||
173 | self.where_predicates.push(WherePredicate { type_ref, bound }); | 173 | self.where_predicates.push(WherePredicate { type_ref, bound }); |
174 | } | 174 | } |
175 | 175 | ||
176 | pub fn find_by_name(&self, name: &Name) -> Option<LocalGenericParamId> { | 176 | pub fn find_by_name(&self, name: &Name) -> Option<LocalTypeParamId> { |
177 | self.params.iter().find_map(|(id, p)| if &p.name == name { Some(id) } else { None }) | 177 | self.types.iter().find_map(|(id, p)| if &p.name == name { Some(id) } else { None }) |
178 | } | 178 | } |
179 | } | 179 | } |
180 | 180 | ||
181 | impl HasChildSource for GenericDefId { | 181 | impl HasChildSource for GenericDefId { |
182 | type ChildId = LocalGenericParamId; | 182 | type ChildId = LocalTypeParamId; |
183 | type Value = Either<ast::TraitDef, ast::TypeParam>; | 183 | type Value = Either<ast::TraitDef, ast::TypeParam>; |
184 | fn child_source(&self, db: &impl DefDatabase) -> InFile<SourceMap> { | 184 | fn child_source(&self, db: &impl DefDatabase) -> InFile<SourceMap> { |
185 | let (_, sm) = GenericParams::new(db, *self); | 185 | let (_, sm) = GenericParams::new(db, *self); |
@@ -193,7 +193,7 @@ impl ChildBySource for GenericDefId { | |||
193 | let arena_map = self.child_source(db); | 193 | let arena_map = self.child_source(db); |
194 | let arena_map = arena_map.as_ref(); | 194 | let arena_map = arena_map.as_ref(); |
195 | for (local_id, src) in arena_map.value.iter() { | 195 | for (local_id, src) in arena_map.value.iter() { |
196 | let id = GenericParamId { parent: *self, local_id }; | 196 | let id = TypeParamId { parent: *self, local_id }; |
197 | if let Either::Right(type_param) = src { | 197 | if let Either::Right(type_param) = src { |
198 | res[keys::TYPE_PARAM].insert(arena_map.with_value(type_param.clone()), id) | 198 | res[keys::TYPE_PARAM].insert(arena_map.with_value(type_param.clone()), id) |
199 | } | 199 | } |
diff --git a/crates/ra_hir_def/src/keys.rs b/crates/ra_hir_def/src/keys.rs index ca5630c80..be702a4f8 100644 --- a/crates/ra_hir_def/src/keys.rs +++ b/crates/ra_hir_def/src/keys.rs | |||
@@ -8,7 +8,7 @@ use rustc_hash::FxHashMap; | |||
8 | 8 | ||
9 | use crate::{ | 9 | use crate::{ |
10 | dyn_map::{DynMap, Policy}, | 10 | dyn_map::{DynMap, Policy}, |
11 | ConstId, EnumVariantId, FunctionId, GenericParamId, StaticId, StructFieldId, TypeAliasId, | 11 | ConstId, EnumVariantId, FunctionId, StaticId, StructFieldId, TypeAliasId, TypeParamId, |
12 | }; | 12 | }; |
13 | 13 | ||
14 | type Key<K, V> = crate::dyn_map::Key<InFile<K>, V, AstPtrPolicy<K, V>>; | 14 | type Key<K, V> = crate::dyn_map::Key<InFile<K>, V, AstPtrPolicy<K, V>>; |
@@ -20,7 +20,7 @@ pub const ENUM_VARIANT: Key<ast::EnumVariant, EnumVariantId> = Key::new(); | |||
20 | pub const TYPE_ALIAS: Key<ast::TypeAliasDef, TypeAliasId> = Key::new(); | 20 | pub const TYPE_ALIAS: Key<ast::TypeAliasDef, TypeAliasId> = Key::new(); |
21 | pub const TUPLE_FIELD: Key<ast::TupleFieldDef, StructFieldId> = Key::new(); | 21 | pub const TUPLE_FIELD: Key<ast::TupleFieldDef, StructFieldId> = Key::new(); |
22 | pub const RECORD_FIELD: Key<ast::RecordFieldDef, StructFieldId> = Key::new(); | 22 | pub const RECORD_FIELD: Key<ast::RecordFieldDef, StructFieldId> = Key::new(); |
23 | pub const TYPE_PARAM: Key<ast::TypeParam, GenericParamId> = Key::new(); | 23 | pub const TYPE_PARAM: Key<ast::TypeParam, TypeParamId> = Key::new(); |
24 | 24 | ||
25 | /// XXX: AST Nodes and SyntaxNodes have identity equality semantics: nodes are | 25 | /// XXX: AST Nodes and SyntaxNodes have identity equality semantics: nodes are |
26 | /// equal if they point to exactly the same object. | 26 | /// equal if they point to exactly the same object. |
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 6dfb3c03d..569da4f28 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs | |||
@@ -318,14 +318,14 @@ macro_rules! impl_froms { | |||
318 | } | 318 | } |
319 | 319 | ||
320 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 320 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
321 | pub struct GenericParamId { | 321 | pub struct TypeParamId { |
322 | pub parent: GenericDefId, | 322 | pub parent: GenericDefId, |
323 | pub local_id: LocalGenericParamId, | 323 | pub local_id: LocalTypeParamId, |
324 | } | 324 | } |
325 | 325 | ||
326 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 326 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
327 | pub struct LocalGenericParamId(RawId); | 327 | pub struct LocalTypeParamId(RawId); |
328 | impl_arena_id!(LocalGenericParamId); | 328 | impl_arena_id!(LocalTypeParamId); |
329 | 329 | ||
330 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 330 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
331 | pub enum ContainerId { | 331 | pub enum ContainerId { |
diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs index e00bd03d5..4c859e497 100644 --- a/crates/ra_hir_def/src/resolver.rs +++ b/crates/ra_hir_def/src/resolver.rs | |||
@@ -18,8 +18,8 @@ use crate::{ | |||
18 | path::{Path, PathKind}, | 18 | path::{Path, PathKind}, |
19 | per_ns::PerNs, | 19 | per_ns::PerNs, |
20 | AdtId, AstItemDef, ConstId, ContainerId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, | 20 | AdtId, AstItemDef, ConstId, ContainerId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, |
21 | GenericDefId, GenericParamId, HasModule, ImplId, LocalModuleId, Lookup, ModuleDefId, ModuleId, | 21 | GenericDefId, HasModule, ImplId, LocalModuleId, Lookup, ModuleDefId, ModuleId, StaticId, |
22 | StaticId, StructId, TraitId, TypeAliasId, | 22 | StructId, TraitId, TypeAliasId, TypeParamId, |
23 | }; | 23 | }; |
24 | 24 | ||
25 | #[derive(Debug, Clone, Default)] | 25 | #[derive(Debug, Clone, Default)] |
@@ -59,7 +59,7 @@ enum Scope { | |||
59 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 59 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
60 | pub enum TypeNs { | 60 | pub enum TypeNs { |
61 | SelfType(ImplId), | 61 | SelfType(ImplId), |
62 | GenericParam(GenericParamId), | 62 | GenericParam(TypeParamId), |
63 | AdtId(AdtId), | 63 | AdtId(AdtId), |
64 | AdtSelfType(AdtId), | 64 | AdtSelfType(AdtId), |
65 | // Yup, enum variants are added to the types ns, but any usage of variant as | 65 | // Yup, enum variants are added to the types ns, but any usage of variant as |
@@ -157,7 +157,7 @@ impl Resolver { | |||
157 | if let Some(local_id) = params.find_by_name(first_name) { | 157 | if let Some(local_id) = params.find_by_name(first_name) { |
158 | let idx = if path.segments.len() == 1 { None } else { Some(1) }; | 158 | let idx = if path.segments.len() == 1 { None } else { Some(1) }; |
159 | return Some(( | 159 | return Some(( |
160 | TypeNs::GenericParam(GenericParamId { local_id, parent: *def }), | 160 | TypeNs::GenericParam(TypeParamId { local_id, parent: *def }), |
161 | idx, | 161 | idx, |
162 | )); | 162 | )); |
163 | } | 163 | } |
@@ -252,7 +252,7 @@ impl Resolver { | |||
252 | 252 | ||
253 | Scope::GenericParams { params, def } if n_segments > 1 => { | 253 | Scope::GenericParams { params, def } if n_segments > 1 => { |
254 | if let Some(local_id) = params.find_by_name(first_name) { | 254 | if let Some(local_id) = params.find_by_name(first_name) { |
255 | let ty = TypeNs::GenericParam(GenericParamId { local_id, parent: *def }); | 255 | let ty = TypeNs::GenericParam(TypeParamId { local_id, parent: *def }); |
256 | return Some(ResolveValueResult::Partial(ty, 1)); | 256 | return Some(ResolveValueResult::Partial(ty, 1)); |
257 | } | 257 | } |
258 | } | 258 | } |
@@ -399,7 +399,7 @@ pub enum ScopeDef { | |||
399 | PerNs(PerNs), | 399 | PerNs(PerNs), |
400 | ImplSelfType(ImplId), | 400 | ImplSelfType(ImplId), |
401 | AdtSelfType(AdtId), | 401 | AdtSelfType(AdtId), |
402 | GenericParam(GenericParamId), | 402 | GenericParam(TypeParamId), |
403 | Local(PatId), | 403 | Local(PatId), |
404 | } | 404 | } |
405 | 405 | ||
@@ -431,10 +431,10 @@ impl Scope { | |||
431 | } | 431 | } |
432 | } | 432 | } |
433 | Scope::GenericParams { params, def } => { | 433 | Scope::GenericParams { params, def } => { |
434 | for (local_id, param) in params.params.iter() { | 434 | for (local_id, param) in params.types.iter() { |
435 | f( | 435 | f( |
436 | param.name.clone(), | 436 | param.name.clone(), |
437 | ScopeDef::GenericParam(GenericParamId { local_id, parent: *def }), | 437 | ScopeDef::GenericParam(TypeParamId { local_id, parent: *def }), |
438 | ) | 438 | ) |
439 | } | 439 | } |
440 | } | 440 | } |
@@ -481,7 +481,7 @@ impl Resolver { | |||
481 | 481 | ||
482 | fn push_generic_params_scope(self, db: &impl DefDatabase, def: GenericDefId) -> Resolver { | 482 | fn push_generic_params_scope(self, db: &impl DefDatabase, def: GenericDefId) -> Resolver { |
483 | let params = db.generic_params(def); | 483 | let params = db.generic_params(def); |
484 | if params.params.is_empty() { | 484 | if params.types.is_empty() { |
485 | self | 485 | self |
486 | } else { | 486 | } else { |
487 | self.push_scope(Scope::GenericParams { def, params }) | 487 | self.push_scope(Scope::GenericParams { def, params }) |
diff --git a/crates/ra_hir_ty/src/utils.rs b/crates/ra_hir_ty/src/utils.rs index 936cfe25e..aeb211a91 100644 --- a/crates/ra_hir_ty/src/utils.rs +++ b/crates/ra_hir_ty/src/utils.rs | |||
@@ -5,10 +5,10 @@ use std::sync::Arc; | |||
5 | use hir_def::{ | 5 | use hir_def::{ |
6 | adt::VariantData, | 6 | adt::VariantData, |
7 | db::DefDatabase, | 7 | db::DefDatabase, |
8 | generics::{GenericParamData, GenericParams}, | 8 | generics::{GenericParams, TypeParamData}, |
9 | resolver::{HasResolver, TypeNs}, | 9 | resolver::{HasResolver, TypeNs}, |
10 | type_ref::TypeRef, | 10 | type_ref::TypeRef, |
11 | ContainerId, GenericDefId, GenericParamId, Lookup, TraitId, TypeAliasId, VariantId, | 11 | ContainerId, GenericDefId, Lookup, TraitId, TypeAliasId, TypeParamId, VariantId, |
12 | }; | 12 | }; |
13 | use hir_expand::name::{self, Name}; | 13 | use hir_expand::name::{self, Name}; |
14 | 14 | ||
@@ -96,23 +96,21 @@ pub(crate) struct Generics { | |||
96 | } | 96 | } |
97 | 97 | ||
98 | impl Generics { | 98 | impl Generics { |
99 | pub(crate) fn iter<'a>(&'a self) -> impl Iterator<Item = (u32, &'a GenericParamData)> + 'a { | 99 | pub(crate) fn iter<'a>(&'a self) -> impl Iterator<Item = (u32, &'a TypeParamData)> + 'a { |
100 | self.parent_generics | 100 | self.parent_generics |
101 | .as_ref() | 101 | .as_ref() |
102 | .into_iter() | 102 | .into_iter() |
103 | .flat_map(|it| it.params.params.iter()) | 103 | .flat_map(|it| it.params.types.iter()) |
104 | .chain(self.params.params.iter()) | 104 | .chain(self.params.types.iter()) |
105 | .enumerate() | 105 | .enumerate() |
106 | .map(|(i, (_local_id, p))| (i as u32, p)) | 106 | .map(|(i, (_local_id, p))| (i as u32, p)) |
107 | } | 107 | } |
108 | 108 | ||
109 | pub(crate) fn iter_parent<'a>( | 109 | pub(crate) fn iter_parent<'a>(&'a self) -> impl Iterator<Item = (u32, &'a TypeParamData)> + 'a { |
110 | &'a self, | ||
111 | ) -> impl Iterator<Item = (u32, &'a GenericParamData)> + 'a { | ||
112 | self.parent_generics | 110 | self.parent_generics |
113 | .as_ref() | 111 | .as_ref() |
114 | .into_iter() | 112 | .into_iter() |
115 | .flat_map(|it| it.params.params.iter()) | 113 | .flat_map(|it| it.params.types.iter()) |
116 | .enumerate() | 114 | .enumerate() |
117 | .map(|(i, (_local_id, p))| (i as u32, p)) | 115 | .map(|(i, (_local_id, p))| (i as u32, p)) |
118 | } | 116 | } |
@@ -123,20 +121,20 @@ impl Generics { | |||
123 | /// (total, parents, child) | 121 | /// (total, parents, child) |
124 | pub(crate) fn len_split(&self) -> (usize, usize, usize) { | 122 | pub(crate) fn len_split(&self) -> (usize, usize, usize) { |
125 | let parent = self.parent_generics.as_ref().map_or(0, |p| p.len()); | 123 | let parent = self.parent_generics.as_ref().map_or(0, |p| p.len()); |
126 | let child = self.params.params.len(); | 124 | let child = self.params.types.len(); |
127 | (parent + child, parent, child) | 125 | (parent + child, parent, child) |
128 | } | 126 | } |
129 | pub(crate) fn param_idx(&self, param: GenericParamId) -> u32 { | 127 | pub(crate) fn param_idx(&self, param: TypeParamId) -> u32 { |
130 | self.find_param(param).0 | 128 | self.find_param(param).0 |
131 | } | 129 | } |
132 | pub(crate) fn param_name(&self, param: GenericParamId) -> Name { | 130 | pub(crate) fn param_name(&self, param: TypeParamId) -> Name { |
133 | self.find_param(param).1.name.clone() | 131 | self.find_param(param).1.name.clone() |
134 | } | 132 | } |
135 | fn find_param(&self, param: GenericParamId) -> (u32, &GenericParamData) { | 133 | fn find_param(&self, param: TypeParamId) -> (u32, &TypeParamData) { |
136 | if param.parent == self.def { | 134 | if param.parent == self.def { |
137 | let (idx, (_local_id, data)) = self | 135 | let (idx, (_local_id, data)) = self |
138 | .params | 136 | .params |
139 | .params | 137 | .types |
140 | .iter() | 138 | .iter() |
141 | .enumerate() | 139 | .enumerate() |
142 | .find(|(_, (idx, _))| *idx == param.local_id) | 140 | .find(|(_, (idx, _))| *idx == param.local_id) |
diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs index e8c3d980f..6a6b49afd 100644 --- a/crates/ra_ide/src/display/navigation_target.rs +++ b/crates/ra_ide/src/display/navigation_target.rs | |||
@@ -351,7 +351,7 @@ impl ToNav for hir::Local { | |||
351 | } | 351 | } |
352 | } | 352 | } |
353 | 353 | ||
354 | impl ToNav for hir::GenericParam { | 354 | impl ToNav for hir::TypeParam { |
355 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { | 355 | fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { |
356 | let src = self.source(db); | 356 | let src = self.source(db); |
357 | let range = match src.value { | 357 | let range = match src.value { |
diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index 64c0cbad4..1b968134d 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs | |||
@@ -66,7 +66,7 @@ pub(crate) fn reference_definition( | |||
66 | match name_kind { | 66 | match name_kind { |
67 | Some(Macro(it)) => return Exact(it.to_nav(db)), | 67 | Some(Macro(it)) => return Exact(it.to_nav(db)), |
68 | Some(Field(it)) => return Exact(it.to_nav(db)), | 68 | Some(Field(it)) => return Exact(it.to_nav(db)), |
69 | Some(GenericParam(it)) => return Exact(it.to_nav(db)), | 69 | Some(TypeParam(it)) => return Exact(it.to_nav(db)), |
70 | Some(AssocItem(it)) => return Exact(it.to_nav(db)), | 70 | Some(AssocItem(it)) => return Exact(it.to_nav(db)), |
71 | Some(Local(it)) => return Exact(it.to_nav(db)), | 71 | Some(Local(it)) => return Exact(it.to_nav(db)), |
72 | Some(Def(def)) => match NavigationTarget::from_def(db, def) { | 72 | Some(Def(def)) => match NavigationTarget::from_def(db, def) { |
diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs index d8185c688..d372ca758 100644 --- a/crates/ra_ide/src/hover.rs +++ b/crates/ra_ide/src/hover.rs | |||
@@ -138,7 +138,7 @@ fn hover_text_from_name_kind( | |||
138 | *no_fallback = true; | 138 | *no_fallback = true; |
139 | None | 139 | None |
140 | } | 140 | } |
141 | GenericParam(_) | SelfType(_) => { | 141 | TypeParam(_) | SelfType(_) => { |
142 | // FIXME: Hover for generic param | 142 | // FIXME: Hover for generic param |
143 | None | 143 | None |
144 | } | 144 | } |
diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs index 3e7bfd872..e3ecde50d 100644 --- a/crates/ra_ide/src/references.rs +++ b/crates/ra_ide/src/references.rs | |||
@@ -85,7 +85,7 @@ pub(crate) fn find_all_refs( | |||
85 | NameKind::Def(def) => NavigationTarget::from_def(db, def)?, | 85 | NameKind::Def(def) => NavigationTarget::from_def(db, def)?, |
86 | NameKind::SelfType(imp) => imp.to_nav(db), | 86 | NameKind::SelfType(imp) => imp.to_nav(db), |
87 | NameKind::Local(local) => local.to_nav(db), | 87 | NameKind::Local(local) => local.to_nav(db), |
88 | NameKind::GenericParam(_) => return None, | 88 | NameKind::TypeParam(_) => return None, |
89 | }; | 89 | }; |
90 | 90 | ||
91 | let search_scope = { | 91 | let search_scope = { |
diff --git a/crates/ra_ide/src/references/classify.rs b/crates/ra_ide/src/references/classify.rs index ed98dbc13..c1f091ec0 100644 --- a/crates/ra_ide/src/references/classify.rs +++ b/crates/ra_ide/src/references/classify.rs | |||
@@ -112,11 +112,11 @@ pub(crate) fn classify_name(db: &RootDatabase, name: InFile<&ast::Name>) -> Opti | |||
112 | }, | 112 | }, |
113 | ast::TypeParam(it) => { | 113 | ast::TypeParam(it) => { |
114 | let src = name.with_value(it); | 114 | let src = name.with_value(it); |
115 | let def = hir::GenericParam::from_source(db, src)?; | 115 | let def = hir::TypeParam::from_source(db, src)?; |
116 | Some(NameDefinition { | 116 | Some(NameDefinition { |
117 | visibility: None, | 117 | visibility: None, |
118 | container: def.module(db), | 118 | container: def.module(db), |
119 | kind: NameKind::GenericParam(def), | 119 | kind: NameKind::TypeParam(def), |
120 | }) | 120 | }) |
121 | }, | 121 | }, |
122 | _ => None, | 122 | _ => None, |
@@ -177,8 +177,8 @@ pub(crate) fn classify_name_ref( | |||
177 | let kind = NameKind::Local(local); | 177 | let kind = NameKind::Local(local); |
178 | Some(NameDefinition { kind, container, visibility: None }) | 178 | Some(NameDefinition { kind, container, visibility: None }) |
179 | } | 179 | } |
180 | PathResolution::GenericParam(par) => { | 180 | PathResolution::TypeParam(par) => { |
181 | let kind = NameKind::GenericParam(par); | 181 | let kind = NameKind::TypeParam(par); |
182 | Some(NameDefinition { kind, container, visibility }) | 182 | Some(NameDefinition { kind, container, visibility }) |
183 | } | 183 | } |
184 | PathResolution::Macro(def) => { | 184 | PathResolution::Macro(def) => { |
diff --git a/crates/ra_ide/src/references/name_definition.rs b/crates/ra_ide/src/references/name_definition.rs index 10d3a2364..8c67c8863 100644 --- a/crates/ra_ide/src/references/name_definition.rs +++ b/crates/ra_ide/src/references/name_definition.rs | |||
@@ -4,8 +4,8 @@ | |||
4 | //! Note that the reference search is possible for not all of the classified items. | 4 | //! Note that the reference search is possible for not all of the classified items. |
5 | 5 | ||
6 | use hir::{ | 6 | use hir::{ |
7 | Adt, AssocItem, GenericParam, HasSource, ImplBlock, Local, MacroDef, Module, ModuleDef, | 7 | Adt, AssocItem, HasSource, ImplBlock, Local, MacroDef, Module, ModuleDef, StructField, |
8 | StructField, VariantDef, | 8 | TypeParam, VariantDef, |
9 | }; | 9 | }; |
10 | use ra_syntax::{ast, ast::VisibilityOwner}; | 10 | use ra_syntax::{ast, ast::VisibilityOwner}; |
11 | 11 | ||
@@ -19,7 +19,7 @@ pub enum NameKind { | |||
19 | Def(ModuleDef), | 19 | Def(ModuleDef), |
20 | SelfType(ImplBlock), | 20 | SelfType(ImplBlock), |
21 | Local(Local), | 21 | Local(Local), |
22 | GenericParam(GenericParam), | 22 | TypeParam(TypeParam), |
23 | } | 23 | } |
24 | 24 | ||
25 | #[derive(PartialEq, Eq)] | 25 | #[derive(PartialEq, Eq)] |
diff --git a/crates/ra_ide/src/snapshots/rainbow_highlighting.html b/crates/ra_ide/src/snapshots/rainbow_highlighting.html index 79f11ea80..9dfbc8047 100644 --- a/crates/ra_ide/src/snapshots/rainbow_highlighting.html +++ b/crates/ra_ide/src/snapshots/rainbow_highlighting.html | |||
@@ -9,6 +9,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd | |||
9 | .parameter { color: #94BFF3; } | 9 | .parameter { color: #94BFF3; } |
10 | .builtin { color: #DD6718; } | 10 | .builtin { color: #DD6718; } |
11 | .text { color: #DCDCCC; } | 11 | .text { color: #DCDCCC; } |
12 | .type { color: #7CB8BB; } | ||
12 | .attribute { color: #94BFF3; } | 13 | .attribute { color: #94BFF3; } |
13 | .literal { color: #BFEBBF; } | 14 | .literal { color: #BFEBBF; } |
14 | .macro { color: #94BFF3; } | 15 | .macro { color: #94BFF3; } |
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 20eefeb57..7ecb1a027 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs | |||
@@ -225,8 +225,7 @@ fn highlight_name(db: &RootDatabase, name_kind: NameKind) -> &'static str { | |||
225 | Def(hir::ModuleDef::Trait(_)) => "type", | 225 | Def(hir::ModuleDef::Trait(_)) => "type", |
226 | Def(hir::ModuleDef::TypeAlias(_)) => "type", | 226 | Def(hir::ModuleDef::TypeAlias(_)) => "type", |
227 | Def(hir::ModuleDef::BuiltinType(_)) => "type", | 227 | Def(hir::ModuleDef::BuiltinType(_)) => "type", |
228 | SelfType(_) => "type", | 228 | SelfType(_) | TypeParam(_) => "type", |
229 | GenericParam(_) => "type", | ||
230 | Local(local) => { | 229 | Local(local) => { |
231 | if local.is_mut(db) { | 230 | if local.is_mut(db) { |
232 | "variable.mut" | 231 | "variable.mut" |