@@ -496,15 +496,32 @@ impl<'tcx> PlaceSet<'tcx> {
496496 }
497497
498498 fn record_debuginfo ( & mut self , var_debug_info : & Vec < VarDebugInfo < ' tcx > > ) {
499+ let ignore_name = |name : Symbol | {
500+ name == sym:: empty || name == kw:: SelfLower || name. as_str ( ) . starts_with ( '_' )
501+ } ;
499502 for var_debug_info in var_debug_info {
500503 if let VarDebugInfoContents :: Place ( place) = var_debug_info. value
501504 && let Some ( index) = self . locals [ place. local ]
505+ && !ignore_name ( var_debug_info. name )
502506 {
503507 self . names . get_or_insert_with ( index, || {
504508 ( var_debug_info. name , var_debug_info. source_info . span )
505509 } ) ;
506510 }
507511 }
512+
513+ // Discard places that will not result in a diagnostic.
514+ for index_opt in self . locals . iter_mut ( ) {
515+ if let Some ( index) = * index_opt {
516+ let remove = match self . names [ index] {
517+ None => true ,
518+ Some ( ( name, _) ) => ignore_name ( name) ,
519+ } ;
520+ if remove {
521+ * index_opt = None ;
522+ }
523+ }
524+ }
508525 }
509526
510527 fn get ( & self , place : PlaceRef < ' tcx > ) -> Option < ( PlaceIndex , & ' tcx [ PlaceElem < ' tcx > ] ) > {
@@ -793,11 +810,6 @@ impl AssignmentResult {
793810 continue ;
794811 }
795812
796- let Some ( ( name, def_span) ) = checked_places. names [ index] else { continue } ;
797- if name. is_empty ( ) || name. as_str ( ) . starts_with ( '_' ) || name == kw:: SelfLower {
798- continue ;
799- }
800-
801813 let local = place. local ;
802814 let decl = & body. local_decls [ local] ;
803815
@@ -813,6 +825,8 @@ impl AssignmentResult {
813825
814826 let introductions = & binding. introductions ;
815827
828+ let Some ( ( name, def_span) ) = checked_places. names [ index] else { continue } ;
829+
816830 // #117284, when `ident_span` and `def_span` have different contexts
817831 // we can't provide a good suggestion, instead we pointed out the spans from macro
818832 let from_macro = def_span. from_expansion ( )
@@ -932,9 +946,6 @@ impl AssignmentResult {
932946 }
933947
934948 let Some ( ( name, decl_span) ) = checked_places. names [ index] else { continue } ;
935- if name. is_empty ( ) || name. as_str ( ) . starts_with ( '_' ) || name == kw:: SelfLower {
936- continue ;
937- }
938949
939950 // We have outstanding assignments and with non-trivial drop.
940951 // This is probably a drop-guard, so we do not issue a warning there.
0 commit comments