@@ -607,15 +607,42 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
607
607
} ;
608
608
let upvar_tys = upvar_substs. upvar_tys ( def_id, tcx) ;
609
609
610
- for ( i, ( decl, ty) ) in mir. upvar_decls . iter ( ) . zip ( upvar_tys) . enumerate ( ) {
611
- let byte_offset_of_var_in_env = closure_layout. fields . offset ( i) . bytes ( ) ;
610
+ let extra_locals = {
611
+ let upvars = mir. upvar_decls
612
+ . iter ( )
613
+ . zip ( upvar_tys)
614
+ . enumerate ( )
615
+ . map ( |( i, ( decl, ty) ) | ( i, decl. debug_name , decl. by_ref , ty) ) ;
616
+
617
+ let generator_fields = mir. generator_layout . as_ref ( ) . map ( |generator_layout| {
618
+ let ( def_id, gen_substs) = match closure_layout. ty . sty {
619
+ ty:: Generator ( def_id, substs, _) => ( def_id, substs) ,
620
+ _ => bug ! ( "generator layout without generator substs" ) ,
621
+ } ;
622
+ let state_tys = gen_substs. state_tys ( def_id, tcx) ;
623
+
624
+ let upvar_count = mir. upvar_decls . len ( ) ;
625
+ generator_layout. fields
626
+ . iter ( )
627
+ . zip ( state_tys)
628
+ . enumerate ( )
629
+ . filter_map ( move |( i, ( decl, ty) ) | {
630
+ decl. name . map ( |name| ( i + upvar_count + 1 , name, false , ty) )
631
+ } )
632
+ } ) . into_iter ( ) . flatten ( ) ;
633
+
634
+ upvars. chain ( generator_fields)
635
+ } ;
636
+
637
+ for ( field, name, by_ref, ty) in extra_locals {
638
+ let byte_offset_of_var_in_env = closure_layout. fields . offset ( field) . bytes ( ) ;
612
639
613
640
let ops = bx. debuginfo_upvar_decls_ops_sequence ( byte_offset_of_var_in_env) ;
614
641
615
642
// The environment and the capture can each be indirect.
616
643
let mut ops = if env_ref { & ops[ ..] } else { & ops[ 1 ..] } ;
617
644
618
- let ty = if let ( true , & ty:: Ref ( _, ty, _) ) = ( decl . by_ref , & ty. sty ) {
645
+ let ty = if let ( true , & ty:: Ref ( _, ty, _) ) = ( by_ref, & ty. sty ) {
619
646
ty
620
647
} else {
621
648
ops = & ops[ ..ops. len ( ) - 1 ] ;
@@ -628,7 +655,7 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
628
655
} ;
629
656
bx. declare_local (
630
657
& fx. debug_context ,
631
- decl . debug_name ,
658
+ name ,
632
659
ty,
633
660
scope,
634
661
variable_access,
0 commit comments