From fb2129e043e19e71562c780dd3ef2402e378d52c Mon Sep 17 00:00:00 2001 From: Jonathan S Date: Tue, 3 Nov 2015 23:12:37 -0600 Subject: [PATCH] Remove the RefCell around freevars and freevars_seen in librustc_resolve --- src/librustc/middle/ty/context.rs | 4 ++-- src/librustc_resolve/lib.rs | 21 ++++++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/librustc/middle/ty/context.rs b/src/librustc/middle/ty/context.rs index 830232cf373b8..fb0b1c402da86 100644 --- a/src/librustc/middle/ty/context.rs +++ b/src/librustc/middle/ty/context.rs @@ -448,7 +448,7 @@ impl<'tcx> ctxt<'tcx> { def_map: DefMap, named_region_map: resolve_lifetime::NamedRegionMap, map: ast_map::Map<'tcx>, - freevars: RefCell, + freevars: FreevarMap, region_maps: RegionMaps, lang_items: middle::lang_items::LanguageItems, stability: stability::Index<'tcx>, @@ -481,7 +481,7 @@ impl<'tcx> ctxt<'tcx> { super_predicates: RefCell::new(DefIdMap()), fulfilled_predicates: RefCell::new(traits::FulfilledPredicates::new()), map: map, - freevars: freevars, + freevars: RefCell::new(freevars), tcache: RefCell::new(DefIdMap()), rcache: RefCell::new(FnvHashMap()), tc_cache: RefCell::new(FnvHashMap()), diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 882283ba06fd3..4f602abfbb586 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1151,8 +1151,8 @@ pub struct Resolver<'a, 'tcx:'a> { primitive_type_table: PrimitiveTypeTable, def_map: DefMap, - freevars: RefCell, - freevars_seen: RefCell>>, + freevars: FreevarMap, + freevars_seen: NodeMap>, export_map: ExportMap, trait_map: TraitMap, external_exports: ExternalExports, @@ -1227,8 +1227,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { primitive_type_table: PrimitiveTypeTable::new(), def_map: RefCell::new(NodeMap()), - freevars: RefCell::new(NodeMap()), - freevars_seen: RefCell::new(NodeMap()), + freevars: NodeMap(), + freevars_seen: NodeMap(), export_map: NodeMap(), trait_map: NodeMap(), used_imports: HashSet::new(), @@ -3081,7 +3081,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } // Resolve a local definition, potentially adjusting for closures. - fn adjust_local_def(&self, local_def: LocalDef, span: Span) -> Option { + fn adjust_local_def(&mut self, local_def: LocalDef, span: Span) -> Option { let ribs = match local_def.ribs { Some((TypeNS, i)) => &self.type_ribs[i+1..], Some((ValueNS, i)) => &self.value_ribs[i+1..], @@ -3103,15 +3103,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { let prev_def = def; let node_def_id = self.ast_map.local_def_id(node_id); - let mut seen = self.freevars_seen.borrow_mut(); - let seen = seen.entry(function_id).or_insert_with(|| NodeMap()); + let seen = self.freevars_seen.entry(function_id) + .or_insert_with(|| NodeMap()); if let Some(&index) = seen.get(&node_id) { def = DefUpvar(node_def_id, node_id, index, function_id); continue; } - let mut freevars = self.freevars.borrow_mut(); - let vec = freevars.entry(function_id) - .or_insert_with(|| vec![]); + let vec = self.freevars.entry(function_id) + .or_insert_with(|| vec![]); let depth = vec.len(); vec.push(Freevar { def: prev_def, span: span }); @@ -4028,7 +4027,7 @@ fn module_to_string(module: &Module) -> String { pub struct CrateMap { pub def_map: DefMap, - pub freevars: RefCell, + pub freevars: FreevarMap, pub export_map: ExportMap, pub trait_map: TraitMap, pub external_exports: ExternalExports,