Skip to content

Commit 38dcfc6

Browse files
committed
Discard anonymous locals from tracking.
1 parent f8126ac commit 38dcfc6

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

compiler/rustc_mir_transform/src/liveness.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -495,15 +495,32 @@ impl<'tcx> PlaceSet<'tcx> {
495495
}
496496

497497
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+
};
498501
for var_debug_info in var_debug_info {
499502
if let VarDebugInfoContents::Place(place) = var_debug_info.value
500503
&& let Some(index) = self.locals[place.local]
504+
&& !ignore_name(var_debug_info.name)
501505
{
502506
self.names.get_or_insert_with(index, || {
503507
(var_debug_info.name, var_debug_info.source_info.span)
504508
});
505509
}
506510
}
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+
}
507524
}
508525

509526
fn get(&self, place: PlaceRef<'tcx>) -> Option<(PlaceIndex, &'tcx [PlaceElem<'tcx>])> {
@@ -792,11 +809,6 @@ impl AssignmentResult {
792809
continue;
793810
}
794811

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-
800812
let local = place.local;
801813
let decl = &body.local_decls[local];
802814

@@ -812,6 +824,8 @@ impl AssignmentResult {
812824

813825
let introductions = &binding.introductions;
814826

827+
let Some((name, def_span)) = checked_places.names[index] else { continue };
828+
815829
// #117284, when `ident_span` and `def_span` have different contexts
816830
// we can't provide a good suggestion, instead we pointed out the spans from macro
817831
let from_macro = def_span.from_expansion()
@@ -931,9 +945,6 @@ impl AssignmentResult {
931945
}
932946

933947
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-
}
937948

938949
// We have outstanding assignments and with non-trivial drop.
939950
// This is probably a drop-guard, so we do not issue a warning there.

0 commit comments

Comments
 (0)