@@ -13,6 +13,7 @@ use hir_def::{
13
13
AdtId , ConstId , DefWithBodyId , EnumId , FunctionId , HasModule , ImplId , LocalEnumVariantId ,
14
14
LocalModuleId , LocalStructFieldId , Lookup , ModuleId , StaticId , StructId , TraitId , TypeAliasId ,
15
15
TypeParamId , UnionId ,
16
+ GenericDefId
16
17
} ;
17
18
use hir_expand:: {
18
19
diagnostics:: DiagnosticSink ,
@@ -21,7 +22,8 @@ use hir_expand::{
21
22
} ;
22
23
use hir_ty:: {
23
24
autoderef, display:: HirFormatter , expr:: ExprValidator , method_resolution, ApplicationTy ,
24
- Canonical , InEnvironment , TraitEnvironment , Ty , TyDefId , TypeCtor , TypeWalk ,
25
+ Canonical , InEnvironment , TraitEnvironment , Ty , TyDefId , TypeCtor ,
26
+ Substs
25
27
} ;
26
28
use ra_db:: { CrateId , Edition , FileId } ;
27
29
use ra_prof:: profile;
@@ -270,7 +272,13 @@ impl StructField {
270
272
271
273
pub fn ty ( & self , db : & impl HirDatabase ) -> Type {
272
274
let var_id = self . parent . into ( ) ;
273
- let ty = db. field_types ( var_id) [ self . id ] . clone ( ) ;
275
+ let generic_def_id: GenericDefId = match self . parent {
276
+ VariantDef :: Struct ( it) => it. id . into ( ) ,
277
+ VariantDef :: Union ( it) => it. id . into ( ) ,
278
+ VariantDef :: EnumVariant ( it) => it. parent . id . into ( ) ,
279
+ } ;
280
+ let substs = Substs :: type_params ( db, generic_def_id) ;
281
+ let ty = db. field_types ( var_id) [ self . id ] . clone ( ) . subst ( & substs) ;
274
282
Type :: new ( db, self . parent . module ( db) . id . krate . into ( ) , var_id, ty)
275
283
}
276
284
@@ -789,11 +797,7 @@ impl ImplBlock {
789
797
pub fn target_ty ( & self , db : & impl HirDatabase ) -> Type {
790
798
let impl_data = db. impl_data ( self . id ) ;
791
799
let resolver = self . id . resolver ( db) ;
792
- let ctx = hir_ty:: TyLoweringContext {
793
- db,
794
- resolver : & resolver,
795
- impl_trait_mode : hir_ty:: ImplTraitLoweringMode :: Disallowed ,
796
- } ;
800
+ let ctx = hir_ty:: TyLoweringContext :: new ( db, & resolver) ;
797
801
let environment = TraitEnvironment :: lower ( db, & resolver) ;
798
802
let ty = Ty :: from_hir ( & ctx, & impl_data. target_type ) ;
799
803
Type {
@@ -856,9 +860,10 @@ impl Type {
856
860
fn from_def (
857
861
db : & impl HirDatabase ,
858
862
krate : CrateId ,
859
- def : impl HasResolver + Into < TyDefId > ,
863
+ def : impl HasResolver + Into < TyDefId > + Into < GenericDefId > ,
860
864
) -> Type {
861
- let ty = db. ty ( def. into ( ) ) ;
865
+ let substs = Substs :: type_params ( db, def) ;
866
+ let ty = db. ty ( def. into ( ) ) . subst ( & substs) ;
862
867
Type :: new ( db, krate, def, ty)
863
868
}
864
869
@@ -955,7 +960,7 @@ impl Type {
955
960
match a_ty. ctor {
956
961
TypeCtor :: Tuple { .. } => {
957
962
for ty in a_ty. parameters . iter ( ) {
958
- let ty = ty. clone ( ) . subst ( & a_ty . parameters ) ;
963
+ let ty = ty. clone ( ) ;
959
964
res. push ( self . derived ( ty) ) ;
960
965
}
961
966
}
0 commit comments