@@ -1085,20 +1085,21 @@ impl Field {
1085
1085
Type :: new ( db, var_id, ty)
1086
1086
}
1087
1087
1088
- pub fn ty_with_generics (
1089
- & self ,
1090
- db : & dyn HirDatabase ,
1091
- mut generics : impl Iterator < Item = Type > ,
1092
- ) -> Type {
1088
+ pub fn ty_with_args ( & self , db : & dyn HirDatabase , generics : impl Iterator < Item = Type > ) -> Type {
1093
1089
let var_id = self . parent . into ( ) ;
1094
1090
let def_id: AdtId = match self . parent {
1095
1091
VariantDef :: Struct ( it) => it. id . into ( ) ,
1096
1092
VariantDef :: Union ( it) => it. id . into ( ) ,
1097
1093
VariantDef :: Variant ( it) => it. parent_enum ( db) . id . into ( ) ,
1098
1094
} ;
1095
+ let mut generics = generics. map ( |it| it. ty . clone ( ) ) ;
1099
1096
let substs = TyBuilder :: subst_for_def ( db, def_id, None )
1100
- . fill ( |_| {
1101
- GenericArg :: new ( Interner , GenericArgData :: Ty ( generics. next ( ) . unwrap ( ) . ty . clone ( ) ) )
1097
+ . fill ( |x| {
1098
+ let ty = generics. next ( ) . unwrap_or_else ( || TyKind :: Error . intern ( Interner ) ) ;
1099
+ match x {
1100
+ ParamKind :: Type => ty. cast ( Interner ) ,
1101
+ ParamKind :: Const ( ty) => unknown_const_as_generic ( ty. clone ( ) ) ,
1102
+ }
1102
1103
} )
1103
1104
. build ( ) ;
1104
1105
let ty = db. field_types ( var_id) [ self . id ] . clone ( ) . substitute ( Interner , & substs) ;
@@ -1158,14 +1159,15 @@ impl Struct {
1158
1159
Type :: from_def ( db, self . id )
1159
1160
}
1160
1161
1161
- pub fn ty_with_generics (
1162
- self ,
1163
- db : & dyn HirDatabase ,
1164
- mut generics : impl Iterator < Item = Type > ,
1165
- ) -> Type {
1162
+ pub fn ty_with_args ( self , db : & dyn HirDatabase , generics : impl Iterator < Item = Type > ) -> Type {
1163
+ let mut generics = generics. map ( |it| it. ty . clone ( ) ) ;
1166
1164
let substs = TyBuilder :: subst_for_def ( db, self . id , None )
1167
- . fill ( |_| {
1168
- GenericArg :: new ( Interner , GenericArgData :: Ty ( generics. next ( ) . unwrap ( ) . ty . clone ( ) ) )
1165
+ . fill ( |x| {
1166
+ let ty = generics. next ( ) . unwrap_or_else ( || TyKind :: Error . intern ( Interner ) ) ;
1167
+ match x {
1168
+ ParamKind :: Type => ty. cast ( Interner ) ,
1169
+ ParamKind :: Const ( ty) => unknown_const_as_generic ( ty. clone ( ) ) ,
1170
+ }
1169
1171
} )
1170
1172
. build ( ) ;
1171
1173
let ty = db. ty ( self . id . into ( ) ) . substitute ( Interner , & substs) ;
@@ -1271,16 +1273,18 @@ impl Enum {
1271
1273
Type :: from_def ( db, self . id )
1272
1274
}
1273
1275
1274
- pub fn ty_with_generics (
1275
- & self ,
1276
- db : & dyn HirDatabase ,
1277
- mut generics : impl Iterator < Item = Type > ,
1278
- ) -> Type {
1276
+ pub fn ty_with_args ( & self , db : & dyn HirDatabase , generics : impl Iterator < Item = Type > ) -> Type {
1277
+ let mut generics = generics. map ( |it| it. ty . clone ( ) ) ;
1279
1278
let substs = TyBuilder :: subst_for_def ( db, self . id , None )
1280
- . fill ( |_| {
1281
- GenericArg :: new ( Interner , GenericArgData :: Ty ( generics. next ( ) . unwrap ( ) . ty . clone ( ) ) )
1279
+ . fill ( |x| {
1280
+ let ty = generics. next ( ) . unwrap_or_else ( || TyKind :: Error . intern ( Interner ) ) ;
1281
+ match x {
1282
+ ParamKind :: Type => ty. cast ( Interner ) ,
1283
+ ParamKind :: Const ( ty) => unknown_const_as_generic ( ty. clone ( ) ) ,
1284
+ }
1282
1285
} )
1283
1286
. build ( ) ;
1287
+
1284
1288
let ty = db. ty ( self . id . into ( ) ) . substitute ( Interner , & substs) ;
1285
1289
Type :: new ( db, self . id , ty)
1286
1290
}
@@ -1854,33 +1858,29 @@ impl Function {
1854
1858
Type :: new_with_resolver_inner ( db, & resolver, ty)
1855
1859
}
1856
1860
1857
- pub fn ret_type_with_generics (
1861
+ pub fn ret_type_with_args (
1858
1862
self ,
1859
1863
db : & dyn HirDatabase ,
1860
- mut generics : impl Iterator < Item = Type > ,
1864
+ generics : impl Iterator < Item = Type > ,
1861
1865
) -> Type {
1862
1866
let resolver = self . id . resolver ( db. upcast ( ) ) ;
1863
1867
let parent_id: Option < GenericDefId > = match self . id . lookup ( db. upcast ( ) ) . container {
1864
1868
ItemContainerId :: ImplId ( it) => Some ( it. into ( ) ) ,
1865
1869
ItemContainerId :: TraitId ( it) => Some ( it. into ( ) ) ,
1866
1870
ItemContainerId :: ModuleId ( _) | ItemContainerId :: ExternBlockId ( _) => None ,
1867
1871
} ;
1868
- let parent_substs = parent_id. map ( |id| {
1869
- TyBuilder :: subst_for_def ( db, id, None )
1870
- . fill ( |_| {
1871
- GenericArg :: new (
1872
- Interner ,
1873
- GenericArgData :: Ty ( generics. next ( ) . unwrap ( ) . ty . clone ( ) ) ,
1874
- )
1875
- } )
1876
- . build ( )
1877
- } ) ;
1872
+ let mut generics = generics. map ( |it| it. ty . clone ( ) ) ;
1873
+ let mut filler = |x : & _ | {
1874
+ let ty = generics. next ( ) . unwrap_or_else ( || TyKind :: Error . intern ( Interner ) ) ;
1875
+ match x {
1876
+ ParamKind :: Type => ty. cast ( Interner ) ,
1877
+ ParamKind :: Const ( ty) => unknown_const_as_generic ( ty. clone ( ) ) ,
1878
+ }
1879
+ } ;
1878
1880
1879
- let substs = TyBuilder :: subst_for_def ( db, self . id , parent_substs)
1880
- . fill ( |_| {
1881
- GenericArg :: new ( Interner , GenericArgData :: Ty ( generics. next ( ) . unwrap ( ) . ty . clone ( ) ) )
1882
- } )
1883
- . build ( ) ;
1881
+ let parent_substs =
1882
+ parent_id. map ( |id| TyBuilder :: subst_for_def ( db, id, None ) . fill ( & mut filler) . build ( ) ) ;
1883
+ let substs = TyBuilder :: subst_for_def ( db, self . id , parent_substs) . fill ( & mut filler) . build ( ) ;
1884
1884
1885
1885
let callable_sig = db. callable_item_signature ( self . id . into ( ) ) . substitute ( Interner , & substs) ;
1886
1886
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