@@ -659,15 +659,42 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
659
659
} ;
660
660
let upvar_tys = upvar_substs. upvar_tys ( def_id, tcx) ;
661
661
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 ( ) ;
664
691
665
692
let ops = bx. debuginfo_upvar_decls_ops_sequence ( byte_offset_of_var_in_env) ;
666
693
667
694
// The environment and the capture can each be indirect.
668
695
let mut ops = if env_ref { & ops[ ..] } else { & ops[ 1 ..] } ;
669
696
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 ) {
671
698
ty
672
699
} else {
673
700
ops = & ops[ ..ops. len ( ) - 1 ] ;
@@ -680,7 +707,7 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
680
707
} ;
681
708
bx. declare_local (
682
709
& fx. debug_context ,
683
- decl . debug_name ,
710
+ name ,
684
711
ty,
685
712
scope,
686
713
variable_access,
0 commit comments