@@ -13,13 +13,13 @@ use std::sync::Arc;
1313use rustc_abi:: VariantIdx ;
1414use rustc_data_structures:: fx:: FxIndexMap ;
1515use rustc_data_structures:: stack:: ensure_sufficient_stack;
16- use rustc_hir:: { BindingMode , ByRef } ;
16+ use rustc_hir:: { BindingMode , ByRef , LetStmt , LocalSource , Node } ;
1717use rustc_middle:: bug;
1818use rustc_middle:: middle:: region;
1919use rustc_middle:: mir:: { self , * } ;
2020use rustc_middle:: thir:: { self , * } ;
2121use rustc_middle:: ty:: { self , CanonicalUserTypeAnnotation , Ty } ;
22- use rustc_span:: { BytePos , Pos , Span , Symbol } ;
22+ use rustc_span:: { BytePos , Pos , Span , Symbol , sym } ;
2323use tracing:: { debug, instrument} ;
2424
2525use crate :: builder:: ForGuard :: { self , OutsideGuard , RefWithinGuard } ;
@@ -2796,13 +2796,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
27962796 ) ) ) ) ,
27972797 } ;
27982798 let for_arm_body = self . local_decls . push ( local) ;
2799- self . var_debug_info . push ( VarDebugInfo {
2800- name,
2801- source_info : debug_source_info,
2802- value : VarDebugInfoContents :: Place ( for_arm_body. into ( ) ) ,
2803- composite : None ,
2804- argument_index : None ,
2805- } ) ;
2799+ if self . should_emit_debug_info_for_binding ( name, var_id) {
2800+ self . var_debug_info . push ( VarDebugInfo {
2801+ name,
2802+ source_info : debug_source_info,
2803+ value : VarDebugInfoContents :: Place ( for_arm_body. into ( ) ) ,
2804+ composite : None ,
2805+ argument_index : None ,
2806+ } ) ;
2807+ }
28062808 let locals = if has_guard. 0 {
28072809 let ref_for_guard = self . local_decls . push ( LocalDecl :: < ' tcx > {
28082810 // This variable isn't mutated but has a name, so has to be
@@ -2815,18 +2817,42 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
28152817 BindingForm :: RefForGuard ,
28162818 ) ) ) ,
28172819 } ) ;
2818- self . var_debug_info . push ( VarDebugInfo {
2819- name,
2820- source_info : debug_source_info,
2821- value : VarDebugInfoContents :: Place ( ref_for_guard. into ( ) ) ,
2822- composite : None ,
2823- argument_index : None ,
2824- } ) ;
2820+ if self . should_emit_debug_info_for_binding ( name, var_id) {
2821+ self . var_debug_info . push ( VarDebugInfo {
2822+ name,
2823+ source_info : debug_source_info,
2824+ value : VarDebugInfoContents :: Place ( ref_for_guard. into ( ) ) ,
2825+ composite : None ,
2826+ argument_index : None ,
2827+ } ) ;
2828+ }
28252829 LocalsForNode :: ForGuard { ref_for_guard, for_arm_body }
28262830 } else {
28272831 LocalsForNode :: One ( for_arm_body)
28282832 } ;
28292833 debug ! ( ?locals) ;
28302834 self . var_indices . insert ( var_id, locals) ;
28312835 }
2836+
2837+ /// Some bindings are introduced when producing HIR from the AST and don't
2838+ /// actually exist in the source. Skip producing debug info for those when
2839+ /// we can recognize them.
2840+ fn should_emit_debug_info_for_binding ( & self , name : Symbol , var_id : LocalVarId ) -> bool {
2841+ // For now we only recognize the output of desugaring assigns.
2842+ if name != sym:: lhs {
2843+ return true ;
2844+ }
2845+
2846+ let tcx = self . tcx ;
2847+ for ( _, node) in tcx. hir_parent_iter ( var_id. 0 ) {
2848+ // FIXME(khuey) at what point is it safe to bail on the iterator?
2849+ // Can we stop at the first non-Pat node?
2850+ if matches ! ( node, Node :: LetStmt ( & LetStmt { source: LocalSource :: AssignDesugar ( _) , .. } ) )
2851+ {
2852+ return false ;
2853+ }
2854+ }
2855+
2856+ true
2857+ }
28322858}
0 commit comments