diff options
| author | Eduard-Mihai Burtescu <edy.burt@gmail.com> | 2019-05-28 17:12:24 +0300 |
|---|---|---|
| committer | Eduard-Mihai Burtescu <edy.burt@gmail.com> | 2019-06-01 19:17:23 +0300 |
| commit | 340b91e2ffdd884be5c260144305b518e5a22a9b (patch) | |
| tree | 24ba9d467866742f6aecdc7237bc4db06c9696cb | |
| parent | a0ca2a2deb8f46fab5add2e35d51a64e712890fb (diff) | |
| download | rust-340b91e2ffdd884be5c260144305b518e5a22a9b.tar.gz rust-340b91e2ffdd884be5c260144305b518e5a22a9b.zip | |
rustc: remove `has_parent` from `hir::Upvar`.
| -rw-r--r-- | src/librustc/hir/mod.rs | 3 | ||||
| -rw-r--r-- | src/librustc/middle/expr_use_visitor.rs | 8 | ||||
| -rw-r--r-- | src/librustc/middle/liveness.rs | 6 | ||||
| -rw-r--r-- | src/librustc_mir/hair/cx/expr.rs | 14 | ||||
| -rw-r--r-- | src/librustc_resolve/lib.rs | 10 |
5 files changed, 7 insertions, 34 deletions
diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 7ec24647b4d..38ef4d3dbd6 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -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 } diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index 36b6ddf3432..477f5ceff61 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -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) diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index c128d4ab8bc..be2f533ced0 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -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 }) diff --git a/src/librustc_mir/hair/cx/expr.rs b/src/librustc_mir/hair/cx/expr.rs index cb110061c0b..181313f9436 100644 --- a/src/librustc_mir/hair/cx/expr.rs +++ b/src/librustc_mir/hair/cx/expr.rs @@ -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, diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index d5c85bde52d..c8ec7367edc 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -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 }); } } } |
