Skip to content

Commit 6779bb4

Browse files
committed
capture_disjoint_fields(#53488)
Refactoring out the HirId of the UpvarId in another struct.
1 parent 1ca505a commit 6779bb4

File tree

15 files changed

+41
-30
lines changed

15 files changed

+41
-30
lines changed

src/librustc/ich/impls_ty.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,9 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for ty::adjustment::AutoBorrow
216216
}
217217
}
218218

219-
impl_stable_hash_for!(struct ty::UpvarId { var_id, closure_expr_id });
219+
impl_stable_hash_for!(struct ty::UpvarPath { hir_id });
220+
221+
impl_stable_hash_for!(struct ty::UpvarId { var_path, closure_expr_id });
220222

221223
impl_stable_hash_for!(enum ty::BorrowKind {
222224
ImmBorrow,

src/librustc/infer/error_reporting/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
13151315
format!(" for lifetime parameter `{}` in coherence check", name)
13161316
}
13171317
infer::UpvarRegion(ref upvar_id, _) => {
1318-
let var_node_id = self.tcx.hir.hir_to_node_id(upvar_id.var_id);
1318+
let var_node_id = self.tcx.hir.hir_to_node_id(upvar_id.var_path.hir_id);
13191319
let var_name = self.tcx.hir.name(var_node_id);
13201320
format!(" for capture of `{}` by closure", var_name)
13211321
}

src/librustc/infer/error_reporting/note.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
4141
"...so that reference does not outlive borrowed content");
4242
}
4343
infer::ReborrowUpvar(span, ref upvar_id) => {
44-
let var_node_id = self.tcx.hir.hir_to_node_id(upvar_id.var_id);
44+
let var_node_id = self.tcx.hir.hir_to_node_id(upvar_id.var_path.hir_id);
4545
let var_name = self.tcx.hir.name(var_node_id);
4646
err.span_note(span,
4747
&format!("...so that closure can access `{}`", var_name));
@@ -174,7 +174,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
174174
err
175175
}
176176
infer::ReborrowUpvar(span, ref upvar_id) => {
177-
let var_node_id = self.tcx.hir.hir_to_node_id(upvar_id.var_id);
177+
let var_node_id = self.tcx.hir.hir_to_node_id(upvar_id.var_path.hir_id);
178178
let var_name = self.tcx.hir.name(var_node_id);
179179
let mut err = struct_span_err!(self.tcx.sess,
180180
span,

src/librustc/middle/expr_use_visitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
938938
let var_hir_id = self.tcx().hir.node_to_hir_id(freevar.var_id());
939939
let closure_def_id = self.tcx().hir.local_def_id(closure_expr.id);
940940
let upvar_id = ty::UpvarId {
941-
var_id: var_hir_id,
941+
var_path: ty::UpvarPath { hir_id: var_hir_id },
942942
closure_expr_id: closure_def_id.to_local(),
943943
};
944944
let upvar_capture = self.mc.tables.upvar_capture(upvar_id);

src/librustc/middle/mem_categorization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
818818
let closure_expr_def_id = self.tcx.hir.local_def_id(fn_node_id);
819819
let var_hir_id = self.tcx.hir.node_to_hir_id(var_id);
820820
let upvar_id = ty::UpvarId {
821-
var_id: var_hir_id,
821+
var_path: ty::UpvarPath { hir_id: var_hir_id },
822822
closure_expr_id: closure_expr_def_id.to_local(),
823823
};
824824

src/librustc/ty/context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for TypeckTables<'gcx> {
789789
pat_adjustments.hash_stable(hcx, hasher);
790790
hash_stable_hashmap(hcx, hasher, upvar_capture_map, |up_var_id, hcx| {
791791
let ty::UpvarId {
792-
var_id,
792+
var_path,
793793
closure_expr_id
794794
} = *up_var_id;
795795

@@ -798,14 +798,14 @@ impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for TypeckTables<'gcx> {
798798

799799
let var_owner_def_id = DefId {
800800
krate: local_id_root.krate,
801-
index: var_id.owner,
801+
index: var_path.hir_id.owner,
802802
};
803803
let closure_def_id = DefId {
804804
krate: local_id_root.krate,
805805
index: closure_expr_id.to_def_id().index,
806806
};
807807
(hcx.def_path_hash(var_owner_def_id),
808-
var_id.local_id,
808+
var_path.hir_id.local_id,
809809
hcx.def_path_hash(closure_def_id))
810810
});
811811

src/librustc/ty/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,12 +731,17 @@ impl<T> List<T> {
731731
}
732732
}
733733

734+
#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
735+
pub struct UpvarPath {
736+
pub hir_id: hir::HirId,
737+
}
738+
734739
/// Upvars do not get their own node-id. Instead, we use the pair of
735740
/// the original var id (that is, the root variable that is referenced
736741
/// by the upvar) and the id of the closure expression.
737742
#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
738743
pub struct UpvarId {
739-
pub var_id: hir::HirId,
744+
pub var_path: UpvarPath,
740745
pub closure_expr_id: LocalDefId,
741746
}
742747

src/librustc/util/ppaux.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,8 +678,8 @@ impl<'tcx> fmt::Debug for ty::ClosureUpvar<'tcx> {
678678
impl fmt::Debug for ty::UpvarId {
679679
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
680680
write!(f, "UpvarId({:?};`{}`;{:?})",
681-
self.var_id,
682-
ty::tls::with(|tcx| tcx.hir.name(tcx.hir.hir_to_node_id(self.var_id))),
681+
self.var_path.hir_id,
682+
ty::tls::with(|tcx| tcx.hir.name(tcx.hir.hir_to_node_id(self.var_path.hir_id))),
683683
self.closure_expr_id)
684684
}
685685
}

src/librustc_borrowck/borrowck/gather_loans/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,8 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> {
453453
}
454454
None
455455
}
456-
LpUpvar(ty::UpvarId{ var_id, closure_expr_id: _ }) => {
457-
self.bccx.used_mut_nodes.borrow_mut().insert(var_id);
456+
LpUpvar(ty::UpvarId{ var_path: ty::UpvarPath { hir_id }, closure_expr_id: _ }) => {
457+
self.bccx.used_mut_nodes.borrow_mut().insert(hir_id);
458458
None
459459
}
460460
LpExtend(ref base, mc::McInherited, LpDeref(pointer_kind)) |

src/librustc_borrowck/borrowck/gather_loans/move_error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ fn report_move_errors<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, errors: &[MoveErr
9797
}
9898
}
9999
if let NoteClosureEnv(upvar_id) = error.move_from.note {
100-
let var_node_id = bccx.tcx.hir.hir_to_node_id(upvar_id.var_id);
100+
let var_node_id = bccx.tcx.hir.hir_to_node_id(upvar_id.var_path.hir_id);
101101
err.span_label(bccx.tcx.hir.span(var_node_id),
102102
"captured outer variable");
103103
}

0 commit comments

Comments
 (0)