]> git.lizzy.rs Git - rust.git/commitdiff
Refactor `directive.import(binding)` -> `resolver.import(binding, directive)`.
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Sun, 31 Jul 2016 04:53:04 +0000 (04:53 +0000)
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Mon, 1 Aug 2016 19:10:07 +0000 (19:10 +0000)
src/librustc_resolve/resolve_imports.rs

index a2aab1ff815ac60297579beb6070f66dec8f9e24..6986f99926e1e43d9dd07874d5d25b29a9d4d6df 100644 (file)
@@ -71,19 +71,6 @@ pub struct ImportDirective<'a> {
 }
 
 impl<'a> ImportDirective<'a> {
-    // Given the binding to which this directive resolves in a particular namespace,
-    // this returns the binding for the name this directive defines in that namespace.
-    fn import(&'a self, binding: &'a NameBinding<'a>) -> NameBinding<'a> {
-        NameBinding {
-            kind: NameBindingKind::Import {
-                binding: binding,
-                directive: self,
-            },
-            span: self.span,
-            vis: self.vis,
-        }
-    }
-
     pub fn is_glob(&self) -> bool {
         match self.subclass { ImportDirectiveSubclass::GlobImport { .. } => true, _ => false }
     }
@@ -258,6 +245,20 @@ pub fn add_import_directive(&self,
 }
 
 impl<'a> Resolver<'a> {
+    // Given a binding and an import directive that resolves to it,
+    // return the corresponding binding defined by the import directive.
+    fn import(&mut self, binding: &'a NameBinding<'a>, directive: &'a ImportDirective<'a>)
+              -> NameBinding<'a> {
+        NameBinding {
+            kind: NameBindingKind::Import {
+                binding: binding,
+                directive: directive,
+            },
+            span: directive.span,
+            vis: directive.vis,
+        }
+    }
+
     // Define the name or return the existing binding if there is a collision.
     pub fn try_define<T>(&mut self, module: Module<'a>, name: Name, ns: Namespace, binding: T)
                          -> Result<(), &'a NameBinding<'a>>
@@ -305,7 +306,8 @@ fn update_resolution<T, F>(&mut self, module: Module<'a>, name: Name, ns: Namesp
         // Define `new_binding` in `module`s glob importers.
         if new_binding.is_importable() && new_binding.is_pseudo_public() {
             for &(importer, directive) in module.glob_importers.borrow_mut().iter() {
-                let _ = self.try_define(importer, name, ns, directive.import(new_binding));
+                let imported_binding = self.import(new_binding, directive);
+                let _ = self.try_define(importer, name, ns, imported_binding);
             }
         }
 
@@ -408,7 +410,7 @@ fn import_dummy_binding(&mut self,
                 span: DUMMY_SP,
                 vis: ty::Visibility::Public,
             });
-            let dummy_binding = directive.import(dummy_binding);
+            let dummy_binding = self.import(dummy_binding, directive);
 
             let _ = self.try_define(source_module, target, ValueNS, dummy_binding.clone());
             let _ = self.try_define(source_module, target, TypeNS, dummy_binding);
@@ -512,10 +514,10 @@ fn resolve_import(&mut self, directive: &'b ImportDirective<'b>) -> ResolveResul
                 Success(binding) if !self.is_accessible(binding.vis) => {}
                 Success(binding) if !determined.get() => {
                     determined.set(true);
-                    let imported_binding = directive.import(binding);
+                    let imported_binding = self.import(binding, directive);
                     let conflict = self.try_define(module, target, ns, imported_binding);
                     if let Err(old_binding) = conflict {
-                        let binding = &directive.import(binding);
+                        let binding = &self.import(binding, directive);
                         self.report_conflict(module, target, ns, binding, old_binding);
                     }
                     privacy_error = false;
@@ -556,7 +558,8 @@ fn resolve_import(&mut self, directive: &'b ImportDirective<'b>) -> ResolveResul
             for &(ns, result) in &[(ValueNS, &value_result), (TypeNS, &type_result)] {
                 let binding = match *result { Success(binding) => binding, _ => continue };
                 self.privacy_errors.push(PrivacyError(directive.span, source, binding));
-                let _ = self.try_define(module, target, ns, directive.import(binding));
+                let imported_binding = self.import(binding, directive);
+                let _ = self.try_define(module, target, ns, imported_binding);
             }
         }
 
@@ -638,7 +641,8 @@ fn resolve_glob_import(&mut self, target_module: Module<'b>, directive: &'b Impo
         }).collect::<Vec<_>>();
         for ((name, ns), binding) in bindings {
             if binding.is_importable() && binding.is_pseudo_public() {
-                let _ = self.try_define(module, name, ns, directive.import(binding));
+                let imported_binding = self.import(binding, directive);
+                let _ = self.try_define(module, name, ns, imported_binding);
             }
         }