@@ -16,7 +16,7 @@ use rustc_mir_dataflow::fmt::DebugWithContext;
1616use rustc_mir_dataflow:: { Analysis , Backward , ResultsCursor } ;
1717use rustc_session:: lint;
1818use rustc_span:: Span ;
19- use rustc_span:: symbol:: { Symbol , kw} ;
19+ use rustc_span:: symbol:: { Symbol , kw, sym } ;
2020
2121use crate :: errors;
2222
@@ -497,15 +497,32 @@ impl<'tcx> PlaceSet<'tcx> {
497497 }
498498
499499 fn record_debuginfo ( & mut self , var_debug_info : & Vec < VarDebugInfo < ' tcx > > ) {
500+ let ignore_name = |name : Symbol | {
501+ name == sym:: empty || name == kw:: SelfLower || name. as_str ( ) . starts_with ( '_' )
502+ } ;
500503 for var_debug_info in var_debug_info {
501504 if let VarDebugInfoContents :: Place ( place) = var_debug_info. value
502505 && let Some ( index) = self . locals [ place. local ]
506+ && !ignore_name ( var_debug_info. name )
503507 {
504508 self . names . get_or_insert_with ( index, || {
505509 ( var_debug_info. name , var_debug_info. source_info . span )
506510 } ) ;
507511 }
508512 }
513+
514+ // Discard places that will not result in a diagnostic.
515+ for index_opt in self . locals . iter_mut ( ) {
516+ if let Some ( index) = * index_opt {
517+ let remove = match self . names [ index] {
518+ None => true ,
519+ Some ( ( name, _) ) => ignore_name ( name) ,
520+ } ;
521+ if remove {
522+ * index_opt = None ;
523+ }
524+ }
525+ }
509526 }
510527
511528 fn get ( & self , place : PlaceRef < ' tcx > ) -> Option < ( PlaceIndex , & ' tcx [ PlaceElem < ' tcx > ] ) > {
@@ -794,11 +811,6 @@ impl AssignmentResult {
794811 continue ;
795812 }
796813
797- let Some ( ( name, def_span) ) = checked_places. names [ index] else { continue } ;
798- if name. is_empty ( ) || name. as_str ( ) . starts_with ( '_' ) || name == kw:: SelfLower {
799- continue ;
800- }
801-
802814 let local = place. local ;
803815 let decl = & body. local_decls [ local] ;
804816
@@ -814,6 +826,8 @@ impl AssignmentResult {
814826
815827 let introductions = & binding. introductions ;
816828
829+ let Some ( ( name, def_span) ) = checked_places. names [ index] else { continue } ;
830+
817831 // #117284, when `ident_span` and `def_span` have different contexts
818832 // we can't provide a good suggestion, instead we pointed out the spans from macro
819833 let from_macro = def_span. from_expansion ( )
@@ -933,9 +947,6 @@ impl AssignmentResult {
933947 }
934948
935949 let Some ( ( name, decl_span) ) = checked_places. names [ index] else { continue } ;
936- if name. is_empty ( ) || name. as_str ( ) . starts_with ( '_' ) || name == kw:: SelfLower {
937- continue ;
938- }
939950
940951 // We have outstanding assignments and with non-trivial drop.
941952 // This is probably a drop-guard, so we do not issue a warning there.
0 commit comments