@@ -1088,20 +1088,21 @@ impl Field {
1088
1088
Type :: new ( db, var_id, ty)
1089
1089
}
1090
1090
1091
- pub fn ty_with_generics (
1092
- & self ,
1093
- db : & dyn HirDatabase ,
1094
- mut generics : impl Iterator < Item = Type > ,
1095
- ) -> Type {
1091
+ pub fn ty_with_args ( & self , db : & dyn HirDatabase , generics : impl Iterator < Item = Type > ) -> Type {
1096
1092
let var_id = self . parent . into ( ) ;
1097
1093
let def_id: AdtId = match self . parent {
1098
1094
VariantDef :: Struct ( it) => it. id . into ( ) ,
1099
1095
VariantDef :: Union ( it) => it. id . into ( ) ,
1100
1096
VariantDef :: Variant ( it) => it. parent_enum ( db) . id . into ( ) ,
1101
1097
} ;
1098
+ let mut generics = generics. map ( |it| it. ty . clone ( ) ) ;
1102
1099
let substs = TyBuilder :: subst_for_def ( db, def_id, None )
1103
- . fill ( |_| {
1104
- GenericArg :: new ( Interner , GenericArgData :: Ty ( generics. next ( ) . unwrap ( ) . ty . clone ( ) ) )
1100
+ . fill ( |x| {
1101
+ let ty = generics. next ( ) . unwrap_or_else ( || TyKind :: Error . intern ( Interner ) ) ;
1102
+ match x {
1103
+ ParamKind :: Type => ty. cast ( Interner ) ,
1104
+ ParamKind :: Const ( ty) => unknown_const_as_generic ( ty. clone ( ) ) ,
1105
+ }
1105
1106
} )
1106
1107
. build ( ) ;
1107
1108
let ty = db. field_types ( var_id) [ self . id ] . clone ( ) . substitute ( Interner , & substs) ;
@@ -1161,14 +1162,15 @@ impl Struct {
1161
1162
Type :: from_def ( db, self . id )
1162
1163
}
1163
1164
1164
- pub fn ty_with_generics (
1165
- self ,
1166
- db : & dyn HirDatabase ,
1167
- mut generics : impl Iterator < Item = Type > ,
1168
- ) -> Type {
1165
+ pub fn ty_with_args ( self , db : & dyn HirDatabase , generics : impl Iterator < Item = Type > ) -> Type {
1166
+ let mut generics = generics. map ( |it| it. ty . clone ( ) ) ;
1169
1167
let substs = TyBuilder :: subst_for_def ( db, self . id , None )
1170
- . fill ( |_| {
1171
- GenericArg :: new ( Interner , GenericArgData :: Ty ( generics. next ( ) . unwrap ( ) . ty . clone ( ) ) )
1168
+ . fill ( |x| {
1169
+ let ty = generics. next ( ) . unwrap_or_else ( || TyKind :: Error . intern ( Interner ) ) ;
1170
+ match x {
1171
+ ParamKind :: Type => ty. cast ( Interner ) ,
1172
+ ParamKind :: Const ( ty) => unknown_const_as_generic ( ty. clone ( ) ) ,
1173
+ }
1172
1174
} )
1173
1175
. build ( ) ;
1174
1176
let ty = db. ty ( self . id . into ( ) ) . substitute ( Interner , & substs) ;
@@ -1274,16 +1276,18 @@ impl Enum {
1274
1276
Type :: from_def ( db, self . id )
1275
1277
}
1276
1278
1277
- pub fn ty_with_generics (
1278
- & self ,
1279
- db : & dyn HirDatabase ,
1280
- mut generics : impl Iterator < Item = Type > ,
1281
- ) -> Type {
1279
+ pub fn ty_with_args ( & self , db : & dyn HirDatabase , generics : impl Iterator < Item = Type > ) -> Type {
1280
+ let mut generics = generics. map ( |it| it. ty . clone ( ) ) ;
1282
1281
let substs = TyBuilder :: subst_for_def ( db, self . id , None )
1283
- . fill ( |_| {
1284
- GenericArg :: new ( Interner , GenericArgData :: Ty ( generics. next ( ) . unwrap ( ) . ty . clone ( ) ) )
1282
+ . fill ( |x| {
1283
+ let ty = generics. next ( ) . unwrap_or_else ( || TyKind :: Error . intern ( Interner ) ) ;
1284
+ match x {
1285
+ ParamKind :: Type => ty. cast ( Interner ) ,
1286
+ ParamKind :: Const ( ty) => unknown_const_as_generic ( ty. clone ( ) ) ,
1287
+ }
1285
1288
} )
1286
1289
. build ( ) ;
1290
+
1287
1291
let ty = db. ty ( self . id . into ( ) ) . substitute ( Interner , & substs) ;
1288
1292
Type :: new ( db, self . id , ty)
1289
1293
}
@@ -2068,33 +2072,29 @@ impl Function {
2068
2072
Type :: new_with_resolver_inner ( db, & resolver, ty)
2069
2073
}
2070
2074
2071
- pub fn ret_type_with_generics (
2075
+ pub fn ret_type_with_args (
2072
2076
self ,
2073
2077
db : & dyn HirDatabase ,
2074
- mut generics : impl Iterator < Item = Type > ,
2078
+ generics : impl Iterator < Item = Type > ,
2075
2079
) -> Type {
2076
2080
let resolver = self . id . resolver ( db. upcast ( ) ) ;
2077
2081
let parent_id: Option < GenericDefId > = match self . id . lookup ( db. upcast ( ) ) . container {
2078
2082
ItemContainerId :: ImplId ( it) => Some ( it. into ( ) ) ,
2079
2083
ItemContainerId :: TraitId ( it) => Some ( it. into ( ) ) ,
2080
2084
ItemContainerId :: ModuleId ( _) | ItemContainerId :: ExternBlockId ( _) => None ,
2081
2085
} ;
2082
- let parent_substs = parent_id. map ( |id| {
2083
- TyBuilder :: subst_for_def ( db, id, None )
2084
- . fill ( |_| {
2085
- GenericArg :: new (
2086
- Interner ,
2087
- GenericArgData :: Ty ( generics. next ( ) . unwrap ( ) . ty . clone ( ) ) ,
2088
- )
2089
- } )
2090
- . build ( )
2091
- } ) ;
2086
+ let mut generics = generics. map ( |it| it. ty . clone ( ) ) ;
2087
+ let mut filler = |x : & _ | {
2088
+ let ty = generics. next ( ) . unwrap_or_else ( || TyKind :: Error . intern ( Interner ) ) ;
2089
+ match x {
2090
+ ParamKind :: Type => ty. cast ( Interner ) ,
2091
+ ParamKind :: Const ( ty) => unknown_const_as_generic ( ty. clone ( ) ) ,
2092
+ }
2093
+ } ;
2092
2094
2093
- let substs = TyBuilder :: subst_for_def ( db, self . id , parent_substs)
2094
- . fill ( |_| {
2095
- GenericArg :: new ( Interner , GenericArgData :: Ty ( generics. next ( ) . unwrap ( ) . ty . clone ( ) ) )
2096
- } )
2097
- . build ( ) ;
2095
+ let parent_substs =
2096
+ parent_id. map ( |id| TyBuilder :: subst_for_def ( db, id, None ) . fill ( & mut filler) . build ( ) ) ;
2097
+ let substs = TyBuilder :: subst_for_def ( db, self . id , parent_substs) . fill ( & mut filler) . build ( ) ;
2098
2098
2099
2099
let callable_sig = db. callable_item_signature ( self . id . into ( ) ) . substitute ( Interner , & substs) ;
2100
2100
let ty = callable_sig. ret ( ) . clone ( ) ;
@@ -2412,11 +2412,7 @@ impl SelfParam {
2412
2412
Type { env : environment, ty }
2413
2413
}
2414
2414
2415
- pub fn ty_with_generics (
2416
- & self ,
2417
- db : & dyn HirDatabase ,
2418
- mut generics : impl Iterator < Item = Type > ,
2419
- ) -> Type {
2415
+ pub fn ty_with_args ( & self , db : & dyn HirDatabase , generics : impl Iterator < Item = Type > ) -> Type {
2420
2416
let parent_id: GenericDefId = match self . func . lookup ( db. upcast ( ) ) . container {
2421
2417
ItemContainerId :: ImplId ( it) => it. into ( ) ,
2422
2418
ItemContainerId :: TraitId ( it) => it. into ( ) ,
@@ -2425,16 +2421,18 @@ impl SelfParam {
2425
2421
}
2426
2422
} ;
2427
2423
2428
- let parent_substs = TyBuilder :: subst_for_def ( db, parent_id, None )
2429
- . fill ( |_| {
2430
- GenericArg :: new ( Interner , GenericArgData :: Ty ( generics. next ( ) . unwrap ( ) . ty . clone ( ) ) )
2431
- } )
2432
- . build ( ) ;
2433
- let substs = TyBuilder :: subst_for_def ( db, self . func , Some ( parent_substs) )
2434
- . fill ( |_| {
2435
- GenericArg :: new ( Interner , GenericArgData :: Ty ( generics. next ( ) . unwrap ( ) . ty . clone ( ) ) )
2436
- } )
2437
- . build ( ) ;
2424
+ let mut generics = generics. map ( |it| it. ty . clone ( ) ) ;
2425
+ let mut filler = |x : & _ | {
2426
+ let ty = generics. next ( ) . unwrap_or_else ( || TyKind :: Error . intern ( Interner ) ) ;
2427
+ match x {
2428
+ ParamKind :: Type => ty. cast ( Interner ) ,
2429
+ ParamKind :: Const ( ty) => unknown_const_as_generic ( ty. clone ( ) ) ,
2430
+ }
2431
+ } ;
2432
+
2433
+ let parent_substs = TyBuilder :: subst_for_def ( db, parent_id, None ) . fill ( & mut filler) . build ( ) ;
2434
+ let substs =
2435
+ TyBuilder :: subst_for_def ( db, self . func , Some ( parent_substs) ) . fill ( & mut filler) . build ( ) ;
2438
2436
let callable_sig =
2439
2437
db. callable_item_signature ( self . func . into ( ) ) . substitute ( Interner , & substs) ;
2440
2438
let environment = db. trait_environment ( self . func . into ( ) ) ;
0 commit comments