Skip to content

Commit 6c475f1

Browse files
committed
Upvars HirIds always have the same owner, thus just use an ItemLocalId
1 parent 9c67cec commit 6c475f1

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

compiler/rustc_mir_build/src/builder/expr/as_place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ fn find_capture_matching_projections<'a, 'tcx>(
159159
) -> Option<(usize, &'a Capture<'tcx>)> {
160160
let hir_projections = convert_to_hir_projections_and_truncate_for_capture(projections);
161161

162-
upvars.get_by_key_enumerated(var_hir_id.0).find(|(_, capture)| {
162+
upvars.get_by_key_enumerated(var_hir_id.0.local_id).find(|(_, capture)| {
163163
let possible_ancestor_proj_kinds: Vec<_> =
164164
capture.captured_place.place.projections.iter().map(|proj| proj.kind).collect();
165165
is_ancestor_or_same_capture(&possible_ancestor_proj_kinds, &hir_projections)

compiler/rustc_mir_build/src/builder/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_data_structures::sorted_map::SortedIndexMultiMap;
1313
use rustc_errors::ErrorGuaranteed;
1414
use rustc_hir::def::DefKind;
1515
use rustc_hir::def_id::{DefId, LocalDefId};
16-
use rustc_hir::{self as hir, BindingMode, ByRef, HirId, Node};
16+
use rustc_hir::{self as hir, BindingMode, ByRef, HirId, ItemLocalId, Node};
1717
use rustc_index::bit_set::GrowableBitSet;
1818
use rustc_index::{Idx, IndexSlice, IndexVec};
1919
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
@@ -221,7 +221,7 @@ struct Builder<'a, 'tcx> {
221221
coverage_info: Option<coverageinfo::CoverageInfoBuilder>,
222222
}
223223

224-
type CaptureMap<'tcx> = SortedIndexMultiMap<usize, HirId, Capture<'tcx>>;
224+
type CaptureMap<'tcx> = SortedIndexMultiMap<usize, ItemLocalId, Capture<'tcx>>;
225225

226226
#[derive(Debug)]
227227
struct Capture<'tcx> {
@@ -853,6 +853,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
853853
let capture_tys = upvar_args.upvar_tys();
854854

855855
let tcx = self.tcx;
856+
let mut upvar_owner = None;
856857
self.upvars = tcx
857858
.closure_captures(self.def_id)
858859
.iter()
@@ -866,6 +867,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
866867
HirPlaceBase::Upvar(upvar_id) => upvar_id.var_path.hir_id,
867868
_ => bug!("Expected an upvar"),
868869
};
870+
let upvar_base = upvar_owner.get_or_insert(var_id.owner);
871+
assert_eq!(*upvar_base, var_id.owner);
872+
let var_id = var_id.local_id;
869873

870874
let mutability = captured_place.mutability;
871875

0 commit comments

Comments
 (0)