@@ -659,15 +659,42 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
659659 } ;
660660 let upvar_tys = upvar_substs. upvar_tys ( def_id, tcx) ;
661661
662- for ( i, ( decl, ty) ) in mir. upvar_decls . iter ( ) . zip ( upvar_tys) . enumerate ( ) {
663- let byte_offset_of_var_in_env = closure_layout. fields . offset ( i) . bytes ( ) ;
662+ let extra_locals = {
663+ let upvars = mir. upvar_decls
664+ . iter ( )
665+ . zip ( upvar_tys)
666+ . enumerate ( )
667+ . map ( |( i, ( decl, ty) ) | ( i, decl. debug_name , decl. by_ref , ty) ) ;
668+
669+ let generator_fields = mir. generator_layout . as_ref ( ) . map ( |generator_layout| {
670+ let ( def_id, gen_substs) = match closure_layout. ty . sty {
671+ ty:: Generator ( def_id, substs, _) => ( def_id, substs) ,
672+ _ => bug ! ( "generator layout without generator substs" ) ,
673+ } ;
674+ let state_tys = gen_substs. state_tys ( def_id, tcx) ;
675+
676+ let upvar_count = mir. upvar_decls . len ( ) ;
677+ generator_layout. fields
678+ . iter ( )
679+ . zip ( state_tys)
680+ . enumerate ( )
681+ . filter_map ( move |( i, ( decl, ty) ) | {
682+ decl. name . map ( |name| ( i + upvar_count + 1 , name, false , ty) )
683+ } )
684+ } ) . into_iter ( ) . flatten ( ) ;
685+
686+ upvars. chain ( generator_fields)
687+ } ;
688+
689+ for ( field, name, by_ref, ty) in extra_locals {
690+ let byte_offset_of_var_in_env = closure_layout. fields . offset ( field) . bytes ( ) ;
664691
665692 let ops = bx. debuginfo_upvar_decls_ops_sequence ( byte_offset_of_var_in_env) ;
666693
667694 // The environment and the capture can each be indirect.
668695 let mut ops = if env_ref { & ops[ ..] } else { & ops[ 1 ..] } ;
669696
670- let ty = if let ( true , & ty:: Ref ( _, ty, _) ) = ( decl . by_ref , & ty. sty ) {
697+ let ty = if let ( true , & ty:: Ref ( _, ty, _) ) = ( by_ref, & ty. sty ) {
671698 ty
672699 } else {
673700 ops = & ops[ ..ops. len ( ) - 1 ] ;
@@ -680,7 +707,7 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
680707 } ;
681708 bx. declare_local (
682709 & fx. debug_context ,
683- decl . debug_name ,
710+ name ,
684711 ty,
685712 scope,
686713 variable_access,
0 commit comments