aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty/lower.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/ty/lower.rs')
-rw-r--r--crates/ra_hir/src/ty/lower.rs21
1 files changed, 17 insertions, 4 deletions
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs
index 4a9b725d1..f4e055feb 100644
--- a/crates/ra_hir/src/ty/lower.rs
+++ b/crates/ra_hir/src/ty/lower.rs
@@ -11,7 +11,7 @@ use std::sync::Arc;
11use crate::{ 11use crate::{
12 Function, Struct, StructField, Enum, EnumVariant, Path, Name, 12 Function, Struct, StructField, Enum, EnumVariant, Path, Name,
13 ModuleDef, TypeAlias, 13 ModuleDef, TypeAlias,
14 Const, 14 Const, Static,
15 HirDatabase, 15 HirDatabase,
16 type_ref::TypeRef, 16 type_ref::TypeRef,
17 name::KnownName, 17 name::KnownName,
@@ -126,7 +126,7 @@ impl Ty {
126 TypableDef::Enum(e) => e.generic_params(db), 126 TypableDef::Enum(e) => e.generic_params(db),
127 TypableDef::EnumVariant(var) => var.parent_enum(db).generic_params(db), 127 TypableDef::EnumVariant(var) => var.parent_enum(db).generic_params(db),
128 TypableDef::TypeAlias(t) => t.generic_params(db), 128 TypableDef::TypeAlias(t) => t.generic_params(db),
129 TypableDef::Const(_) => GenericParams::default().into(), 129 TypableDef::Const(_) | TypableDef::Static(_) => GenericParams::default().into(),
130 }; 130 };
131 let parent_param_count = def_generics.count_parent_params(); 131 let parent_param_count = def_generics.count_parent_params();
132 substs.extend((0..parent_param_count).map(|_| Ty::Unknown)); 132 substs.extend((0..parent_param_count).map(|_| Ty::Unknown));
@@ -166,6 +166,7 @@ impl Ty {
166 | TypableDef::Struct(_) 166 | TypableDef::Struct(_)
167 | TypableDef::Enum(_) 167 | TypableDef::Enum(_)
168 | TypableDef::Const(_) 168 | TypableDef::Const(_)
169 | TypableDef::Static(_)
169 | TypableDef::TypeAlias(_) => last, 170 | TypableDef::TypeAlias(_) => last,
170 TypableDef::EnumVariant(_) => { 171 TypableDef::EnumVariant(_) => {
171 // the generic args for an enum variant may be either specified 172 // the generic args for an enum variant may be either specified
@@ -201,6 +202,7 @@ pub(crate) fn type_for_def(db: &impl HirDatabase, def: TypableDef, ns: Namespace
201 (TypableDef::EnumVariant(v), Namespace::Values) => type_for_enum_variant_constructor(db, v), 202 (TypableDef::EnumVariant(v), Namespace::Values) => type_for_enum_variant_constructor(db, v),
202 (TypableDef::TypeAlias(t), Namespace::Types) => type_for_type_alias(db, t), 203 (TypableDef::TypeAlias(t), Namespace::Types) => type_for_type_alias(db, t),
203 (TypableDef::Const(c), Namespace::Values) => type_for_const(db, c), 204 (TypableDef::Const(c), Namespace::Values) => type_for_const(db, c),
205 (TypableDef::Static(c), Namespace::Values) => type_for_static(db, c),
204 206
205 // 'error' cases: 207 // 'error' cases:
206 (TypableDef::Function(_), Namespace::Types) => Ty::Unknown, 208 (TypableDef::Function(_), Namespace::Types) => Ty::Unknown,
@@ -208,6 +210,7 @@ pub(crate) fn type_for_def(db: &impl HirDatabase, def: TypableDef, ns: Namespace
208 (TypableDef::EnumVariant(_), Namespace::Types) => Ty::Unknown, 210 (TypableDef::EnumVariant(_), Namespace::Types) => Ty::Unknown,
209 (TypableDef::TypeAlias(_), Namespace::Values) => Ty::Unknown, 211 (TypableDef::TypeAlias(_), Namespace::Values) => Ty::Unknown,
210 (TypableDef::Const(_), Namespace::Types) => Ty::Unknown, 212 (TypableDef::Const(_), Namespace::Types) => Ty::Unknown,
213 (TypableDef::Static(_), Namespace::Types) => Ty::Unknown,
211 } 214 }
212} 215}
213 216
@@ -246,6 +249,14 @@ fn type_for_const(db: &impl HirDatabase, def: Const) -> Ty {
246 Ty::from_hir(db, &resolver, signature.type_ref()) 249 Ty::from_hir(db, &resolver, signature.type_ref())
247} 250}
248 251
252/// Build the declared type of a static.
253fn type_for_static(db: &impl HirDatabase, def: Static) -> Ty {
254 let signature = def.signature(db);
255 let resolver = def.resolver(db);
256
257 Ty::from_hir(db, &resolver, signature.type_ref())
258}
259
249/// Build the type of a tuple struct constructor. 260/// Build the type of a tuple struct constructor.
250fn type_for_struct_constructor(db: &impl HirDatabase, def: Struct) -> Ty { 261fn type_for_struct_constructor(db: &impl HirDatabase, def: Struct) -> Ty {
251 let var_data = def.variant_data(db); 262 let var_data = def.variant_data(db);
@@ -332,8 +343,9 @@ pub enum TypableDef {
332 EnumVariant(EnumVariant), 343 EnumVariant(EnumVariant),
333 TypeAlias(TypeAlias), 344 TypeAlias(TypeAlias),
334 Const(Const), 345 Const(Const),
346 Static(Static),
335} 347}
336impl_froms!(TypableDef: Function, Struct, Enum, EnumVariant, TypeAlias, Const); 348impl_froms!(TypableDef: Function, Struct, Enum, EnumVariant, TypeAlias, Const, Static);
337 349
338impl From<ModuleDef> for Option<TypableDef> { 350impl From<ModuleDef> for Option<TypableDef> {
339 fn from(def: ModuleDef) -> Option<TypableDef> { 351 fn from(def: ModuleDef) -> Option<TypableDef> {
@@ -344,7 +356,8 @@ impl From<ModuleDef> for Option<TypableDef> {
344 ModuleDef::EnumVariant(v) => v.into(), 356 ModuleDef::EnumVariant(v) => v.into(),
345 ModuleDef::TypeAlias(t) => t.into(), 357 ModuleDef::TypeAlias(t) => t.into(),
346 ModuleDef::Const(v) => v.into(), 358 ModuleDef::Const(v) => v.into(),
347 ModuleDef::Static(_) | ModuleDef::Module(_) | ModuleDef::Trait(_) => return None, 359 ModuleDef::Static(v) => v.into(),
360 ModuleDef::Module(_) | ModuleDef::Trait(_) => return None,
348 }; 361 };
349 Some(res) 362 Some(res)
350 } 363 }