@@ -1218,22 +1218,35 @@ pub fn typeid_for_instance<'tcx>(
12181218 let trait_id = tcx. fn_trait_kind_to_def_id ( closure_args. kind ( ) ) . unwrap ( ) ;
12191219 let tuple_args =
12201220 tcx. instantiate_bound_regions_with_erased ( closure_args. sig ( ) ) . inputs ( ) [ 0 ] ;
1221- ( trait_id, tuple_args)
1221+ ( trait_id, Some ( tuple_args) )
12221222 }
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+ } ,
12271237 ty:: CoroutineClosure ( ..) => (
12281238 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+ ) ,
12331245 ) ,
12341246 x => bug ! ( "Unexpected type kind for closure-like: {x:?}" ) ,
12351247 } ;
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) ;
12371250 let invoke_ty = trait_object_ty ( tcx, ty:: Binder :: dummy ( trait_ref) ) ;
12381251 let abstract_args = tcx. mk_args_trait ( invoke_ty, trait_ref. args . into_iter ( ) . skip ( 1 ) ) ;
12391252 // There should be exactly one method on this trait, and it should be the one we're
0 commit comments