aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/code_model_api.rs22
-rw-r--r--crates/ra_hir/src/db.rs8
-rw-r--r--crates/ra_hir/src/generics.rs13
-rw-r--r--crates/ra_hir/src/impl_block.rs16
-rw-r--r--crates/ra_hir/src/lib.rs2
-rw-r--r--crates/ra_hir/src/nameres/lower.rs4
-rw-r--r--crates/ra_hir/src/ty/infer.rs4
-rw-r--r--crates/ra_hir/src/ty/lower.rs18
-rw-r--r--crates/ra_hir/src/type_alias.rs7
9 files changed, 54 insertions, 40 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs
index 29c08e34b..278407504 100644
--- a/crates/ra_hir/src/code_model_api.rs
+++ b/crates/ra_hir/src/code_model_api.rs
@@ -85,9 +85,19 @@ pub enum ModuleDef {
85 Const(Const), 85 Const(Const),
86 Static(Static), 86 Static(Static),
87 Trait(Trait), 87 Trait(Trait),
88 Type(Type), 88 TypeAlias(TypeAlias),
89} 89}
90impl_froms!(ModuleDef: Module, Function, Struct, Enum, EnumVariant, Const, Static, Trait, Type); 90impl_froms!(
91 ModuleDef: Module,
92 Function,
93 Struct,
94 Enum,
95 EnumVariant,
96 Const,
97 Static,
98 Trait,
99 TypeAlias
100);
91 101
92pub enum ModuleSource { 102pub enum ModuleSource {
93 SourceFile(TreeArc<ast::SourceFile>), 103 SourceFile(TreeArc<ast::SourceFile>),
@@ -604,11 +614,11 @@ impl Docs for Trait {
604} 614}
605 615
606#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 616#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
607pub struct Type { 617pub struct TypeAlias {
608 pub(crate) id: TypeId, 618 pub(crate) id: TypeId,
609} 619}
610 620
611impl Type { 621impl TypeAlias {
612 pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::TypeDef>) { 622 pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::TypeDef>) {
613 self.id.source(db) 623 self.id.source(db)
614 } 624 }
@@ -645,7 +655,7 @@ impl Type {
645 } 655 }
646} 656}
647 657
648impl Docs for Type { 658impl Docs for TypeAlias {
649 fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> { 659 fn docs(&self, db: &impl HirDatabase) -> Option<Documentation> {
650 docs_from_ast(&*self.source(db).1) 660 docs_from_ast(&*self.source(db).1)
651 } 661 }
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs
index b8bd82f0c..b8715abab 100644
--- a/crates/ra_hir/src/db.rs
+++ b/crates/ra_hir/src/db.rs
@@ -6,7 +6,7 @@ use ra_db::{SourceDatabase, salsa};
6use crate::{ 6use crate::{
7 MacroCallId, HirFileId, 7 MacroCallId, HirFileId,
8 SourceFileItems, SourceItemId, Crate, Module, HirInterner, 8 SourceFileItems, SourceItemId, Crate, Module, HirInterner,
9 Function, FnSignature, ExprScopes, 9 Function, FnSignature, ExprScopes, TypeAlias,
10 Struct, Enum, StructField, 10 Struct, Enum, StructField,
11 macros::MacroExpansion, 11 macros::MacroExpansion,
12 module_tree::ModuleTree, 12 module_tree::ModuleTree,
@@ -15,7 +15,9 @@ use crate::{
15 adt::{StructData, EnumData}, 15 adt::{StructData, EnumData},
16 impl_block::{ModuleImplBlocks, ImplSourceMap}, 16 impl_block::{ModuleImplBlocks, ImplSourceMap},
17 generics::{GenericParams, GenericDef}, 17 generics::{GenericParams, GenericDef},
18 ids::SourceFileItemId, nameres::Namespace, type_ref::TypeRef, code_model_api::Type 18 ids::SourceFileItemId,
19 nameres::Namespace,
20 type_ref::TypeRef,
19}; 21};
20 22
21#[salsa::query_group(PersistentHirDatabaseStorage)] 23#[salsa::query_group(PersistentHirDatabaseStorage)]
@@ -79,7 +81,7 @@ pub trait PersistentHirDatabase: SourceDatabase + AsRef<HirInterner> {
79 fn fn_signature(&self, func: Function) -> Arc<FnSignature>; 81 fn fn_signature(&self, func: Function) -> Arc<FnSignature>;
80 82
81 #[salsa::invoke(crate::type_alias::type_alias_ref_query)] 83 #[salsa::invoke(crate::type_alias::type_alias_ref_query)]
82 fn type_alias_ref(&self, typ: Type) -> Arc<TypeRef>; 84 fn type_alias_ref(&self, typ: TypeAlias) -> Arc<TypeRef>;
83} 85}
84 86
85#[salsa::query_group(HirDatabaseStorage)] 87#[salsa::query_group(HirDatabaseStorage)]
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs
index c494beeb0..0f759a235 100644
--- a/crates/ra_hir/src/generics.rs
+++ b/crates/ra_hir/src/generics.rs
@@ -7,7 +7,10 @@ use std::sync::Arc;
7 7
8use ra_syntax::ast::{self, NameOwner, TypeParamsOwner}; 8use ra_syntax::ast::{self, NameOwner, TypeParamsOwner};
9 9
10use crate::{db::PersistentHirDatabase, Name, AsName, Function, Struct, Enum, Trait, Type, ImplBlock}; 10use crate::{
11 db::PersistentHirDatabase,
12 Name, AsName, Function, Struct, Enum, Trait, TypeAlias, ImplBlock
13};
11 14
12/// Data about a generic parameter (to a function, struct, impl, ...). 15/// Data about a generic parameter (to a function, struct, impl, ...).
13#[derive(Clone, PartialEq, Eq, Debug)] 16#[derive(Clone, PartialEq, Eq, Debug)]
@@ -30,10 +33,10 @@ pub enum GenericDef {
30 Struct(Struct), 33 Struct(Struct),
31 Enum(Enum), 34 Enum(Enum),
32 Trait(Trait), 35 Trait(Trait),
33 Type(Type), 36 TypeAlias(TypeAlias),
34 ImplBlock(ImplBlock), 37 ImplBlock(ImplBlock),
35} 38}
36impl_froms!(GenericDef: Function, Struct, Enum, Trait, Type, ImplBlock); 39impl_froms!(GenericDef: Function, Struct, Enum, Trait, TypeAlias, ImplBlock);
37 40
38impl GenericParams { 41impl GenericParams {
39 pub(crate) fn generic_params_query( 42 pub(crate) fn generic_params_query(
@@ -43,7 +46,7 @@ impl GenericParams {
43 let mut generics = GenericParams::default(); 46 let mut generics = GenericParams::default();
44 let parent = match def { 47 let parent = match def {
45 GenericDef::Function(it) => it.impl_block(db), 48 GenericDef::Function(it) => it.impl_block(db),
46 GenericDef::Type(it) => it.impl_block(db), 49 GenericDef::TypeAlias(it) => it.impl_block(db),
47 GenericDef::Struct(_) | GenericDef::Enum(_) | GenericDef::Trait(_) => None, 50 GenericDef::Struct(_) | GenericDef::Enum(_) | GenericDef::Trait(_) => None,
48 GenericDef::ImplBlock(_) => None, 51 GenericDef::ImplBlock(_) => None,
49 }; 52 };
@@ -54,7 +57,7 @@ impl GenericParams {
54 GenericDef::Struct(it) => generics.fill(&*it.source(db).1, start), 57 GenericDef::Struct(it) => generics.fill(&*it.source(db).1, start),
55 GenericDef::Enum(it) => generics.fill(&*it.source(db).1, start), 58 GenericDef::Enum(it) => generics.fill(&*it.source(db).1, start),
56 GenericDef::Trait(it) => generics.fill(&*it.source(db).1, start), 59 GenericDef::Trait(it) => generics.fill(&*it.source(db).1, start),
57 GenericDef::Type(it) => generics.fill(&*it.source(db).1, start), 60 GenericDef::TypeAlias(it) => generics.fill(&*it.source(db).1, start),
58 GenericDef::ImplBlock(it) => generics.fill(&*it.source(db).1, start), 61 GenericDef::ImplBlock(it) => generics.fill(&*it.source(db).1, start),
59 } 62 }
60 63
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs
index 7ecf8c368..2f3c916fd 100644
--- a/crates/ra_hir/src/impl_block.rs
+++ b/crates/ra_hir/src/impl_block.rs
@@ -7,7 +7,7 @@ use ra_syntax::{
7ast::{self, AstNode}}; 7ast::{self, AstNode}};
8 8
9use crate::{ 9use crate::{
10 Const, Type, Function, HirFileId, 10 Const, TypeAlias, Function, HirFileId,
11 HirDatabase, PersistentHirDatabase, 11 HirDatabase, PersistentHirDatabase,
12 ModuleDef, Trait, Resolution, 12 ModuleDef, Trait, Resolution,
13 type_ref::TypeRef, 13 type_ref::TypeRef,
@@ -135,13 +135,9 @@ impl ImplData {
135 item_list 135 item_list
136 .impl_items() 136 .impl_items()
137 .map(|item_node| match item_node.kind() { 137 .map(|item_node| match item_node.kind() {
138 ast::ImplItemKind::FnDef(it) => { 138 ast::ImplItemKind::FnDef(it) => Function { id: ctx.to_def(it) }.into(),
139 ImplItem::Method(Function { id: ctx.to_def(it) }) 139 ast::ImplItemKind::ConstDef(it) => Const { id: ctx.to_def(it) }.into(),
140 } 140 ast::ImplItemKind::TypeDef(it) => TypeAlias { id: ctx.to_def(it) }.into(),
141 ast::ImplItemKind::ConstDef(it) => {
142 ImplItem::Const(Const { id: ctx.to_def(it) })
143 }
144 ast::ImplItemKind::TypeDef(it) => ImplItem::Type(Type { id: ctx.to_def(it) }),
145 }) 141 })
146 .collect() 142 .collect()
147 } else { 143 } else {
@@ -168,10 +164,10 @@ impl ImplData {
168pub enum ImplItem { 164pub enum ImplItem {
169 Method(Function), 165 Method(Function),
170 Const(Const), 166 Const(Const),
171 Type(Type), 167 TypeAlias(TypeAlias),
172 // Existential 168 // Existential
173} 169}
174impl_froms!(ImplItem: Const, Type); 170impl_froms!(ImplItem: Const, TypeAlias);
175 171
176impl From<Function> for ImplItem { 172impl From<Function> for ImplItem {
177 fn from(func: Function) -> ImplItem { 173 fn from(func: Function) -> ImplItem {
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 78fa4952b..aa5fc5607 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -72,5 +72,5 @@ pub use self::code_model_api::{
72 Function, FnSignature, 72 Function, FnSignature,
73 StructField, FieldSource, 73 StructField, FieldSource,
74 Static, Const, 74 Static, Const,
75 Trait, Type, 75 Trait, TypeAlias,
76}; 76};
diff --git a/crates/ra_hir/src/nameres/lower.rs b/crates/ra_hir/src/nameres/lower.rs
index 81d80654c..522f13b44 100644
--- a/crates/ra_hir/src/nameres/lower.rs
+++ b/crates/ra_hir/src/nameres/lower.rs
@@ -10,7 +10,7 @@ use rustc_hash::FxHashMap;
10use crate::{ 10use crate::{
11 SourceItemId, Path, ModuleSource, Name, 11 SourceItemId, Path, ModuleSource, Name,
12 HirFileId, MacroCallLoc, AsName, PerNs, Function, 12 HirFileId, MacroCallLoc, AsName, PerNs, Function,
13 ModuleDef, Module, Struct, Enum, Const, Static, Trait, Type, 13 ModuleDef, Module, Struct, Enum, Const, Static, Trait, TypeAlias,
14 ids::LocationCtx, PersistentHirDatabase, 14 ids::LocationCtx, PersistentHirDatabase,
15}; 15};
16 16
@@ -169,7 +169,7 @@ impl LoweredModule {
169 } 169 }
170 ast::ModuleItemKind::TypeDef(it) => { 170 ast::ModuleItemKind::TypeDef(it) => {
171 if let Some(name) = it.name() { 171 if let Some(name) = it.name() {
172 let t = Type { id: ctx.to_def(it) }; 172 let t = TypeAlias { id: ctx.to_def(it) };
173 self.declarations.insert(name.as_name(), PerNs::types(t.into())); 173 self.declarations.insert(name.as_name(), PerNs::types(t.into()));
174 } 174 }
175 } 175 }
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs
index 29331bea5..921130b71 100644
--- a/crates/ra_hir/src/ty/infer.rs
+++ b/crates/ra_hir/src/ty/infer.rs
@@ -406,7 +406,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
406 crate::ImplItem::Const(_) => None, 406 crate::ImplItem::Const(_) => None,
407 407
408 // TODO: Resolve associated types 408 // TODO: Resolve associated types
409 crate::ImplItem::Type(_) => None, 409 crate::ImplItem::TypeAlias(_) => None,
410 })?; 410 })?;
411 resolved = Resolution::Def(item.into()); 411 resolved = Resolution::Def(item.into());
412 } 412 }
@@ -477,7 +477,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
477 let ty = self.insert_type_vars(ty.apply_substs(substs)); 477 let ty = self.insert_type_vars(ty.apply_substs(substs));
478 (ty, Some(var.into())) 478 (ty, Some(var.into()))
479 } 479 }
480 TypableDef::Type(_) | TypableDef::Function(_) | TypableDef::Enum(_) => { 480 TypableDef::TypeAlias(_) | TypableDef::Function(_) | TypableDef::Enum(_) => {
481 (Ty::Unknown, None) 481 (Ty::Unknown, None)
482 } 482 }
483 } 483 }
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs
index a11d964c8..b66b8e4a5 100644
--- a/crates/ra_hir/src/ty/lower.rs
+++ b/crates/ra_hir/src/ty/lower.rs
@@ -10,7 +10,7 @@ use std::sync::Arc;
10 10
11use crate::{ 11use crate::{
12 Function, Struct, StructField, Enum, EnumVariant, Path, Name, 12 Function, Struct, StructField, Enum, EnumVariant, Path, Name,
13 ModuleDef, Type, 13 ModuleDef, TypeAlias,
14 HirDatabase, 14 HirDatabase,
15 type_ref::TypeRef, 15 type_ref::TypeRef,
16 name::KnownName, 16 name::KnownName,
@@ -124,7 +124,7 @@ impl Ty {
124 TypableDef::Struct(s) => s.generic_params(db), 124 TypableDef::Struct(s) => s.generic_params(db),
125 TypableDef::Enum(e) => e.generic_params(db), 125 TypableDef::Enum(e) => e.generic_params(db),
126 TypableDef::EnumVariant(var) => var.parent_enum(db).generic_params(db), 126 TypableDef::EnumVariant(var) => var.parent_enum(db).generic_params(db),
127 TypableDef::Type(t) => t.generic_params(db), 127 TypableDef::TypeAlias(t) => t.generic_params(db),
128 }; 128 };
129 let parent_param_count = def_generics.count_parent_params(); 129 let parent_param_count = def_generics.count_parent_params();
130 substs.extend((0..parent_param_count).map(|_| Ty::Unknown)); 130 substs.extend((0..parent_param_count).map(|_| Ty::Unknown));
@@ -163,7 +163,7 @@ impl Ty {
163 TypableDef::Function(_) 163 TypableDef::Function(_)
164 | TypableDef::Struct(_) 164 | TypableDef::Struct(_)
165 | TypableDef::Enum(_) 165 | TypableDef::Enum(_)
166 | TypableDef::Type(_) => last, 166 | TypableDef::TypeAlias(_) => last,
167 TypableDef::EnumVariant(_) => { 167 TypableDef::EnumVariant(_) => {
168 // the generic args for an enum variant may be either specified 168 // the generic args for an enum variant may be either specified
169 // on the segment referring to the enum, or on the segment 169 // on the segment referring to the enum, or on the segment
@@ -196,13 +196,13 @@ pub(crate) fn type_for_def(db: &impl HirDatabase, def: TypableDef, ns: Namespace
196 (TypableDef::Struct(s), Namespace::Values) => type_for_struct_constructor(db, s), 196 (TypableDef::Struct(s), Namespace::Values) => type_for_struct_constructor(db, s),
197 (TypableDef::Enum(e), Namespace::Types) => type_for_enum(db, e), 197 (TypableDef::Enum(e), Namespace::Types) => type_for_enum(db, e),
198 (TypableDef::EnumVariant(v), Namespace::Values) => type_for_enum_variant_constructor(db, v), 198 (TypableDef::EnumVariant(v), Namespace::Values) => type_for_enum_variant_constructor(db, v),
199 (TypableDef::Type(t), Namespace::Types) => type_for_type_alias(db, t), 199 (TypableDef::TypeAlias(t), Namespace::Types) => type_for_type_alias(db, t),
200 200
201 // 'error' cases: 201 // 'error' cases:
202 (TypableDef::Function(_), Namespace::Types) => Ty::Unknown, 202 (TypableDef::Function(_), Namespace::Types) => Ty::Unknown,
203 (TypableDef::Enum(_), Namespace::Values) => Ty::Unknown, 203 (TypableDef::Enum(_), Namespace::Values) => Ty::Unknown,
204 (TypableDef::EnumVariant(_), Namespace::Types) => Ty::Unknown, 204 (TypableDef::EnumVariant(_), Namespace::Types) => Ty::Unknown,
205 (TypableDef::Type(_), Namespace::Values) => Ty::Unknown, 205 (TypableDef::TypeAlias(_), Namespace::Values) => Ty::Unknown,
206 } 206 }
207} 207}
208 208
@@ -302,7 +302,7 @@ fn type_for_enum(db: &impl HirDatabase, s: Enum) -> Ty {
302 } 302 }
303} 303}
304 304
305fn type_for_type_alias(db: &impl HirDatabase, t: Type) -> Ty { 305fn type_for_type_alias(db: &impl HirDatabase, t: TypeAlias) -> Ty {
306 let generics = t.generic_params(db); 306 let generics = t.generic_params(db);
307 let resolver = t.resolver(db); 307 let resolver = t.resolver(db);
308 let type_ref = t.type_ref(db); 308 let type_ref = t.type_ref(db);
@@ -317,9 +317,9 @@ pub enum TypableDef {
317 Struct(Struct), 317 Struct(Struct),
318 Enum(Enum), 318 Enum(Enum),
319 EnumVariant(EnumVariant), 319 EnumVariant(EnumVariant),
320 Type(Type), 320 TypeAlias(TypeAlias),
321} 321}
322impl_froms!(TypableDef: Function, Struct, Enum, EnumVariant, Type); 322impl_froms!(TypableDef: Function, Struct, Enum, EnumVariant, TypeAlias);
323 323
324impl From<ModuleDef> for Option<TypableDef> { 324impl From<ModuleDef> for Option<TypableDef> {
325 fn from(def: ModuleDef) -> Option<TypableDef> { 325 fn from(def: ModuleDef) -> Option<TypableDef> {
@@ -328,7 +328,7 @@ impl From<ModuleDef> for Option<TypableDef> {
328 ModuleDef::Struct(s) => s.into(), 328 ModuleDef::Struct(s) => s.into(),
329 ModuleDef::Enum(e) => e.into(), 329 ModuleDef::Enum(e) => e.into(),
330 ModuleDef::EnumVariant(v) => v.into(), 330 ModuleDef::EnumVariant(v) => v.into(),
331 ModuleDef::Type(t) => t.into(), 331 ModuleDef::TypeAlias(t) => t.into(),
332 ModuleDef::Const(_) 332 ModuleDef::Const(_)
333 | ModuleDef::Static(_) 333 | ModuleDef::Static(_)
334 | ModuleDef::Module(_) 334 | ModuleDef::Module(_)
diff --git a/crates/ra_hir/src/type_alias.rs b/crates/ra_hir/src/type_alias.rs
index ab9481708..d02762d20 100644
--- a/crates/ra_hir/src/type_alias.rs
+++ b/crates/ra_hir/src/type_alias.rs
@@ -2,9 +2,12 @@
2 2
3use std::sync::Arc; 3use std::sync::Arc;
4 4
5use crate::{code_model_api::Type, db::PersistentHirDatabase, type_ref::TypeRef}; 5use crate::{TypeAlias, db::PersistentHirDatabase, type_ref::TypeRef};
6 6
7pub(crate) fn type_alias_ref_query(db: &impl PersistentHirDatabase, typ: Type) -> Arc<TypeRef> { 7pub(crate) fn type_alias_ref_query(
8 db: &impl PersistentHirDatabase,
9 typ: TypeAlias,
10) -> Arc<TypeRef> {
8 let (_, node) = typ.source(db); 11 let (_, node) = typ.source(db);
9 Arc::new(TypeRef::from_ast_opt(node.type_ref())) 12 Arc::new(TypeRef::from_ast_opt(node.type_ref()))
10} 13}