Upvars HirIds always have the same owner, thus just use an ItemLocalId

This commit is contained in:
Oli Scherer 2025-03-17 12:23:53 +00:00
parent 805f389da5
commit 0795b3de9b
2 changed files with 7 additions and 3 deletions

View File

@ -159,7 +159,7 @@ fn find_capture_matching_projections<'a, 'tcx>(
) -> Option<(usize, &'a Capture<'tcx>)> {
let hir_projections = convert_to_hir_projections_and_truncate_for_capture(projections);
upvars.get_by_key_enumerated(var_hir_id.0).find(|(_, capture)| {
upvars.get_by_key_enumerated(var_hir_id.0.local_id).find(|(_, capture)| {
let possible_ancestor_proj_kinds: Vec<_> =
capture.captured_place.place.projections.iter().map(|proj| proj.kind).collect();
is_ancestor_or_same_capture(&possible_ancestor_proj_kinds, &hir_projections)

View File

@ -13,7 +13,7 @@ use rustc_data_structures::sorted_map::SortedIndexMultiMap;
use rustc_errors::ErrorGuaranteed;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::{self as hir, BindingMode, ByRef, HirId, Node};
use rustc_hir::{self as hir, BindingMode, ByRef, HirId, ItemLocalId, Node};
use rustc_index::bit_set::GrowableBitSet;
use rustc_index::{Idx, IndexSlice, IndexVec};
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
@ -221,7 +221,7 @@ struct Builder<'a, 'tcx> {
coverage_info: Option<coverageinfo::CoverageInfoBuilder>,
}
type CaptureMap<'tcx> = SortedIndexMultiMap<usize, HirId, Capture<'tcx>>;
type CaptureMap<'tcx> = SortedIndexMultiMap<usize, ItemLocalId, Capture<'tcx>>;
#[derive(Debug)]
struct Capture<'tcx> {
@ -853,6 +853,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let capture_tys = upvar_args.upvar_tys();
let tcx = self.tcx;
let mut upvar_owner = None;
self.upvars = tcx
.closure_captures(self.def_id)
.iter()
@ -866,6 +867,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
HirPlaceBase::Upvar(upvar_id) => upvar_id.var_path.hir_id,
_ => bug!("Expected an upvar"),
};
let upvar_base = upvar_owner.get_or_insert(var_id.owner);
assert_eq!(*upvar_base, var_id.owner);
let var_id = var_id.local_id;
let mutability = captured_place.mutability;