aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/lower.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty/src/lower.rs')
-rw-r--r--crates/ra_hir_ty/src/lower.rs22
1 files changed, 10 insertions, 12 deletions
diff --git a/crates/ra_hir_ty/src/lower.rs b/crates/ra_hir_ty/src/lower.rs
index c2a3703fa..52da34574 100644
--- a/crates/ra_hir_ty/src/lower.rs
+++ b/crates/ra_hir_ty/src/lower.rs
@@ -361,10 +361,8 @@ impl Ty {
361 for t in traits { 361 for t in traits {
362 if let Some(associated_ty) = ctx.db.trait_data(t).associated_type_by_name(&segment.name) 362 if let Some(associated_ty) = ctx.db.trait_data(t).associated_type_by_name(&segment.name)
363 { 363 {
364 let substs = Substs::build_for_def(ctx.db, t) 364 let substs =
365 .push(self_ty.clone()) 365 Substs::build_for_def(ctx.db, t).push(self_ty).fill_with_unknown().build();
366 .fill_with_unknown()
367 .build();
368 // FIXME handle type parameters on the segment 366 // FIXME handle type parameters on the segment
369 return Ty::Projection(ProjectionTy { associated_ty, parameters: substs }); 367 return Ty::Projection(ProjectionTy { associated_ty, parameters: substs });
370 } 368 }
@@ -428,7 +426,7 @@ pub(super) fn substs_from_path_segment(
428 _add_self_param: bool, 426 _add_self_param: bool,
429) -> Substs { 427) -> Substs {
430 let mut substs = Vec::new(); 428 let mut substs = Vec::new();
431 let def_generics = def_generic.map(|def| generics(ctx.db, def.into())); 429 let def_generics = def_generic.map(|def| generics(ctx.db, def));
432 430
433 let (parent_params, self_params, type_params, impl_trait_params) = 431 let (parent_params, self_params, type_params, impl_trait_params) =
434 def_generics.map_or((0, 0, 0, 0), |g| g.provenance_split()); 432 def_generics.map_or((0, 0, 0, 0), |g| g.provenance_split());
@@ -459,7 +457,7 @@ pub(super) fn substs_from_path_segment(
459 457
460 // handle defaults 458 // handle defaults
461 if let Some(def_generic) = def_generic { 459 if let Some(def_generic) = def_generic {
462 let default_substs = ctx.db.generic_defaults(def_generic.into()); 460 let default_substs = ctx.db.generic_defaults(def_generic);
463 assert_eq!(substs.len(), default_substs.len()); 461 assert_eq!(substs.len(), default_substs.len());
464 462
465 for (i, default_ty) in default_substs.iter().enumerate() { 463 for (i, default_ty) in default_substs.iter().enumerate() {
@@ -483,7 +481,7 @@ impl TraitRef {
483 _ => return None, 481 _ => return None,
484 }; 482 };
485 let segment = path.segments().last().expect("path should have at least one segment"); 483 let segment = path.segments().last().expect("path should have at least one segment");
486 Some(TraitRef::from_resolved_path(ctx, resolved.into(), segment, explicit_self_ty)) 484 Some(TraitRef::from_resolved_path(ctx, resolved, segment, explicit_self_ty))
487 } 485 }
488 486
489 pub(crate) fn from_resolved_path( 487 pub(crate) fn from_resolved_path(
@@ -728,7 +726,7 @@ pub(crate) fn generic_predicates_query(
728pub(crate) fn generic_defaults_query(db: &impl HirDatabase, def: GenericDefId) -> Substs { 726pub(crate) fn generic_defaults_query(db: &impl HirDatabase, def: GenericDefId) -> Substs {
729 let resolver = def.resolver(db); 727 let resolver = def.resolver(db);
730 let ctx = TyLoweringContext::new(db, &resolver); 728 let ctx = TyLoweringContext::new(db, &resolver);
731 let generic_params = generics(db, def.into()); 729 let generic_params = generics(db, def);
732 730
733 let defaults = generic_params 731 let defaults = generic_params
734 .iter() 732 .iter()
@@ -792,7 +790,7 @@ fn type_for_builtin(def: BuiltinType) -> Ty {
792} 790}
793 791
794fn fn_sig_for_struct_constructor(db: &impl HirDatabase, def: StructId) -> PolyFnSig { 792fn fn_sig_for_struct_constructor(db: &impl HirDatabase, def: StructId) -> PolyFnSig {
795 let struct_data = db.struct_data(def.into()); 793 let struct_data = db.struct_data(def);
796 let fields = struct_data.variant_data.fields(); 794 let fields = struct_data.variant_data.fields();
797 let resolver = def.resolver(db); 795 let resolver = def.resolver(db);
798 let ctx = 796 let ctx =
@@ -805,7 +803,7 @@ fn fn_sig_for_struct_constructor(db: &impl HirDatabase, def: StructId) -> PolyFn
805 803
806/// Build the type of a tuple struct constructor. 804/// Build the type of a tuple struct constructor.
807fn type_for_struct_constructor(db: &impl HirDatabase, def: StructId) -> Binders<Ty> { 805fn type_for_struct_constructor(db: &impl HirDatabase, def: StructId) -> Binders<Ty> {
808 let struct_data = db.struct_data(def.into()); 806 let struct_data = db.struct_data(def);
809 if let StructKind::Unit = struct_data.variant_data.kind() { 807 if let StructKind::Unit = struct_data.variant_data.kind() {
810 return type_for_adt(db, def.into()); 808 return type_for_adt(db, def.into());
811 } 809 }
@@ -836,7 +834,7 @@ fn type_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariantId)
836 } 834 }
837 let generics = generics(db, def.parent.into()); 835 let generics = generics(db, def.parent.into());
838 let substs = Substs::bound_vars(&generics); 836 let substs = Substs::bound_vars(&generics);
839 Binders::new(substs.len(), Ty::apply(TypeCtor::FnDef(EnumVariantId::from(def).into()), substs)) 837 Binders::new(substs.len(), Ty::apply(TypeCtor::FnDef(def.into()), substs))
840} 838}
841 839
842fn type_for_adt(db: &impl HirDatabase, adt: AdtId) -> Binders<Ty> { 840fn type_for_adt(db: &impl HirDatabase, adt: AdtId) -> Binders<Ty> {
@@ -964,6 +962,6 @@ pub(crate) fn impl_trait_query(
964 let target_trait = impl_data.target_trait.as_ref()?; 962 let target_trait = impl_data.target_trait.as_ref()?;
965 Some(Binders::new( 963 Some(Binders::new(
966 self_ty.num_binders, 964 self_ty.num_binders,
967 TraitRef::from_hir(&ctx, target_trait, Some(self_ty.value.clone()))?, 965 TraitRef::from_hir(&ctx, target_trait, Some(self_ty.value))?,
968 )) 966 ))
969} 967}