@@ -495,15 +495,32 @@ impl<'tcx> PlaceSet<'tcx> {
495
495
}
496
496
497
497
fn record_debuginfo ( & mut self , var_debug_info : & Vec < VarDebugInfo < ' tcx > > ) {
498
+ let ignore_name = |name : Symbol | {
499
+ name == sym:: empty || name == kw:: SelfLower || name. as_str ( ) . starts_with ( '_' )
500
+ } ;
498
501
for var_debug_info in var_debug_info {
499
502
if let VarDebugInfoContents :: Place ( place) = var_debug_info. value
500
503
&& let Some ( index) = self . locals [ place. local ]
504
+ && !ignore_name ( var_debug_info. name )
501
505
{
502
506
self . names . get_or_insert_with ( index, || {
503
507
( var_debug_info. name , var_debug_info. source_info . span )
504
508
} ) ;
505
509
}
506
510
}
511
+
512
+ // Discard places that will not result in a diagnostic.
513
+ for index_opt in self . locals . iter_mut ( ) {
514
+ if let Some ( index) = * index_opt {
515
+ let remove = match self . names [ index] {
516
+ None => true ,
517
+ Some ( ( name, _) ) => ignore_name ( name) ,
518
+ } ;
519
+ if remove {
520
+ * index_opt = None ;
521
+ }
522
+ }
523
+ }
507
524
}
508
525
509
526
fn get ( & self , place : PlaceRef < ' tcx > ) -> Option < ( PlaceIndex , & ' tcx [ PlaceElem < ' tcx > ] ) > {
@@ -792,11 +809,6 @@ impl AssignmentResult {
792
809
continue ;
793
810
}
794
811
795
- let Some ( ( name, def_span) ) = checked_places. names [ index] else { continue } ;
796
- if name. is_empty ( ) || name. as_str ( ) . starts_with ( '_' ) || name == kw:: SelfLower {
797
- continue ;
798
- }
799
-
800
812
let local = place. local ;
801
813
let decl = & body. local_decls [ local] ;
802
814
@@ -812,6 +824,8 @@ impl AssignmentResult {
812
824
813
825
let introductions = & binding. introductions ;
814
826
827
+ let Some ( ( name, def_span) ) = checked_places. names [ index] else { continue } ;
828
+
815
829
// #117284, when `ident_span` and `def_span` have different contexts
816
830
// we can't provide a good suggestion, instead we pointed out the spans from macro
817
831
let from_macro = def_span. from_expansion ( )
@@ -931,9 +945,6 @@ impl AssignmentResult {
931
945
}
932
946
933
947
let Some ( ( name, decl_span) ) = checked_places. names [ index] else { continue } ;
934
- if name. is_empty ( ) || name. as_str ( ) . starts_with ( '_' ) || name == kw:: SelfLower {
935
- continue ;
936
- }
937
948
938
949
// We have outstanding assignments and with non-trivial drop.
939
950
// This is probably a drop-guard, so we do not issue a warning there.
0 commit comments