@@ -1218,22 +1218,35 @@ pub fn typeid_for_instance<'tcx>(
1218
1218
let trait_id = tcx. fn_trait_kind_to_def_id ( closure_args. kind ( ) ) . unwrap ( ) ;
1219
1219
let tuple_args =
1220
1220
tcx. instantiate_bound_regions_with_erased ( closure_args. sig ( ) ) . inputs ( ) [ 0 ] ;
1221
- ( trait_id, tuple_args)
1221
+ ( trait_id, Some ( tuple_args) )
1222
1222
}
1223
- ty:: Coroutine ( ..) => (
1224
- tcx. require_lang_item ( LangItem :: Coroutine , None ) ,
1225
- instance. args . as_coroutine ( ) . resume_ty ( ) ,
1226
- ) ,
1223
+ ty:: Coroutine ( ..) => match tcx. coroutine_kind ( instance. def_id ( ) ) . unwrap ( ) {
1224
+ hir:: CoroutineKind :: Coroutine ( ..) => (
1225
+ tcx. require_lang_item ( LangItem :: Coroutine , None ) ,
1226
+ Some ( instance. args . as_coroutine ( ) . resume_ty ( ) ) ,
1227
+ ) ,
1228
+ hir:: CoroutineKind :: Desugared ( desugaring, _) => {
1229
+ let lang_item = match desugaring {
1230
+ hir:: CoroutineDesugaring :: Async => LangItem :: Future ,
1231
+ hir:: CoroutineDesugaring :: AsyncGen => LangItem :: AsyncIterator ,
1232
+ hir:: CoroutineDesugaring :: Gen => LangItem :: Iterator ,
1233
+ } ;
1234
+ ( tcx. require_lang_item ( lang_item, None ) , None )
1235
+ }
1236
+ } ,
1227
1237
ty:: CoroutineClosure ( ..) => (
1228
1238
tcx. require_lang_item ( LangItem :: FnOnce , None ) ,
1229
- tcx. instantiate_bound_regions_with_erased (
1230
- instance. args . as_coroutine_closure ( ) . coroutine_closure_sig ( ) ,
1231
- )
1232
- . tupled_inputs_ty ,
1239
+ Some (
1240
+ tcx. instantiate_bound_regions_with_erased (
1241
+ instance. args . as_coroutine_closure ( ) . coroutine_closure_sig ( ) ,
1242
+ )
1243
+ . tupled_inputs_ty ,
1244
+ ) ,
1233
1245
) ,
1234
1246
x => bug ! ( "Unexpected type kind for closure-like: {x:?}" ) ,
1235
1247
} ;
1236
- let trait_ref = ty:: TraitRef :: new ( tcx, trait_id, [ closure_ty, inputs] ) ;
1248
+ let concrete_args = tcx. mk_args_trait ( closure_ty, inputs. map ( Into :: into) ) ;
1249
+ let trait_ref = ty:: TraitRef :: new ( tcx, trait_id, concrete_args) ;
1237
1250
let invoke_ty = trait_object_ty ( tcx, ty:: Binder :: dummy ( trait_ref) ) ;
1238
1251
let abstract_args = tcx. mk_args_trait ( invoke_ty, trait_ref. args . into_iter ( ) . skip ( 1 ) ) ;
1239
1252
// There should be exactly one method on this trait, and it should be the one we're
0 commit comments