]> git.lizzy.rs Git - rust.git/commitdiff
Refactor away `NameResolution::result`
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Wed, 9 Mar 2016 04:51:33 +0000 (04:51 +0000)
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Fri, 25 Mar 2016 22:22:15 +0000 (22:22 +0000)
src/librustc_resolve/resolve_imports.rs

index a29954ade184a494cb6a494cffea14dd87638c20..3e7a709345c1da2b5ffeed723c89b7c67107ef04 100644 (file)
@@ -141,26 +141,20 @@ fn try_define(&mut self, binding: &'a NameBinding<'a>) -> Result<(), &'a NameBin
         Ok(())
     }
 
-    // Returns the resolution of the name assuming no more globs will define it.
-    fn result(&self, allow_private_imports: bool) -> ResolveResult<&'a NameBinding<'a>> {
-        match self.binding {
-            Some(binding) if !binding.defined_with(DefModifiers::GLOB_IMPORTED) => Success(binding),
-            // If we don't allow private imports and no public imports can define the name, fail.
-            _ if !allow_private_imports && self.pub_outstanding_references == 0 &&
-                 !self.binding.map(NameBinding::is_public).unwrap_or(false) => Failed(None),
-            _ if self.outstanding_references > 0 => Indeterminate,
-            Some(binding) => Success(binding),
-            None => Failed(None),
-        }
-    }
-
     // Returns Some(the resolution of the name), or None if the resolution depends
     // on whether more globs can define the name.
     fn try_result(&self, allow_private_imports: bool)
                   -> Option<ResolveResult<&'a NameBinding<'a>>> {
-        match self.result(allow_private_imports) {
-            Failed(_) => None,
-            result @ _ => Some(result),
+        match self.binding {
+            Some(binding) if !binding.defined_with(DefModifiers::GLOB_IMPORTED) =>
+                Some(Success(binding)),
+            // If (1) we don't allow private imports, (2) no public single import can define the
+            // name, and (3) no public glob has defined the name, the resolution depends on globs.
+            _ if !allow_private_imports && self.pub_outstanding_references == 0 &&
+                 !self.binding.map(NameBinding::is_public).unwrap_or(false) => None,
+            _ if self.outstanding_references > 0 => Some(Indeterminate),
+            Some(binding) => Some(Success(binding)),
+            None => None,
         }
     }