diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index e62cc2a658a47..0383d5ca68232 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -31,7 +31,7 @@ use std::rc::Rc; use syntax::ast; use syntax::ptr::P; use syntax_pos::Span; -use util::nodemap::ItemLocalMap; +use util::nodemap::ItemLocalSet; /////////////////////////////////////////////////////////////////////////// // The Delegate trait @@ -279,7 +279,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx, 'tcx> { param_env: ty::ParamEnv<'tcx>, region_scope_tree: &'a region::ScopeTree, tables: &'a ty::TypeckTables<'tcx>, - rvalue_promotable_map: Option>>) + rvalue_promotable_map: Option>) -> Self { ExprUseVisitor { diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index e0e30f8831676..fc10406c8cebd 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -86,7 +86,7 @@ use syntax_pos::Span; use std::fmt; use std::rc::Rc; -use util::nodemap::ItemLocalMap; +use util::nodemap::ItemLocalSet; #[derive(Clone, PartialEq)] pub enum Categorization<'tcx> { @@ -286,7 +286,7 @@ pub struct MemCategorizationContext<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { pub tcx: TyCtxt<'a, 'gcx, 'tcx>, pub region_scope_tree: &'a region::ScopeTree, pub tables: &'a ty::TypeckTables<'tcx>, - rvalue_promotable_map: Option>>, + rvalue_promotable_map: Option>, infcx: Option<&'a InferCtxt<'a, 'gcx, 'tcx>>, } @@ -395,7 +395,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx, 'tcx> { pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>, region_scope_tree: &'a region::ScopeTree, tables: &'a ty::TypeckTables<'tcx>, - rvalue_promotable_map: Option>>) + rvalue_promotable_map: Option>) -> MemCategorizationContext<'a, 'tcx, 'tcx> { MemCategorizationContext { tcx, @@ -897,7 +897,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> { expr_ty: Ty<'tcx>) -> cmt<'tcx> { let hir_id = self.tcx.hir.node_to_hir_id(id); - let promotable = self.rvalue_promotable_map.as_ref().map(|m| m[&hir_id.local_id]) + let promotable = self.rvalue_promotable_map.as_ref().map(|m| m.contains(&hir_id.local_id)) .unwrap_or(false); // Always promote `[T; 0]` (even when e.g. borrowed mutably). diff --git a/src/librustc/ty/maps/mod.rs b/src/librustc/ty/maps/mod.rs index 7d8586741fb15..e3fa1e59087d2 100644 --- a/src/librustc/ty/maps/mod.rs +++ b/src/librustc/ty/maps/mod.rs @@ -37,7 +37,7 @@ use ty::{self, CrateInherentImpls, Ty, TyCtxt}; use ty::layout::{Layout, LayoutError}; use ty::steal::Steal; use ty::subst::Substs; -use util::nodemap::{DefIdSet, DefIdMap, ItemLocalMap}; +use util::nodemap::{DefIdSet, DefIdMap, ItemLocalSet}; use util::common::{profq_msg, ProfileQueriesMsg}; use rustc_data_structures::indexed_set::IdxSetBuf; @@ -236,7 +236,7 @@ define_maps! { <'tcx> [] fn is_exported_symbol: IsExportedSymbol(DefId) -> bool, [] fn item_body_nested_bodies: ItemBodyNestedBodies(DefId) -> ExternBodyNestedBodies, [] fn const_is_rvalue_promotable_to_static: ConstIsRvaluePromotableToStatic(DefId) -> bool, - [] fn rvalue_promotable_map: RvaluePromotableMap(DefId) -> Rc>, + [] fn rvalue_promotable_map: RvaluePromotableMap(DefId) -> Rc, [] fn is_mir_available: IsMirAvailable(DefId) -> bool, [] fn vtable_methods: vtable_methods_node(ty::PolyTraitRef<'tcx>) -> Rc)>>>, diff --git a/src/librustc/util/nodemap.rs b/src/librustc/util/nodemap.rs index c397371c5c767..674f67d5cd2f1 100644 --- a/src/librustc/util/nodemap.rs +++ b/src/librustc/util/nodemap.rs @@ -25,10 +25,12 @@ pub type ItemLocalMap = FxHashMap; pub type NodeSet = FxHashSet; pub type DefIdSet = FxHashSet; +pub type ItemLocalSet = FxHashSet; pub fn NodeMap() -> NodeMap { FxHashMap() } pub fn DefIdMap() -> DefIdMap { FxHashMap() } pub fn ItemLocalMap() -> ItemLocalMap { FxHashMap() } pub fn NodeSet() -> NodeSet { FxHashSet() } pub fn DefIdSet() -> DefIdSet { FxHashSet() } +pub fn ItemLocalSet() -> ItemLocalSet { FxHashSet() } diff --git a/src/librustc_passes/consts.rs b/src/librustc_passes/consts.rs index a6eaff4481c76..4515d9c7837c8 100644 --- a/src/librustc_passes/consts.rs +++ b/src/librustc_passes/consts.rs @@ -43,7 +43,7 @@ use rustc::ty::maps::{queries, Providers}; use rustc::ty::subst::Substs; use rustc::traits::Reveal; use rustc::util::common::ErrorReported; -use rustc::util::nodemap::{ItemLocalMap, NodeSet}; +use rustc::util::nodemap::{ItemLocalSet, NodeSet}; use rustc::lint::builtin::CONST_ERR; use rustc::hir::{self, PatKind, RangeEnd}; use std::rc::Rc; @@ -79,12 +79,12 @@ fn const_is_rvalue_promotable_to_static<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, .expect("rvalue_promotable_map invoked with non-local def-id"); let body_id = tcx.hir.body_owned_by(node_id); let body_hir_id = tcx.hir.node_to_hir_id(body_id.node_id); - tcx.rvalue_promotable_map(def_id).contains_key(&body_hir_id.local_id) + tcx.rvalue_promotable_map(def_id).contains(&body_hir_id.local_id) } fn rvalue_promotable_map<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) - -> Rc> + -> Rc { let outer_def_id = tcx.closure_base_def_id(def_id); if outer_def_id != def_id { @@ -100,7 +100,7 @@ fn rvalue_promotable_map<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, mut_rvalue_borrows: NodeSet(), param_env: ty::ParamEnv::empty(Reveal::UserFacing), identity_substs: Substs::empty(), - result_map: ItemLocalMap(), + result: ItemLocalSet(), }; // `def_id` should be a `Body` owner @@ -109,7 +109,7 @@ fn rvalue_promotable_map<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let body_id = tcx.hir.body_owned_by(node_id); visitor.visit_nested_body(body_id); - Rc::new(visitor.result_map) + Rc::new(visitor.result) } struct CheckCrateVisitor<'a, 'tcx: 'a> { @@ -121,7 +121,7 @@ struct CheckCrateVisitor<'a, 'tcx: 'a> { param_env: ty::ParamEnv<'tcx>, identity_substs: &'tcx Substs<'tcx>, tables: &'a ty::TypeckTables<'tcx>, - result_map: ItemLocalMap, + result: ItemLocalSet, } impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> { @@ -322,7 +322,9 @@ impl<'a, 'tcx> Visitor<'tcx> for CheckCrateVisitor<'a, 'tcx> { } } - self.result_map.insert(ex.hir_id.local_id, self.promotable); + if self.promotable { + self.result.insert(ex.hir_id.local_id); + } self.promotable &= outer; } }