Skip to content
Permalink
Browse files

rustc: remove `has_parent` from `hir::Upvar`.

  • Loading branch information...
eddyb committed May 28, 2019
1 parent a0ca2a2 commit 340b91e2ffdd884be5c260144305b518e5a22a9b
@@ -2495,9 +2495,6 @@ impl ForeignItemKind {
/// A variable captured by a closure.
#[derive(Debug, Copy, Clone, RustcEncodable, RustcDecodable, HashStable)]
pub struct Upvar {
/// Whether this is not a direct capture (comes from parent closure).
pub has_parent: bool,

// First span where it is accessed (there can be multiple).
pub span: Span
}
@@ -940,8 +940,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
let upvar_capture = self.mc.tables.upvar_capture(upvar_id);
let cmt_var = return_if_err!(self.cat_captured_var(closure_expr.hir_id,
fn_decl_span,
var_id,
upvar));
var_id));
match upvar_capture {
ty::UpvarCapture::ByValue => {
let mode = copy_or_move(&self.mc,
@@ -966,12 +965,11 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
fn cat_captured_var(&mut self,
closure_hir_id: hir::HirId,
closure_span: Span,
var_id: hir::HirId,
upvar: &hir::Upvar)
var_id: hir::HirId)
-> mc::McResult<mc::cmt_<'tcx>> {
// Create the cmt for the variable being borrowed, from the
// caller's perspective
let res = if upvar.has_parent {
let res = if self.mc.upvars.map_or(false, |upvars| upvars.contains_key(&var_id)) {
Res::Upvar(var_id)
} else {
Res::Local(var_id)
@@ -99,7 +99,7 @@ use self::VarKind::*;

use crate::hir::def::*;
use crate::hir::Node;
use crate::ty::{self, DefIdTree, TyCtxt};
use crate::ty::{self, TyCtxt};
use crate::ty::query::Providers;
use crate::lint;
use crate::util::nodemap::{HirIdMap, HirIdSet};
@@ -493,12 +493,8 @@ fn visit_expr<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, expr: &'tcx Expr) {
if let Some(upvars) = ir.tcx.upvars(closure_def_id) {
let parent_upvars = ir.tcx.upvars(ir.body_owner);
call_caps.extend(upvars.iter().filter_map(|(&var_id, upvar)| {
if upvar.has_parent {
assert_eq!(ir.body_owner, ir.tcx.parent(closure_def_id).unwrap());
}
let has_parent = parent_upvars
.map_or(false, |upvars| upvars.contains_key(&var_id));
assert_eq!(upvar.has_parent, has_parent);
if !has_parent {
let upvar_ln = ir.add_live_node(UpvarNode(upvar.span));
Some(CaptureInfo { ln: upvar_ln, var_hid: var_id })
@@ -6,7 +6,7 @@ use crate::hair::util::UserAnnotatedTyHelpers;
use rustc_data_structures::indexed_vec::Idx;
use rustc::hir::def::{CtorOf, Res, DefKind, CtorKind};
use rustc::mir::interpret::{GlobalId, ErrorHandled, ConstValue};
use rustc::ty::{self, AdtKind, DefIdTree, Ty};
use rustc::ty::{self, AdtKind, Ty};
use rustc::ty::adjustment::{Adjustment, Adjust, AutoBorrow, AutoBorrowMutability, PointerCast};
use rustc::ty::subst::{InternalSubsts, SubstsRef};
use rustc::hir;
@@ -515,7 +515,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
let upvars = cx.tcx.upvars(def_id).iter()
.flat_map(|upvars| upvars.iter())
.zip(substs.upvar_tys(def_id, cx.tcx))
.map(|((&var_hir_id, upvar), ty)| capture_upvar(cx, expr, var_hir_id, upvar, ty))
.map(|((&var_hir_id, _), ty)| capture_upvar(cx, expr, var_hir_id, ty))
.collect();
ExprKind::Closure {
closure_id: def_id,
@@ -1192,7 +1192,6 @@ fn overloaded_place<'a, 'gcx, 'tcx>(
fn capture_upvar<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
closure_expr: &'tcx hir::Expr,
var_hir_id: hir::HirId,
upvar: &hir::Upvar,
upvar_ty: Ty<'tcx>)
-> ExprRef<'tcx> {
let upvar_id = ty::UpvarId {
@@ -1202,15 +1201,6 @@ fn capture_upvar<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
let upvar_capture = cx.tables().upvar_capture(upvar_id);
let temp_lifetime = cx.region_scope_tree.temporary_scope(closure_expr.hir_id.local_id);
let var_ty = cx.tables().node_type(var_hir_id);
if upvar.has_parent {
let closure_def_id = upvar_id.closure_expr_id.to_def_id();
assert_eq!(cx.body_owner, cx.tcx.parent(closure_def_id).unwrap());
}
assert_eq!(
upvar.has_parent,
cx.tables().upvar_list.get(&cx.body_owner)
.map_or(false, |upvars| upvars.contains_key(&var_hir_id)),
);
let captured_var = Expr {
temp_lifetime,
ty: var_ty,
@@ -4049,20 +4049,12 @@ impl<'a> Resolver<'a> {
// Nothing to do. Continue.
}
ClosureRibKind(function_id) => {
let has_parent = match res {
Res::Upvar(..) => true,
_ => false,
};
res = Res::Upvar(var_id);

match self.upvars.entry(function_id).or_default().entry(var_id) {
indexmap::map::Entry::Occupied(_) => continue,
indexmap::map::Entry::Vacant(entry) => {
if record_used {
entry.insert(Upvar {
has_parent,
span,
});
entry.insert(Upvar { span });
}
}
}

0 comments on commit 340b91e

Please sign in to comment.
You can’t perform that action at this time.