@@ -13,13 +13,13 @@ use std::sync::Arc;
13
13
use rustc_abi:: VariantIdx ;
14
14
use rustc_data_structures:: fx:: FxIndexMap ;
15
15
use rustc_data_structures:: stack:: ensure_sufficient_stack;
16
- use rustc_hir:: { BindingMode , ByRef } ;
16
+ use rustc_hir:: { BindingMode , ByRef , LetStmt , LocalSource , Node } ;
17
17
use rustc_middle:: bug;
18
18
use rustc_middle:: middle:: region;
19
19
use rustc_middle:: mir:: { self , * } ;
20
20
use rustc_middle:: thir:: { self , * } ;
21
21
use rustc_middle:: ty:: { self , CanonicalUserTypeAnnotation , Ty } ;
22
- use rustc_span:: { BytePos , Pos , Span , Symbol } ;
22
+ use rustc_span:: { BytePos , Pos , Span , Symbol , sym } ;
23
23
use tracing:: { debug, instrument} ;
24
24
25
25
use crate :: builder:: ForGuard :: { self , OutsideGuard , RefWithinGuard } ;
@@ -2796,13 +2796,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
2796
2796
) ) ) ) ,
2797
2797
} ;
2798
2798
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
+ }
2806
2808
let locals = if has_guard. 0 {
2807
2809
let ref_for_guard = self . local_decls . push ( LocalDecl :: < ' tcx > {
2808
2810
// This variable isn't mutated but has a name, so has to be
@@ -2815,18 +2817,42 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
2815
2817
BindingForm :: RefForGuard ,
2816
2818
) ) ) ,
2817
2819
} ) ;
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
+ }
2825
2829
LocalsForNode :: ForGuard { ref_for_guard, for_arm_body }
2826
2830
} else {
2827
2831
LocalsForNode :: One ( for_arm_body)
2828
2832
} ;
2829
2833
debug ! ( ?locals) ;
2830
2834
self . var_indices . insert ( var_id, locals) ;
2831
2835
}
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
+ }
2832
2858
}
0 commit comments