From de970b1dff21f3e1913374d0794bf85511668667 Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Wed, 9 Mar 2016 04:51:33 +0000 Subject: [PATCH] Refactor away `NameResolution::result` --- src/librustc_resolve/resolve_imports.rs | 26 ++++++++++--------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index a29954ade18..3e7a709345c 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -141,26 +141,20 @@ impl<'a> NameResolution<'a> { 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>> { - 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, } }