Skip to content

Commit 7d9f389

Browse files
committed
Refactor away NameResolution::result
1 parent cbf2d89 commit 7d9f389

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

src/librustc_resolve/resolve_imports.rs

+10-16
Original file line numberDiff line numberDiff line change
@@ -141,26 +141,20 @@ impl<'a> NameResolution<'a> {
141141
Ok(())
142142
}
143143

144-
// Returns the resolution of the name assuming no more globs will define it.
145-
fn result(&self, allow_private_imports: bool) -> ResolveResult<&'a NameBinding<'a>> {
146-
match self.binding {
147-
Some(binding) if !binding.defined_with(DefModifiers::GLOB_IMPORTED) => Success(binding),
148-
// If we don't allow private imports and no public imports can define the name, fail.
149-
_ if !allow_private_imports && self.pub_outstanding_references == 0 &&
150-
!self.binding.map(NameBinding::is_public).unwrap_or(false) => Failed(None),
151-
_ if self.outstanding_references > 0 => Indeterminate,
152-
Some(binding) => Success(binding),
153-
None => Failed(None),
154-
}
155-
}
156-
157144
// Returns Some(the resolution of the name), or None if the resolution depends
158145
// on whether more globs can define the name.
159146
fn try_result(&self, allow_private_imports: bool)
160147
-> Option<ResolveResult<&'a NameBinding<'a>>> {
161-
match self.result(allow_private_imports) {
162-
Failed(_) => None,
163-
result @ _ => Some(result),
148+
match self.binding {
149+
Some(binding) if !binding.defined_with(DefModifiers::GLOB_IMPORTED) =>
150+
Some(Success(binding)),
151+
// If (1) we don't allow private imports, (2) no public single import can define the
152+
// name, and (3) no public glob has defined the name, the resolution depends on globs.
153+
_ if !allow_private_imports && self.pub_outstanding_references == 0 &&
154+
!self.binding.map(NameBinding::is_public).unwrap_or(false) => None,
155+
_ if self.outstanding_references > 0 => Some(Indeterminate),
156+
Some(binding) => Some(Success(binding)),
157+
None => None,
164158
}
165159
}
166160

0 commit comments

Comments
 (0)