aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-11-11 16:21:55 +0000
committerGitHub <[email protected]>2019-11-11 16:21:55 +0000
commitf742803c6a5a632af6e0aecb123920d1962e5fee (patch)
tree1b0f7c7b0f430d4174ca05e5464b3af98128bafe
parenta599147b4232c0d4f6b071a3a96e86f903f4cf52 (diff)
parentc5a18c44e5211282c22b9ca7aae8700ee8ca1817 (diff)
Merge #2213
2213: Hir generic param r=flodiebold a=matklad r? @flodiebold This should make the life of IDE easier: before, it got `GenericParam(u32)` which was of questionable utility. Now, it's a proper code_model type, so it can gain `source`, `name`, `module` and all the other hir methods, should the IDE need them. Moreover, IDE now doesn't care about internal representation of generic param, which seems like a long-term win. The problem is, of course, that we now have to types named `GenericParam` in hir: this code_model type, and an internal type with an index which doesn't know about the parent. I think it's fine for the time being, but, after we finish cratefication of hir, this local `GenericParam` should move to `hir_def` or `hir_ty`, and *maybe* restrucured as `ParamId / PramData` pair. Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r--crates/ra_hir/src/code_model.rs8
-rw-r--r--crates/ra_hir/src/lib.rs8
-rw-r--r--crates/ra_hir/src/source_binder.rs11
-rw-r--r--crates/ra_hir/src/ty.rs12
-rw-r--r--crates/ra_hir/src/ty/autoderef.rs2
-rw-r--r--crates/ra_hir/src/ty/infer/path.rs3
-rw-r--r--crates/ra_hir/src/ty/traits/chalk.rs4
-rw-r--r--crates/ra_ide_api/src/references/name_definition.rs5
8 files changed, 32 insertions, 21 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 806f1daed..92d71b9e8 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -39,7 +39,7 @@ mod ty;
39mod impl_block; 39mod impl_block;
40mod expr; 40mod expr;
41mod lang_item; 41mod lang_item;
42mod generics; 42pub mod generics;
43mod resolve; 43mod resolve;
44pub mod diagnostics; 44pub mod diagnostics;
45mod util; 45mod util;
@@ -65,12 +65,12 @@ 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,
73 generics::{GenericDef, GenericParam, GenericParams, HasGenericParams}, 73 generics::GenericDef,
74 ids::{HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFile}, 74 ids::{HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFile},
75 impl_block::ImplBlock, 75 impl_block::ImplBlock,
76 resolve::ScopeDef, 76 resolve::ScopeDef,
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()),
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index cd2ac0e8b..6f24cfad6 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -17,8 +17,11 @@ use std::sync::Arc;
17use std::{fmt, iter, mem}; 17use std::{fmt, iter, mem};
18 18
19use crate::{ 19use crate::{
20 db::HirDatabase, expr::ExprId, util::make_mut_slice, Adt, Crate, DefWithBody, GenericParams, 20 db::HirDatabase,
21 HasGenericParams, Mutability, Name, Trait, TypeAlias, 21 expr::ExprId,
22 generics::{GenericParams, HasGenericParams},
23 util::make_mut_slice,
24 Adt, Crate, DefWithBody, Mutability, Name, Trait, TypeAlias,
22}; 25};
23use display::{HirDisplay, HirFormatter}; 26use display::{HirDisplay, HirFormatter};
24 27
@@ -342,10 +345,7 @@ impl Substs {
342 ) 345 )
343 } 346 }
344 347
345 pub fn build_for_def( 348 pub fn build_for_def(db: &impl HirDatabase, def: impl HasGenericParams) -> SubstsBuilder {
346 db: &impl HirDatabase,
347 def: impl crate::HasGenericParams,
348 ) -> SubstsBuilder {
349 let params = def.generic_params(db); 349 let params = def.generic_params(db);
350 let param_count = params.count_params_including_parent(); 350 let param_count = params.count_params_including_parent();
351 Substs::builder(param_count) 351 Substs::builder(param_count)
diff --git a/crates/ra_hir/src/ty/autoderef.rs b/crates/ra_hir/src/ty/autoderef.rs
index 3645ee831..872a4517d 100644
--- a/crates/ra_hir/src/ty/autoderef.rs
+++ b/crates/ra_hir/src/ty/autoderef.rs
@@ -9,7 +9,7 @@ use hir_expand::name;
9use log::{info, warn}; 9use log::{info, warn};
10 10
11use super::{traits::Solution, Canonical, Substs, Ty, TypeWalk}; 11use super::{traits::Solution, Canonical, Substs, Ty, TypeWalk};
12use crate::{db::HirDatabase, HasGenericParams, Resolver}; 12use crate::{db::HirDatabase, generics::HasGenericParams, Resolver};
13 13
14const AUTODEREF_RECURSION_LIMIT: usize = 10; 14const AUTODEREF_RECURSION_LIMIT: usize = 10;
15 15
diff --git a/crates/ra_hir/src/ty/infer/path.rs b/crates/ra_hir/src/ty/infer/path.rs
index 865ced5a1..31ca675aa 100644
--- a/crates/ra_hir/src/ty/infer/path.rs
+++ b/crates/ra_hir/src/ty/infer/path.rs
@@ -5,9 +5,10 @@ use hir_def::path::PathSegment;
5use super::{ExprOrPatId, InferenceContext, TraitRef}; 5use super::{ExprOrPatId, InferenceContext, TraitRef};
6use crate::{ 6use crate::{
7 db::HirDatabase, 7 db::HirDatabase,
8 generics::HasGenericParams,
8 resolve::{ResolveValueResult, Resolver, TypeNs, ValueNs}, 9 resolve::{ResolveValueResult, Resolver, TypeNs, ValueNs},
9 ty::{method_resolution, Namespace, Substs, Ty, TypableDef, TypeWalk}, 10 ty::{method_resolution, Namespace, Substs, Ty, TypableDef, TypeWalk},
10 AssocItem, Container, HasGenericParams, Name, Path, 11 AssocItem, Container, Name, Path,
11}; 12};
12 13
13impl<'a, D: HirDatabase> InferenceContext<'a, D> { 14impl<'a, D: HirDatabase> InferenceContext<'a, D> {
diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs
index c694952f3..14c54b9fb 100644
--- a/crates/ra_hir/src/ty/traits/chalk.rs
+++ b/crates/ra_hir/src/ty/traits/chalk.rs
@@ -16,13 +16,13 @@ use ra_db::salsa::{InternId, InternKey};
16use super::{Canonical, ChalkContext, Impl, Obligation}; 16use super::{Canonical, ChalkContext, Impl, Obligation};
17use crate::{ 17use crate::{
18 db::HirDatabase, 18 db::HirDatabase,
19 generics::GenericDef, 19 generics::{GenericDef, HasGenericParams},
20 ty::display::HirDisplay, 20 ty::display::HirDisplay,
21 ty::{ 21 ty::{
22 ApplicationTy, GenericPredicate, Namespace, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, 22 ApplicationTy, GenericPredicate, Namespace, ProjectionTy, Substs, TraitRef, Ty, TypeCtor,
23 TypeWalk, 23 TypeWalk,
24 }, 24 },
25 AssocItem, Crate, HasGenericParams, ImplBlock, Trait, TypeAlias, 25 AssocItem, Crate, ImplBlock, Trait, TypeAlias,
26}; 26};
27 27
28/// This represents a trait whose name we could not resolve. 28/// This represents a trait whose name we could not resolve.
diff --git a/crates/ra_ide_api/src/references/name_definition.rs b/crates/ra_ide_api/src/references/name_definition.rs
index 450f7ea9b..ccd75278a 100644
--- a/crates/ra_ide_api/src/references/name_definition.rs
+++ b/crates/ra_ide_api/src/references/name_definition.rs
@@ -4,7 +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
6use hir::{ 6use hir::{
7 Adt, AssocItem, HasSource, Local, MacroDef, Module, ModuleDef, StructField, Ty, VariantDef, 7 Adt, AssocItem, GenericParam, HasSource, Local, MacroDef, Module, ModuleDef, StructField, Ty,
8 VariantDef,
8}; 9};
9use ra_syntax::{ast, ast::VisibilityOwner}; 10use ra_syntax::{ast, ast::VisibilityOwner};
10 11
@@ -18,7 +19,7 @@ pub enum NameKind {
18 Def(ModuleDef), 19 Def(ModuleDef),
19 SelfType(Ty), 20 SelfType(Ty),
20 Local(Local), 21 Local(Local),
21 GenericParam(u32), 22 GenericParam(GenericParam),
22} 23}
23 24
24#[derive(PartialEq, Eq)] 25#[derive(PartialEq, Eq)]