Skip to content

Commit

Permalink
Refactor away resolve_item_by_name_in_lexical_scope
Browse files Browse the repository at this point in the history
  • Loading branch information
jseyfried committed Feb 3, 2016
1 parent 964b72b commit 79a3f22
Showing 1 changed file with 10 additions and 45 deletions.
55 changes: 10 additions & 45 deletions src/librustc_resolve/lib.rs
Expand Up @@ -2774,9 +2774,17 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
}
}

// Check the items.
let module = self.current_module;
let name = identifier.unhygienic_name;
self.resolve_item_by_name_in_lexical_scope(name, namespace, record_used)
.map(LocalDef::from_def)
match self.resolve_item_in_lexical_scope(module, name, namespace, record_used) {
Success((target, _)) => target.binding.def().map(LocalDef::from_def),
Failed(Some((span, msg))) => {
resolve_error(self, span, ResolutionError::FailedToResolve(&*msg));
None
}
_ => None,
}
}

// Resolve a local definition, potentially adjusting for closures.
Expand Down Expand Up @@ -3020,49 +3028,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
None
}

fn resolve_item_by_name_in_lexical_scope(&mut self,
name: Name,
namespace: Namespace,
record_used: bool)
-> Option<Def> {
// Check the items.
let module = self.current_module;
match self.resolve_item_in_lexical_scope(module, name, namespace, record_used) {
Success((target, _)) => {
match target.binding.def() {
None => {
// This can happen if we were looking for a type and
// found a module instead. Modules don't have defs.
debug!("(resolving item path by identifier in lexical scope) failed to \
resolve {} after success...",
name);
None
}
Some(def) => {
debug!("(resolving item path in lexical scope) resolved `{}` to item",
name);
// This lookup is "all public" because it only searched
// for one identifier in the current module (couldn't
// have passed through reexports or anything like that.
Some(def)
}
}
}
Indeterminate => None,
Failed(err) => {
debug!("(resolving item path by identifier in lexical scope) failed to \
resolve `{}`",
name);

if let Some((span, msg)) = err {
resolve_error(self, span, ResolutionError::FailedToResolve(&*msg))
}

None
}
}
}

fn with_no_errors<T, F>(&mut self, f: F) -> T
where F: FnOnce(&mut Resolver) -> T
{
Expand Down

0 comments on commit 79a3f22

Please sign in to comment.