about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-08-17 01:33:19 +0000
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-08-18 03:22:47 +0000
commit75c3fd89d47d6da340ef6c1b98e80968d0218337 (patch)
tree70b01e430ae7ffea566eefa94ec3c01ee26b47cf /src
parentbfc98f59a48d7c8a65cd1a15656bb6165fb3589f (diff)
downloadrust-75c3fd89d47d6da340ef6c1b98e80968d0218337.tar.gz
rust-75c3fd89d47d6da340ef6c1b98e80968d0218337.zip
Refactor away the field `arenas` of `ModuleS`.
Diffstat (limited to 'src')
-rw-r--r--src/librustc_resolve/lib.rs14
-rw-r--r--src/librustc_resolve/resolve_imports.rs20
2 files changed, 14 insertions, 20 deletions
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs
index 71dee48f339..efc0247e6ff 100644
--- a/src/librustc_resolve/lib.rs
+++ b/src/librustc_resolve/lib.rs
@@ -765,17 +765,12 @@ pub struct ModuleS<'a> {
     // access the children must be preceded with a
     // `populate_module_if_necessary` call.
     populated: Cell<bool>,
-
-    arenas: &'a ResolverArenas<'a>,
 }
 
 pub type Module<'a> = &'a ModuleS<'a>;
 
 impl<'a> ModuleS<'a> {
-    fn new(parent_link: ParentLink<'a>,
-           def: Option<Def>,
-           external: bool,
-           arenas: &'a ResolverArenas<'a>) -> Self {
+    fn new(parent_link: ParentLink<'a>, def: Option<Def>, external: bool) -> Self {
         ModuleS {
             parent_link: parent_link,
             def: def,
@@ -786,7 +781,6 @@ impl<'a> ModuleS<'a> {
             globs: RefCell::new((Vec::new())),
             traits: RefCell::new(None),
             populated: Cell::new(!external),
-            arenas: arenas
         }
     }
 
@@ -1136,7 +1130,7 @@ impl<'a> Resolver<'a> {
                -> Resolver<'a> {
         let root_def_id = DefId::local(CRATE_DEF_INDEX);
         let graph_root =
-            ModuleS::new(NoParentLink, Some(Def::Mod(root_def_id)), false, arenas);
+            ModuleS::new(NoParentLink, Some(Def::Mod(root_def_id)), false);
         let graph_root = arenas.alloc_module(graph_root);
         let mut module_map = NodeMap();
         module_map.insert(CRATE_NODE_ID, graph_root);
@@ -1211,12 +1205,12 @@ impl<'a> Resolver<'a> {
 
     fn new_module(&self, parent_link: ParentLink<'a>, def: Option<Def>, external: bool)
                   -> Module<'a> {
-        self.arenas.alloc_module(ModuleS::new(parent_link, def, external, self.arenas))
+        self.arenas.alloc_module(ModuleS::new(parent_link, def, external))
     }
 
     fn new_extern_crate_module(&self, parent_link: ParentLink<'a>, def: Def, local_node_id: NodeId)
                                -> Module<'a> {
-        let mut module = ModuleS::new(parent_link, Some(def), false, self.arenas);
+        let mut module = ModuleS::new(parent_link, Some(def), false);
         module.extern_crate_id = Some(local_node_id);
         self.arenas.modules.alloc(module)
     }
diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs
index 0905632d4e6..05c4430a687 100644
--- a/src/librustc_resolve/resolve_imports.rs
+++ b/src/librustc_resolve/resolve_imports.rs
@@ -135,14 +135,13 @@ impl<'a> NameResolution<'a> {
     }
 }
 
-impl<'a> ::ModuleS<'a> {
-    fn resolution(&self, name: Name, ns: Namespace) -> &'a RefCell<NameResolution<'a>> {
-        *self.resolutions.borrow_mut().entry((name, ns))
-             .or_insert_with(|| self.arenas.alloc_name_resolution())
+impl<'a> Resolver<'a> {
+    fn resolution(&self, module: Module<'a>, name: Name, ns: Namespace)
+                  -> &'a RefCell<NameResolution<'a>> {
+        *module.resolutions.borrow_mut().entry((name, ns))
+               .or_insert_with(|| self.arenas.alloc_name_resolution())
     }
-}
 
-impl<'a> Resolver<'a> {
     /// Attempts to resolve the supplied name in the given module for the given namespace.
     /// If successful, returns the binding corresponding to the name.
     pub fn resolve_name_in_module(&mut self,
@@ -154,7 +153,7 @@ impl<'a> Resolver<'a> {
                                   -> ResolveResult<&'a NameBinding<'a>> {
         self.populate_module_if_necessary(module);
 
-        let resolution = module.resolution(name, ns);
+        let resolution = self.resolution(module, name, ns);
         let resolution = match resolution.borrow_state() {
             ::std::cell::BorrowState::Unused => resolution.borrow_mut(),
             _ => return Failed(None), // This happens when there is a cycle of imports
@@ -240,8 +239,9 @@ impl<'a> Resolver<'a> {
                                 span: Span,
                                 id: NodeId,
                                 vis: ty::Visibility) {
+        let current_module = self.current_module;
         let directive = self.arenas.alloc_import_directive(ImportDirective {
-            parent: self.current_module,
+            parent: current_module,
             module_path: module_path,
             target_module: Cell::new(None),
             subclass: subclass,
@@ -254,7 +254,7 @@ impl<'a> Resolver<'a> {
         match directive.subclass {
             SingleImport { target, .. } => {
                 for &ns in &[ValueNS, TypeNS] {
-                    let mut resolution = self.current_module.resolution(target, ns).borrow_mut();
+                    let mut resolution = self.resolution(current_module, target, ns).borrow_mut();
                     resolution.single_imports.add_directive(directive);
                 }
             }
@@ -311,7 +311,7 @@ impl<'a> Resolver<'a> {
         // Ensure that `resolution` isn't borrowed when defining in the module's glob importers,
         // during which the resolution might end up getting re-defined via a glob cycle.
         let (new_binding, t) = {
-            let mut resolution = &mut *module.resolution(name, ns).borrow_mut();
+            let mut resolution = &mut *self.resolution(module, name, ns).borrow_mut();
             let was_known = resolution.binding().is_some();
 
             let t = f(self, resolution);