@@ -1068,20 +1068,21 @@ impl Field {
1068
1068
Type :: new ( db, var_id, ty)
1069
1069
}
1070
1070
1071
- pub fn ty_with_generics (
1072
- & self ,
1073
- db : & dyn HirDatabase ,
1074
- mut generics : impl Iterator < Item = Type > ,
1075
- ) -> Type {
1071
+ pub fn ty_with_args ( & self , db : & dyn HirDatabase , generics : impl Iterator < Item = Type > ) -> Type {
1076
1072
let var_id = self . parent . into ( ) ;
1077
1073
let def_id: AdtId = match self . parent {
1078
1074
VariantDef :: Struct ( it) => it. id . into ( ) ,
1079
1075
VariantDef :: Union ( it) => it. id . into ( ) ,
1080
1076
VariantDef :: Variant ( it) => it. parent . id . into ( ) ,
1081
1077
} ;
1078
+ let mut generics = generics. map ( |it| it. ty . clone ( ) ) ;
1082
1079
let substs = TyBuilder :: subst_for_def ( db, def_id, None )
1083
- . fill ( |_| {
1084
- GenericArg :: new ( Interner , GenericArgData :: Ty ( generics. next ( ) . unwrap ( ) . ty . clone ( ) ) )
1080
+ . fill ( |x| {
1081
+ let ty = generics. next ( ) . unwrap_or_else ( || TyKind :: Error . intern ( Interner ) ) ;
1082
+ match x {
1083
+ ParamKind :: Type => ty. cast ( Interner ) ,
1084
+ ParamKind :: Const ( ty) => unknown_const_as_generic ( ty. clone ( ) ) ,
1085
+ }
1085
1086
} )
1086
1087
. build ( ) ;
1087
1088
let ty = db. field_types ( var_id) [ self . id ] . clone ( ) . substitute ( Interner , & substs) ;
@@ -1141,14 +1142,15 @@ impl Struct {
1141
1142
Type :: from_def ( db, self . id )
1142
1143
}
1143
1144
1144
- pub fn ty_with_generics (
1145
- self ,
1146
- db : & dyn HirDatabase ,
1147
- mut generics : impl Iterator < Item = Type > ,
1148
- ) -> Type {
1145
+ pub fn ty_with_args ( self , db : & dyn HirDatabase , generics : impl Iterator < Item = Type > ) -> Type {
1146
+ let mut generics = generics. map ( |it| it. ty . clone ( ) ) ;
1149
1147
let substs = TyBuilder :: subst_for_def ( db, self . id , None )
1150
- . fill ( |_| {
1151
- GenericArg :: new ( Interner , GenericArgData :: Ty ( generics. next ( ) . unwrap ( ) . ty . clone ( ) ) )
1148
+ . fill ( |x| {
1149
+ let ty = generics. next ( ) . unwrap_or_else ( || TyKind :: Error . intern ( Interner ) ) ;
1150
+ match x {
1151
+ ParamKind :: Type => ty. cast ( Interner ) ,
1152
+ ParamKind :: Const ( ty) => unknown_const_as_generic ( ty. clone ( ) ) ,
1153
+ }
1152
1154
} )
1153
1155
. build ( ) ;
1154
1156
let ty = db. ty ( self . id . into ( ) ) . substitute ( Interner , & substs) ;
@@ -1254,16 +1256,18 @@ impl Enum {
1254
1256
Type :: from_def ( db, self . id )
1255
1257
}
1256
1258
1257
- pub fn ty_with_generics (
1258
- & self ,
1259
- db : & dyn HirDatabase ,
1260
- mut generics : impl Iterator < Item = Type > ,
1261
- ) -> Type {
1259
+ pub fn ty_with_args ( & self , db : & dyn HirDatabase , generics : impl Iterator < Item = Type > ) -> Type {
1260
+ let mut generics = generics. map ( |it| it. ty . clone ( ) ) ;
1262
1261
let substs = TyBuilder :: subst_for_def ( db, self . id , None )
1263
- . fill ( |_| {
1264
- GenericArg :: new ( Interner , GenericArgData :: Ty ( generics. next ( ) . unwrap ( ) . ty . clone ( ) ) )
1262
+ . fill ( |x| {
1263
+ let ty = generics. next ( ) . unwrap_or_else ( || TyKind :: Error . intern ( Interner ) ) ;
1264
+ match x {
1265
+ ParamKind :: Type => ty. cast ( Interner ) ,
1266
+ ParamKind :: Const ( ty) => unknown_const_as_generic ( ty. clone ( ) ) ,
1267
+ }
1265
1268
} )
1266
1269
. build ( ) ;
1270
+
1267
1271
let ty = db. ty ( self . id . into ( ) ) . substitute ( Interner , & substs) ;
1268
1272
Type :: new ( db, self . id , ty)
1269
1273
}
@@ -2070,33 +2074,29 @@ impl Function {
2070
2074
Type :: new_with_resolver_inner ( db, & resolver, ty)
2071
2075
}
2072
2076
2073
- pub fn ret_type_with_generics (
2077
+ pub fn ret_type_with_args (
2074
2078
self ,
2075
2079
db : & dyn HirDatabase ,
2076
- mut generics : impl Iterator < Item = Type > ,
2080
+ generics : impl Iterator < Item = Type > ,
2077
2081
) -> Type {
2078
2082
let resolver = self . id . resolver ( db. upcast ( ) ) ;
2079
2083
let parent_id: Option < GenericDefId > = match self . id . lookup ( db. upcast ( ) ) . container {
2080
2084
ItemContainerId :: ImplId ( it) => Some ( it. into ( ) ) ,
2081
2085
ItemContainerId :: TraitId ( it) => Some ( it. into ( ) ) ,
2082
2086
ItemContainerId :: ModuleId ( _) | ItemContainerId :: ExternBlockId ( _) => None ,
2083
2087
} ;
2084
- let parent_substs = parent_id. map ( |id| {
2085
- TyBuilder :: subst_for_def ( db, id, None )
2086
- . fill ( |_| {
2087
- GenericArg :: new (
2088
- Interner ,
2089
- GenericArgData :: Ty ( generics. next ( ) . unwrap ( ) . ty . clone ( ) ) ,
2090
- )
2091
- } )
2092
- . build ( )
2093
- } ) ;
2088
+ let mut generics = generics. map ( |it| it. ty . clone ( ) ) ;
2089
+ let mut filler = |x : & _ | {
2090
+ let ty = generics. next ( ) . unwrap_or_else ( || TyKind :: Error . intern ( Interner ) ) ;
2091
+ match x {
2092
+ ParamKind :: Type => ty. cast ( Interner ) ,
2093
+ ParamKind :: Const ( ty) => unknown_const_as_generic ( ty. clone ( ) ) ,
2094
+ }
2095
+ } ;
2094
2096
2095
- let substs = TyBuilder :: subst_for_def ( db, self . id , parent_substs)
2096
- . fill ( |_| {
2097
- GenericArg :: new ( Interner , GenericArgData :: Ty ( generics. next ( ) . unwrap ( ) . ty . clone ( ) ) )
2098
- } )
2099
- . build ( ) ;
2097
+ let parent_substs =
2098
+ parent_id. map ( |id| TyBuilder :: subst_for_def ( db, id, None ) . fill ( & mut filler) . build ( ) ) ;
2099
+ let substs = TyBuilder :: subst_for_def ( db, self . id , parent_substs) . fill ( & mut filler) . build ( ) ;
2100
2100
2101
2101
let callable_sig = db. callable_item_signature ( self . id . into ( ) ) . substitute ( Interner , & substs) ;
2102
2102
let ty = callable_sig. ret ( ) . clone ( ) ;
@@ -2414,11 +2414,7 @@ impl SelfParam {
2414
2414
Type { env : environment, ty }
2415
2415
}
2416
2416
2417
- pub fn ty_with_generics (
2418
- & self ,
2419
- db : & dyn HirDatabase ,
2420
- mut generics : impl Iterator < Item = Type > ,
2421
- ) -> Type {
2417
+ pub fn ty_with_args ( & self , db : & dyn HirDatabase , generics : impl Iterator < Item = Type > ) -> Type {
2422
2418
let parent_id: GenericDefId = match self . func . lookup ( db. upcast ( ) ) . container {
2423
2419
ItemContainerId :: ImplId ( it) => it. into ( ) ,
2424
2420
ItemContainerId :: TraitId ( it) => it. into ( ) ,
@@ -2427,16 +2423,18 @@ impl SelfParam {
2427
2423
}
2428
2424
} ;
2429
2425
2430
- let parent_substs = TyBuilder :: subst_for_def ( db, parent_id, None )
2431
- . fill ( |_| {
2432
- GenericArg :: new ( Interner , GenericArgData :: Ty ( generics. next ( ) . unwrap ( ) . ty . clone ( ) ) )
2433
- } )
2434
- . build ( ) ;
2435
- let substs = TyBuilder :: subst_for_def ( db, self . func , Some ( parent_substs) )
2436
- . fill ( |_| {
2437
- GenericArg :: new ( Interner , GenericArgData :: Ty ( generics. next ( ) . unwrap ( ) . ty . clone ( ) ) )
2438
- } )
2439
- . build ( ) ;
2426
+ let mut generics = generics. map ( |it| it. ty . clone ( ) ) ;
2427
+ let mut filler = |x : & _ | {
2428
+ let ty = generics. next ( ) . unwrap_or_else ( || TyKind :: Error . intern ( Interner ) ) ;
2429
+ match x {
2430
+ ParamKind :: Type => ty. cast ( Interner ) ,
2431
+ ParamKind :: Const ( ty) => unknown_const_as_generic ( ty. clone ( ) ) ,
2432
+ }
2433
+ } ;
2434
+
2435
+ let parent_substs = TyBuilder :: subst_for_def ( db, parent_id, None ) . fill ( & mut filler) . build ( ) ;
2436
+ let substs =
2437
+ TyBuilder :: subst_for_def ( db, self . func , Some ( parent_substs) ) . fill ( & mut filler) . build ( ) ;
2440
2438
let callable_sig =
2441
2439
db. callable_item_signature ( self . func . into ( ) ) . substitute ( Interner , & substs) ;
2442
2440
let environment = db. trait_environment ( self . func . into ( ) ) ;
0 commit comments