@@ -16,7 +16,7 @@ use rustc_mir_dataflow::fmt::DebugWithContext;
16
16
use rustc_mir_dataflow:: { Analysis , Backward , ResultsCursor } ;
17
17
use rustc_session:: lint;
18
18
use rustc_span:: Span ;
19
- use rustc_span:: symbol:: { Symbol , kw} ;
19
+ use rustc_span:: symbol:: { Symbol , kw, sym } ;
20
20
21
21
use crate :: errors;
22
22
@@ -497,15 +497,32 @@ impl<'tcx> PlaceSet<'tcx> {
497
497
}
498
498
499
499
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
+ } ;
500
503
for var_debug_info in var_debug_info {
501
504
if let VarDebugInfoContents :: Place ( place) = var_debug_info. value
502
505
&& let Some ( index) = self . locals [ place. local ]
506
+ && !ignore_name ( var_debug_info. name )
503
507
{
504
508
self . names . get_or_insert_with ( index, || {
505
509
( var_debug_info. name , var_debug_info. source_info . span )
506
510
} ) ;
507
511
}
508
512
}
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
+ }
509
526
}
510
527
511
528
fn get ( & self , place : PlaceRef < ' tcx > ) -> Option < ( PlaceIndex , & ' tcx [ PlaceElem < ' tcx > ] ) > {
@@ -794,11 +811,6 @@ impl AssignmentResult {
794
811
continue ;
795
812
}
796
813
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
-
802
814
let local = place. local ;
803
815
let decl = & body. local_decls [ local] ;
804
816
@@ -814,6 +826,8 @@ impl AssignmentResult {
814
826
815
827
let introductions = & binding. introductions ;
816
828
829
+ let Some ( ( name, def_span) ) = checked_places. names [ index] else { continue } ;
830
+
817
831
// #117284, when `ident_span` and `def_span` have different contexts
818
832
// we can't provide a good suggestion, instead we pointed out the spans from macro
819
833
let from_macro = def_span. from_expansion ( )
@@ -933,9 +947,6 @@ impl AssignmentResult {
933
947
}
934
948
935
949
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
- }
939
950
940
951
// We have outstanding assignments and with non-trivial drop.
941
952
// This is probably a drop-guard, so we do not issue a warning there.
0 commit comments