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.rs23
1 files changed, 6 insertions, 17 deletions
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs
index f4e055feb..ee4508bb2 100644
--- a/crates/ra_hir/src/ty/lower.rs
+++ b/crates/ra_hir/src/ty/lower.rs
@@ -9,7 +9,7 @@
9use std::sync::Arc; 9use std::sync::Arc;
10 10
11use crate::{ 11use crate::{
12 Function, Struct, StructField, Enum, EnumVariant, Path, Name, 12 Function, Struct, StructField, Enum, EnumVariant, Path,
13 ModuleDef, TypeAlias, 13 ModuleDef, TypeAlias,
14 Const, Static, 14 Const, Static,
15 HirDatabase, 15 HirDatabase,
@@ -232,13 +232,12 @@ fn type_for_fn(db: &impl HirDatabase, def: Function) -> Ty {
232 let signature = def.signature(db); 232 let signature = def.signature(db);
233 let resolver = def.resolver(db); 233 let resolver = def.resolver(db);
234 let generics = def.generic_params(db); 234 let generics = def.generic_params(db);
235 let name = def.name(db);
236 let input = 235 let input =
237 signature.params().iter().map(|tr| Ty::from_hir(db, &resolver, tr)).collect::<Vec<_>>(); 236 signature.params().iter().map(|tr| Ty::from_hir(db, &resolver, tr)).collect::<Vec<_>>();
238 let output = Ty::from_hir(db, &resolver, signature.ret_type()); 237 let output = Ty::from_hir(db, &resolver, signature.ret_type());
239 let sig = Arc::new(FnSig { input, output }); 238 let sig = Arc::new(FnSig { input, output });
240 let substs = make_substs(&generics); 239 let substs = make_substs(&generics);
241 Ty::FnDef { def: def.into(), sig, name, substs } 240 Ty::FnDef { def: def.into(), sig, substs }
242} 241}
243 242
244/// Build the declared type of a const. 243/// Build the declared type of a const.
@@ -266,7 +265,6 @@ fn type_for_struct_constructor(db: &impl HirDatabase, def: Struct) -> Ty {
266 }; 265 };
267 let resolver = def.resolver(db); 266 let resolver = def.resolver(db);
268 let generics = def.generic_params(db); 267 let generics = def.generic_params(db);
269 let name = def.name(db).unwrap_or_else(Name::missing);
270 let input = fields 268 let input = fields
271 .iter() 269 .iter()
272 .map(|(_, field)| Ty::from_hir(db, &resolver, &field.type_ref)) 270 .map(|(_, field)| Ty::from_hir(db, &resolver, &field.type_ref))
@@ -274,7 +272,7 @@ fn type_for_struct_constructor(db: &impl HirDatabase, def: Struct) -> Ty {
274 let output = type_for_struct(db, def); 272 let output = type_for_struct(db, def);
275 let sig = Arc::new(FnSig { input, output }); 273 let sig = Arc::new(FnSig { input, output });
276 let substs = make_substs(&generics); 274 let substs = make_substs(&generics);
277 Ty::FnDef { def: def.into(), sig, name, substs } 275 Ty::FnDef { def: def.into(), sig, substs }
278} 276}
279 277
280/// Build the type of a tuple enum variant constructor. 278/// Build the type of a tuple enum variant constructor.
@@ -286,7 +284,6 @@ fn type_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariant) ->
286 }; 284 };
287 let resolver = def.parent_enum(db).resolver(db); 285 let resolver = def.parent_enum(db).resolver(db);
288 let generics = def.parent_enum(db).generic_params(db); 286 let generics = def.parent_enum(db).generic_params(db);
289 let name = def.name(db).unwrap_or_else(Name::missing);
290 let input = fields 287 let input = fields
291 .iter() 288 .iter()
292 .map(|(_, field)| Ty::from_hir(db, &resolver, &field.type_ref)) 289 .map(|(_, field)| Ty::from_hir(db, &resolver, &field.type_ref))
@@ -294,7 +291,7 @@ fn type_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariant) ->
294 let substs = make_substs(&generics); 291 let substs = make_substs(&generics);
295 let output = type_for_enum(db, def.parent_enum(db)).subst(&substs); 292 let output = type_for_enum(db, def.parent_enum(db)).subst(&substs);
296 let sig = Arc::new(FnSig { input, output }); 293 let sig = Arc::new(FnSig { input, output });
297 Ty::FnDef { def: def.into(), sig, name, substs } 294 Ty::FnDef { def: def.into(), sig, substs }
298} 295}
299 296
300fn make_substs(generics: &GenericParams) -> Substs { 297fn make_substs(generics: &GenericParams) -> Substs {
@@ -310,20 +307,12 @@ fn make_substs(generics: &GenericParams) -> Substs {
310 307
311fn type_for_struct(db: &impl HirDatabase, s: Struct) -> Ty { 308fn type_for_struct(db: &impl HirDatabase, s: Struct) -> Ty {
312 let generics = s.generic_params(db); 309 let generics = s.generic_params(db);
313 Ty::Adt { 310 Ty::Adt { def_id: s.into(), substs: make_substs(&generics) }
314 def_id: s.into(),
315 name: s.name(db).unwrap_or_else(Name::missing),
316 substs: make_substs(&generics),
317 }
318} 311}
319 312
320fn type_for_enum(db: &impl HirDatabase, s: Enum) -> Ty { 313fn type_for_enum(db: &impl HirDatabase, s: Enum) -> Ty {
321 let generics = s.generic_params(db); 314 let generics = s.generic_params(db);
322 Ty::Adt { 315 Ty::Adt { def_id: s.into(), substs: make_substs(&generics) }
323 def_id: s.into(),
324 name: s.name(db).unwrap_or_else(Name::missing),
325 substs: make_substs(&generics),
326 }
327} 316}
328 317
329fn type_for_type_alias(db: &impl HirDatabase, t: TypeAlias) -> Ty { 318fn type_for_type_alias(db: &impl HirDatabase, t: TypeAlias) -> Ty {