Skip to content

Commit 340b91e

Browse files
committed
rustc: remove has_parent from hir::Upvar.
1 parent a0ca2a2 commit 340b91e

File tree

5 files changed

+7
-34
lines changed

5 files changed

+7
-34
lines changed

src/librustc/hir/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,9 +2495,6 @@ impl ForeignItemKind {
24952495
/// A variable captured by a closure.
24962496
#[derive(Debug, Copy, Clone, RustcEncodable, RustcDecodable, HashStable)]
24972497
pub struct Upvar {
2498-
/// Whether this is not a direct capture (comes from parent closure).
2499-
pub has_parent: bool,
2500-
25012498
// First span where it is accessed (there can be multiple).
25022499
pub span: Span
25032500
}

src/librustc/middle/expr_use_visitor.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -940,8 +940,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
940940
let upvar_capture = self.mc.tables.upvar_capture(upvar_id);
941941
let cmt_var = return_if_err!(self.cat_captured_var(closure_expr.hir_id,
942942
fn_decl_span,
943-
var_id,
944-
upvar));
943+
var_id));
945944
match upvar_capture {
946945
ty::UpvarCapture::ByValue => {
947946
let mode = copy_or_move(&self.mc,
@@ -966,12 +965,11 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
966965
fn cat_captured_var(&mut self,
967966
closure_hir_id: hir::HirId,
968967
closure_span: Span,
969-
var_id: hir::HirId,
970-
upvar: &hir::Upvar)
968+
var_id: hir::HirId)
971969
-> mc::McResult<mc::cmt_<'tcx>> {
972970
// Create the cmt for the variable being borrowed, from the
973971
// caller's perspective
974-
let res = if upvar.has_parent {
972+
let res = if self.mc.upvars.map_or(false, |upvars| upvars.contains_key(&var_id)) {
975973
Res::Upvar(var_id)
976974
} else {
977975
Res::Local(var_id)

src/librustc/middle/liveness.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ use self::VarKind::*;
9999

100100
use crate::hir::def::*;
101101
use crate::hir::Node;
102-
use crate::ty::{self, DefIdTree, TyCtxt};
102+
use crate::ty::{self, TyCtxt};
103103
use crate::ty::query::Providers;
104104
use crate::lint;
105105
use crate::util::nodemap::{HirIdMap, HirIdSet};
@@ -493,12 +493,8 @@ fn visit_expr<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, expr: &'tcx Expr) {
493493
if let Some(upvars) = ir.tcx.upvars(closure_def_id) {
494494
let parent_upvars = ir.tcx.upvars(ir.body_owner);
495495
call_caps.extend(upvars.iter().filter_map(|(&var_id, upvar)| {
496-
if upvar.has_parent {
497-
assert_eq!(ir.body_owner, ir.tcx.parent(closure_def_id).unwrap());
498-
}
499496
let has_parent = parent_upvars
500497
.map_or(false, |upvars| upvars.contains_key(&var_id));
501-
assert_eq!(upvar.has_parent, has_parent);
502498
if !has_parent {
503499
let upvar_ln = ir.add_live_node(UpvarNode(upvar.span));
504500
Some(CaptureInfo { ln: upvar_ln, var_hid: var_id })

src/librustc_mir/hair/cx/expr.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::hair::util::UserAnnotatedTyHelpers;
66
use rustc_data_structures::indexed_vec::Idx;
77
use rustc::hir::def::{CtorOf, Res, DefKind, CtorKind};
88
use rustc::mir::interpret::{GlobalId, ErrorHandled, ConstValue};
9-
use rustc::ty::{self, AdtKind, DefIdTree, Ty};
9+
use rustc::ty::{self, AdtKind, Ty};
1010
use rustc::ty::adjustment::{Adjustment, Adjust, AutoBorrow, AutoBorrowMutability, PointerCast};
1111
use rustc::ty::subst::{InternalSubsts, SubstsRef};
1212
use rustc::hir;
@@ -515,7 +515,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
515515
let upvars = cx.tcx.upvars(def_id).iter()
516516
.flat_map(|upvars| upvars.iter())
517517
.zip(substs.upvar_tys(def_id, cx.tcx))
518-
.map(|((&var_hir_id, upvar), ty)| capture_upvar(cx, expr, var_hir_id, upvar, ty))
518+
.map(|((&var_hir_id, _), ty)| capture_upvar(cx, expr, var_hir_id, ty))
519519
.collect();
520520
ExprKind::Closure {
521521
closure_id: def_id,
@@ -1192,7 +1192,6 @@ fn overloaded_place<'a, 'gcx, 'tcx>(
11921192
fn capture_upvar<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
11931193
closure_expr: &'tcx hir::Expr,
11941194
var_hir_id: hir::HirId,
1195-
upvar: &hir::Upvar,
11961195
upvar_ty: Ty<'tcx>)
11971196
-> ExprRef<'tcx> {
11981197
let upvar_id = ty::UpvarId {
@@ -1202,15 +1201,6 @@ fn capture_upvar<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
12021201
let upvar_capture = cx.tables().upvar_capture(upvar_id);
12031202
let temp_lifetime = cx.region_scope_tree.temporary_scope(closure_expr.hir_id.local_id);
12041203
let var_ty = cx.tables().node_type(var_hir_id);
1205-
if upvar.has_parent {
1206-
let closure_def_id = upvar_id.closure_expr_id.to_def_id();
1207-
assert_eq!(cx.body_owner, cx.tcx.parent(closure_def_id).unwrap());
1208-
}
1209-
assert_eq!(
1210-
upvar.has_parent,
1211-
cx.tables().upvar_list.get(&cx.body_owner)
1212-
.map_or(false, |upvars| upvars.contains_key(&var_hir_id)),
1213-
);
12141204
let captured_var = Expr {
12151205
temp_lifetime,
12161206
ty: var_ty,

src/librustc_resolve/lib.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4049,20 +4049,12 @@ impl<'a> Resolver<'a> {
40494049
// Nothing to do. Continue.
40504050
}
40514051
ClosureRibKind(function_id) => {
4052-
let has_parent = match res {
4053-
Res::Upvar(..) => true,
4054-
_ => false,
4055-
};
40564052
res = Res::Upvar(var_id);
4057-
40584053
match self.upvars.entry(function_id).or_default().entry(var_id) {
40594054
indexmap::map::Entry::Occupied(_) => continue,
40604055
indexmap::map::Entry::Vacant(entry) => {
40614056
if record_used {
4062-
entry.insert(Upvar {
4063-
has_parent,
4064-
span,
4065-
});
4057+
entry.insert(Upvar { span });
40664058
}
40674059
}
40684060
}

0 commit comments

Comments
 (0)