Skip to content

Commit 357031a

Browse files
committed
Rollup merge of #55953 - blitzerr:master, r=nikomatsakis
#53488 Refactoring UpvarId
2 parents 6104758 + 6779bb4 commit 357031a

File tree

15 files changed

+113
-102
lines changed

15 files changed

+113
-102
lines changed

src/librustc/ich/impls_ty.rs

+3-1
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

+1-1
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

+2-2
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

+1-1
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

+1-1
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

+3-3
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

+6-1
Original file line numberDiff line numberDiff line change
@@ -733,12 +733,17 @@ impl<T> List<T> {
733733
}
734734
}
735735

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

src/librustc/util/ppaux.rs

+2-2
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

+2-2
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

+1-1
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
}

src/librustc_borrowck/borrowck/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
846846
MutabilityViolation => {
847847
let mut db = self.cannot_assign(error_span, &descr, Origin::Ast);
848848
if let mc::NoteClosureEnv(upvar_id) = err.cmt.note {
849-
let node_id = self.tcx.hir.hir_to_node_id(upvar_id.var_id);
849+
let node_id = self.tcx.hir.hir_to_node_id(upvar_id.var_path.hir_id);
850850
let sp = self.tcx.hir.span(node_id);
851851
let fn_closure_msg = "`Fn` closures cannot capture their enclosing \
852852
environment for modifications";
@@ -1415,7 +1415,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
14151415
loan_path: &LoanPath<'tcx>,
14161416
out: &mut String) {
14171417
match loan_path.kind {
1418-
LpUpvar(ty::UpvarId { var_id: id, closure_expr_id: _ }) => {
1418+
LpUpvar(ty::UpvarId { var_path: ty::UpvarPath { hir_id: id}, closure_expr_id: _ }) => {
14191419
out.push_str(&self.tcx.hir.name(self.tcx.hir.hir_to_node_id(id)).as_str());
14201420
}
14211421
LpVar(id) => {
@@ -1533,7 +1533,7 @@ impl<'tcx> fmt::Debug for LoanPath<'tcx> {
15331533
write!(f, "$({})", ty::tls::with(|tcx| tcx.hir.node_to_string(id)))
15341534
}
15351535

1536-
LpUpvar(ty::UpvarId{ var_id, closure_expr_id }) => {
1536+
LpUpvar(ty::UpvarId{ var_path: ty::UpvarPath {hir_id: var_id}, closure_expr_id }) => {
15371537
let s = ty::tls::with(|tcx| {
15381538
let var_node_id = tcx.hir.hir_to_node_id(var_id);
15391539
tcx.hir.node_to_string(var_node_id)
@@ -1568,9 +1568,9 @@ impl<'tcx> fmt::Display for LoanPath<'tcx> {
15681568
write!(f, "$({})", ty::tls::with(|tcx| tcx.hir.node_to_user_string(id)))
15691569
}
15701570

1571-
LpUpvar(ty::UpvarId{ var_id, closure_expr_id: _ }) => {
1571+
LpUpvar(ty::UpvarId{ var_path: ty::UpvarPath { hir_id }, closure_expr_id: _ }) => {
15721572
let s = ty::tls::with(|tcx| {
1573-
let var_node_id = tcx.hir.hir_to_node_id(var_id);
1573+
let var_node_id = tcx.hir.hir_to_node_id(hir_id);
15741574
tcx.hir.node_to_string(var_node_id)
15751575
});
15761576
write!(f, "$({} captured by closure)", s)

src/librustc_mir/build/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
664664
let var_hir_id = tcx.hir.node_to_hir_id(var_id);
665665
let closure_expr_id = tcx.hir.local_def_id(fn_id);
666666
let capture = hir.tables().upvar_capture(ty::UpvarId {
667-
var_id: var_hir_id,
667+
var_path: ty::UpvarPath {hir_id: var_hir_id},
668668
closure_expr_id: LocalDefId::from_def_id(closure_expr_id),
669669
});
670670
let by_ref = match capture {

src/librustc_mir/hair/cx/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ fn convert_var<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
10611061
// ...but the upvar might be an `&T` or `&mut T` capture, at which
10621062
// point we need an implicit deref
10631063
let upvar_id = ty::UpvarId {
1064-
var_id: var_hir_id,
1064+
var_path: ty::UpvarPath {hir_id: var_hir_id},
10651065
closure_expr_id: LocalDefId::from_def_id(closure_def_id),
10661066
};
10671067
match cx.tables().upvar_capture(upvar_id) {
@@ -1178,7 +1178,7 @@ fn capture_freevar<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
11781178
-> ExprRef<'tcx> {
11791179
let var_hir_id = cx.tcx.hir.node_to_hir_id(freevar.var_id());
11801180
let upvar_id = ty::UpvarId {
1181-
var_id: var_hir_id,
1181+
var_path: ty::UpvarPath { hir_id: var_hir_id },
11821182
closure_expr_id: cx.tcx.hir.local_def_id(closure_expr.id).to_local(),
11831183
};
11841184
let upvar_capture = cx.tables().upvar_capture(upvar_id);

0 commit comments

Comments
 (0)