@@ -496,15 +496,32 @@ impl<'tcx> PlaceSet<'tcx> {
496
496
}
497
497
498
498
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
+ } ;
499
502
for var_debug_info in var_debug_info {
500
503
if let VarDebugInfoContents :: Place ( place) = var_debug_info. value
501
504
&& let Some ( index) = self . locals [ place. local ]
505
+ && !ignore_name ( var_debug_info. name )
502
506
{
503
507
self . names . get_or_insert_with ( index, || {
504
508
( var_debug_info. name , var_debug_info. source_info . span )
505
509
} ) ;
506
510
}
507
511
}
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
+ }
508
525
}
509
526
510
527
fn get ( & self , place : PlaceRef < ' tcx > ) -> Option < ( PlaceIndex , & ' tcx [ PlaceElem < ' tcx > ] ) > {
@@ -793,11 +810,6 @@ impl AssignmentResult {
793
810
continue ;
794
811
}
795
812
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
-
801
813
let local = place. local ;
802
814
let decl = & body. local_decls [ local] ;
803
815
@@ -813,6 +825,8 @@ impl AssignmentResult {
813
825
814
826
let introductions = & binding. introductions ;
815
827
828
+ let Some ( ( name, def_span) ) = checked_places. names [ index] else { continue } ;
829
+
816
830
// #117284, when `ident_span` and `def_span` have different contexts
817
831
// we can't provide a good suggestion, instead we pointed out the spans from macro
818
832
let from_macro = def_span. from_expansion ( )
@@ -932,9 +946,6 @@ impl AssignmentResult {
932
946
}
933
947
934
948
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
- }
938
949
939
950
// We have outstanding assignments and with non-trivial drop.
940
951
// This is probably a drop-guard, so we do not issue a warning there.
0 commit comments