@@ -1089,20 +1089,21 @@ impl Field {
1089
1089
Type :: new ( db, var_id, ty)
1090
1090
}
1091
1091
1092
- pub fn ty_with_generics (
1093
- & self ,
1094
- db : & dyn HirDatabase ,
1095
- mut generics : impl Iterator < Item = Type > ,
1096
- ) -> Type {
1092
+ pub fn ty_with_args ( & self , db : & dyn HirDatabase , generics : impl Iterator < Item = Type > ) -> Type {
1097
1093
let var_id = self . parent . into ( ) ;
1098
1094
let def_id: AdtId = match self . parent {
1099
1095
VariantDef :: Struct ( it) => it. id . into ( ) ,
1100
1096
VariantDef :: Union ( it) => it. id . into ( ) ,
1101
1097
VariantDef :: Variant ( it) => it. parent . id . into ( ) ,
1102
1098
} ;
1099
+ let mut generics = generics. map ( |it| it. ty . clone ( ) ) ;
1103
1100
let substs = TyBuilder :: subst_for_def ( db, def_id, None )
1104
- . fill ( |_| {
1105
- GenericArg :: new ( Interner , GenericArgData :: Ty ( generics. next ( ) . unwrap ( ) . ty . clone ( ) ) )
1101
+ . fill ( |x| {
1102
+ let ty = generics. next ( ) . unwrap_or_else ( || TyKind :: Error . intern ( Interner ) ) ;
1103
+ match x {
1104
+ ParamKind :: Type => ty. cast ( Interner ) ,
1105
+ ParamKind :: Const ( ty) => unknown_const_as_generic ( ty. clone ( ) ) ,
1106
+ }
1106
1107
} )
1107
1108
. build ( ) ;
1108
1109
let ty = db. field_types ( var_id) [ self . id ] . clone ( ) . substitute ( Interner , & substs) ;
@@ -1162,14 +1163,15 @@ impl Struct {
1162
1163
Type :: from_def ( db, self . id )
1163
1164
}
1164
1165
1165
- pub fn ty_with_generics (
1166
- self ,
1167
- db : & dyn HirDatabase ,
1168
- mut generics : impl Iterator < Item = Type > ,
1169
- ) -> Type {
1166
+ pub fn ty_with_args ( self , db : & dyn HirDatabase , generics : impl Iterator < Item = Type > ) -> Type {
1167
+ let mut generics = generics. map ( |it| it. ty . clone ( ) ) ;
1170
1168
let substs = TyBuilder :: subst_for_def ( db, self . id , None )
1171
- . fill ( |_| {
1172
- GenericArg :: new ( Interner , GenericArgData :: Ty ( generics. next ( ) . unwrap ( ) . ty . clone ( ) ) )
1169
+ . fill ( |x| {
1170
+ let ty = generics. next ( ) . unwrap_or_else ( || TyKind :: Error . intern ( Interner ) ) ;
1171
+ match x {
1172
+ ParamKind :: Type => ty. cast ( Interner ) ,
1173
+ ParamKind :: Const ( ty) => unknown_const_as_generic ( ty. clone ( ) ) ,
1174
+ }
1173
1175
} )
1174
1176
. build ( ) ;
1175
1177
let ty = db. ty ( self . id . into ( ) ) . substitute ( Interner , & substs) ;
@@ -1275,16 +1277,18 @@ impl Enum {
1275
1277
Type :: from_def ( db, self . id )
1276
1278
}
1277
1279
1278
- pub fn ty_with_generics (
1279
- & self ,
1280
- db : & dyn HirDatabase ,
1281
- mut generics : impl Iterator < Item = Type > ,
1282
- ) -> Type {
1280
+ pub fn ty_with_args ( & self , db : & dyn HirDatabase , generics : impl Iterator < Item = Type > ) -> Type {
1281
+ let mut generics = generics. map ( |it| it. ty . clone ( ) ) ;
1283
1282
let substs = TyBuilder :: subst_for_def ( db, self . id , None )
1284
- . fill ( |_| {
1285
- GenericArg :: new ( Interner , GenericArgData :: Ty ( generics. next ( ) . unwrap ( ) . ty . clone ( ) ) )
1283
+ . fill ( |x| {
1284
+ let ty = generics. next ( ) . unwrap_or_else ( || TyKind :: Error . intern ( Interner ) ) ;
1285
+ match x {
1286
+ ParamKind :: Type => ty. cast ( Interner ) ,
1287
+ ParamKind :: Const ( ty) => unknown_const_as_generic ( ty. clone ( ) ) ,
1288
+ }
1286
1289
} )
1287
1290
. build ( ) ;
1291
+
1288
1292
let ty = db. ty ( self . id . into ( ) ) . substitute ( Interner , & substs) ;
1289
1293
Type :: new ( db, self . id , ty)
1290
1294
}
@@ -2103,33 +2107,29 @@ impl Function {
2103
2107
Type :: new_with_resolver_inner ( db, & resolver, ty)
2104
2108
}
2105
2109
2106
- pub fn ret_type_with_generics (
2110
+ pub fn ret_type_with_args (
2107
2111
self ,
2108
2112
db : & dyn HirDatabase ,
2109
- mut generics : impl Iterator < Item = Type > ,
2113
+ generics : impl Iterator < Item = Type > ,
2110
2114
) -> Type {
2111
2115
let resolver = self . id . resolver ( db. upcast ( ) ) ;
2112
2116
let parent_id: Option < GenericDefId > = match self . id . lookup ( db. upcast ( ) ) . container {
2113
2117
ItemContainerId :: ImplId ( it) => Some ( it. into ( ) ) ,
2114
2118
ItemContainerId :: TraitId ( it) => Some ( it. into ( ) ) ,
2115
2119
ItemContainerId :: ModuleId ( _) | ItemContainerId :: ExternBlockId ( _) => None ,
2116
2120
} ;
2117
- let parent_substs = parent_id. map ( |id| {
2118
- TyBuilder :: subst_for_def ( db, id, None )
2119
- . fill ( |_| {
2120
- GenericArg :: new (
2121
- Interner ,
2122
- GenericArgData :: Ty ( generics. next ( ) . unwrap ( ) . ty . clone ( ) ) ,
2123
- )
2124
- } )
2125
- . build ( )
2126
- } ) ;
2121
+ let mut generics = generics. map ( |it| it. ty . clone ( ) ) ;
2122
+ let mut filler = |x : & _ | {
2123
+ let ty = generics. next ( ) . unwrap_or_else ( || TyKind :: Error . intern ( Interner ) ) ;
2124
+ match x {
2125
+ ParamKind :: Type => ty. cast ( Interner ) ,
2126
+ ParamKind :: Const ( ty) => unknown_const_as_generic ( ty. clone ( ) ) ,
2127
+ }
2128
+ } ;
2127
2129
2128
- let substs = TyBuilder :: subst_for_def ( db, self . id , parent_substs)
2129
- . fill ( |_| {
2130
- GenericArg :: new ( Interner , GenericArgData :: Ty ( generics. next ( ) . unwrap ( ) . ty . clone ( ) ) )
2131
- } )
2132
- . build ( ) ;
2130
+ let parent_substs =
2131
+ parent_id. map ( |id| TyBuilder :: subst_for_def ( db, id, None ) . fill ( & mut filler) . build ( ) ) ;
2132
+ let substs = TyBuilder :: subst_for_def ( db, self . id , parent_substs) . fill ( & mut filler) . build ( ) ;
2133
2133
2134
2134
let callable_sig = db. callable_item_signature ( self . id . into ( ) ) . substitute ( Interner , & substs) ;
2135
2135
let ty = callable_sig. ret ( ) . clone ( ) ;
@@ -2449,11 +2449,7 @@ impl SelfParam {
2449
2449
Type { env : environment, ty }
2450
2450
}
2451
2451
2452
- pub fn ty_with_generics (
2453
- & self ,
2454
- db : & dyn HirDatabase ,
2455
- mut generics : impl Iterator < Item = Type > ,
2456
- ) -> Type {
2452
+ pub fn ty_with_args ( & self , db : & dyn HirDatabase , generics : impl Iterator < Item = Type > ) -> Type {
2457
2453
let parent_id: GenericDefId = match self . func . lookup ( db. upcast ( ) ) . container {
2458
2454
ItemContainerId :: ImplId ( it) => it. into ( ) ,
2459
2455
ItemContainerId :: TraitId ( it) => it. into ( ) ,
@@ -2462,16 +2458,18 @@ impl SelfParam {
2462
2458
}
2463
2459
} ;
2464
2460
2465
- let parent_substs = TyBuilder :: subst_for_def ( db, parent_id, None )
2466
- . fill ( |_| {
2467
- GenericArg :: new ( Interner , GenericArgData :: Ty ( generics. next ( ) . unwrap ( ) . ty . clone ( ) ) )
2468
- } )
2469
- . build ( ) ;
2470
- let substs = TyBuilder :: subst_for_def ( db, self . func , Some ( parent_substs) )
2471
- . fill ( |_| {
2472
- GenericArg :: new ( Interner , GenericArgData :: Ty ( generics. next ( ) . unwrap ( ) . ty . clone ( ) ) )
2473
- } )
2474
- . build ( ) ;
2461
+ let mut generics = generics. map ( |it| it. ty . clone ( ) ) ;
2462
+ let mut filler = |x : & _ | {
2463
+ let ty = generics. next ( ) . unwrap_or_else ( || TyKind :: Error . intern ( Interner ) ) ;
2464
+ match x {
2465
+ ParamKind :: Type => ty. cast ( Interner ) ,
2466
+ ParamKind :: Const ( ty) => unknown_const_as_generic ( ty. clone ( ) ) ,
2467
+ }
2468
+ } ;
2469
+
2470
+ let parent_substs = TyBuilder :: subst_for_def ( db, parent_id, None ) . fill ( & mut filler) . build ( ) ;
2471
+ let substs =
2472
+ TyBuilder :: subst_for_def ( db, self . func , Some ( parent_substs) ) . fill ( & mut filler) . build ( ) ;
2475
2473
let callable_sig =
2476
2474
db. callable_item_signature ( self . func . into ( ) ) . substitute ( Interner , & substs) ;
2477
2475
let environment = db. trait_environment ( self . func . into ( ) ) ;
0 commit comments