@@ -1084,20 +1084,21 @@ impl Field {
1084
1084
Type :: new ( db, var_id, ty)
1085
1085
}
1086
1086
1087
- pub fn ty_with_generics (
1088
- & self ,
1089
- db : & dyn HirDatabase ,
1090
- mut generics : impl Iterator < Item = Type > ,
1091
- ) -> Type {
1087
+ pub fn ty_with_args ( & self , db : & dyn HirDatabase , generics : impl Iterator < Item = Type > ) -> Type {
1092
1088
let var_id = self . parent . into ( ) ;
1093
1089
let def_id: AdtId = match self . parent {
1094
1090
VariantDef :: Struct ( it) => it. id . into ( ) ,
1095
1091
VariantDef :: Union ( it) => it. id . into ( ) ,
1096
1092
VariantDef :: Variant ( it) => it. parent_enum ( db) . id . into ( ) ,
1097
1093
} ;
1094
+ let mut generics = generics. map ( |it| it. ty . clone ( ) ) ;
1098
1095
let substs = TyBuilder :: subst_for_def ( db, def_id, None )
1099
- . fill ( |_| {
1100
- GenericArg :: new ( Interner , GenericArgData :: Ty ( generics. next ( ) . unwrap ( ) . ty . clone ( ) ) )
1096
+ . fill ( |x| {
1097
+ let ty = generics. next ( ) . unwrap_or_else ( || TyKind :: Error . intern ( Interner ) ) ;
1098
+ match x {
1099
+ ParamKind :: Type => ty. cast ( Interner ) ,
1100
+ ParamKind :: Const ( ty) => unknown_const_as_generic ( ty. clone ( ) ) ,
1101
+ }
1101
1102
} )
1102
1103
. build ( ) ;
1103
1104
let ty = db. field_types ( var_id) [ self . id ] . clone ( ) . substitute ( Interner , & substs) ;
@@ -1157,14 +1158,15 @@ impl Struct {
1157
1158
Type :: from_def ( db, self . id )
1158
1159
}
1159
1160
1160
- pub fn ty_with_generics (
1161
- self ,
1162
- db : & dyn HirDatabase ,
1163
- mut generics : impl Iterator < Item = Type > ,
1164
- ) -> Type {
1161
+ pub fn ty_with_args ( self , db : & dyn HirDatabase , generics : impl Iterator < Item = Type > ) -> Type {
1162
+ let mut generics = generics. map ( |it| it. ty . clone ( ) ) ;
1165
1163
let substs = TyBuilder :: subst_for_def ( db, self . id , None )
1166
- . fill ( |_| {
1167
- GenericArg :: new ( Interner , GenericArgData :: Ty ( generics. next ( ) . unwrap ( ) . ty . clone ( ) ) )
1164
+ . fill ( |x| {
1165
+ let ty = generics. next ( ) . unwrap_or_else ( || TyKind :: Error . intern ( Interner ) ) ;
1166
+ match x {
1167
+ ParamKind :: Type => ty. cast ( Interner ) ,
1168
+ ParamKind :: Const ( ty) => unknown_const_as_generic ( ty. clone ( ) ) ,
1169
+ }
1168
1170
} )
1169
1171
. build ( ) ;
1170
1172
let ty = db. ty ( self . id . into ( ) ) . substitute ( Interner , & substs) ;
@@ -1270,16 +1272,18 @@ impl Enum {
1270
1272
Type :: from_def ( db, self . id )
1271
1273
}
1272
1274
1273
- pub fn ty_with_generics (
1274
- & self ,
1275
- db : & dyn HirDatabase ,
1276
- mut generics : impl Iterator < Item = Type > ,
1277
- ) -> Type {
1275
+ pub fn ty_with_args ( & self , db : & dyn HirDatabase , generics : impl Iterator < Item = Type > ) -> Type {
1276
+ let mut generics = generics. map ( |it| it. ty . clone ( ) ) ;
1278
1277
let substs = TyBuilder :: subst_for_def ( db, self . id , None )
1279
- . fill ( |_| {
1280
- GenericArg :: new ( Interner , GenericArgData :: Ty ( generics. next ( ) . unwrap ( ) . ty . clone ( ) ) )
1278
+ . fill ( |x| {
1279
+ let ty = generics. next ( ) . unwrap_or_else ( || TyKind :: Error . intern ( Interner ) ) ;
1280
+ match x {
1281
+ ParamKind :: Type => ty. cast ( Interner ) ,
1282
+ ParamKind :: Const ( ty) => unknown_const_as_generic ( ty. clone ( ) ) ,
1283
+ }
1281
1284
} )
1282
1285
. build ( ) ;
1286
+
1283
1287
let ty = db. ty ( self . id . into ( ) ) . substitute ( Interner , & substs) ;
1284
1288
Type :: new ( db, self . id , ty)
1285
1289
}
@@ -1853,33 +1857,29 @@ impl Function {
1853
1857
Type :: new_with_resolver_inner ( db, & resolver, ty)
1854
1858
}
1855
1859
1856
- pub fn ret_type_with_generics (
1860
+ pub fn ret_type_with_args (
1857
1861
self ,
1858
1862
db : & dyn HirDatabase ,
1859
- mut generics : impl Iterator < Item = Type > ,
1863
+ generics : impl Iterator < Item = Type > ,
1860
1864
) -> Type {
1861
1865
let resolver = self . id . resolver ( db. upcast ( ) ) ;
1862
1866
let parent_id: Option < GenericDefId > = match self . id . lookup ( db. upcast ( ) ) . container {
1863
1867
ItemContainerId :: ImplId ( it) => Some ( it. into ( ) ) ,
1864
1868
ItemContainerId :: TraitId ( it) => Some ( it. into ( ) ) ,
1865
1869
ItemContainerId :: ModuleId ( _) | ItemContainerId :: ExternBlockId ( _) => None ,
1866
1870
} ;
1867
- let parent_substs = parent_id. map ( |id| {
1868
- TyBuilder :: subst_for_def ( db, id, None )
1869
- . fill ( |_| {
1870
- GenericArg :: new (
1871
- Interner ,
1872
- GenericArgData :: Ty ( generics. next ( ) . unwrap ( ) . ty . clone ( ) ) ,
1873
- )
1874
- } )
1875
- . build ( )
1876
- } ) ;
1871
+ let mut generics = generics. map ( |it| it. ty . clone ( ) ) ;
1872
+ let mut filler = |x : & _ | {
1873
+ let ty = generics. next ( ) . unwrap_or_else ( || TyKind :: Error . intern ( Interner ) ) ;
1874
+ match x {
1875
+ ParamKind :: Type => ty. cast ( Interner ) ,
1876
+ ParamKind :: Const ( ty) => unknown_const_as_generic ( ty. clone ( ) ) ,
1877
+ }
1878
+ } ;
1877
1879
1878
- let substs = TyBuilder :: subst_for_def ( db, self . id , parent_substs)
1879
- . fill ( |_| {
1880
- GenericArg :: new ( Interner , GenericArgData :: Ty ( generics. next ( ) . unwrap ( ) . ty . clone ( ) ) )
1881
- } )
1882
- . build ( ) ;
1880
+ let parent_substs =
1881
+ parent_id. map ( |id| TyBuilder :: subst_for_def ( db, id, None ) . fill ( & mut filler) . build ( ) ) ;
1882
+ let substs = TyBuilder :: subst_for_def ( db, self . id , parent_substs) . fill ( & mut filler) . build ( ) ;
1883
1883
1884
1884
let callable_sig = db. callable_item_signature ( self . id . into ( ) ) . substitute ( Interner , & substs) ;
1885
1885
let ty = callable_sig. ret ( ) . clone ( ) ;
@@ -2197,11 +2197,7 @@ impl SelfParam {
2197
2197
Type { env : environment, ty }
2198
2198
}
2199
2199
2200
- pub fn ty_with_generics (
2201
- & self ,
2202
- db : & dyn HirDatabase ,
2203
- mut generics : impl Iterator < Item = Type > ,
2204
- ) -> Type {
2200
+ pub fn ty_with_args ( & self , db : & dyn HirDatabase , generics : impl Iterator < Item = Type > ) -> Type {
2205
2201
let parent_id: GenericDefId = match self . func . lookup ( db. upcast ( ) ) . container {
2206
2202
ItemContainerId :: ImplId ( it) => it. into ( ) ,
2207
2203
ItemContainerId :: TraitId ( it) => it. into ( ) ,
@@ -2210,16 +2206,18 @@ impl SelfParam {
2210
2206
}
2211
2207
} ;
2212
2208
2213
- let parent_substs = TyBuilder :: subst_for_def ( db, parent_id, None )
2214
- . fill ( |_| {
2215
- GenericArg :: new ( Interner , GenericArgData :: Ty ( generics. next ( ) . unwrap ( ) . ty . clone ( ) ) )
2216
- } )
2217
- . build ( ) ;
2218
- let substs = TyBuilder :: subst_for_def ( db, self . func , Some ( parent_substs) )
2219
- . fill ( |_| {
2220
- GenericArg :: new ( Interner , GenericArgData :: Ty ( generics. next ( ) . unwrap ( ) . ty . clone ( ) ) )
2221
- } )
2222
- . build ( ) ;
2209
+ let mut generics = generics. map ( |it| it. ty . clone ( ) ) ;
2210
+ let mut filler = |x : & _ | {
2211
+ let ty = generics. next ( ) . unwrap_or_else ( || TyKind :: Error . intern ( Interner ) ) ;
2212
+ match x {
2213
+ ParamKind :: Type => ty. cast ( Interner ) ,
2214
+ ParamKind :: Const ( ty) => unknown_const_as_generic ( ty. clone ( ) ) ,
2215
+ }
2216
+ } ;
2217
+
2218
+ let parent_substs = TyBuilder :: subst_for_def ( db, parent_id, None ) . fill ( & mut filler) . build ( ) ;
2219
+ let substs =
2220
+ TyBuilder :: subst_for_def ( db, self . func , Some ( parent_substs) ) . fill ( & mut filler) . build ( ) ;
2223
2221
let callable_sig =
2224
2222
db. callable_item_signature ( self . func . into ( ) ) . substitute ( Interner , & substs) ;
2225
2223
let environment = db. trait_environment ( self . func . into ( ) ) ;
0 commit comments