Skip to content

Commit 8e61ca4

Browse files
committed
Refactor resolve_item_in_lexical_scope
1 parent 298346d commit 8e61ca4

File tree

1 file changed

+18
-56
lines changed

1 file changed

+18
-56
lines changed

src/librustc_resolve/lib.rs

Lines changed: 18 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,47 +1423,29 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
14231423
namespace,
14241424
module_to_string(&*module_));
14251425

1426-
// The current module node is handled specially. First, check for
1427-
// its immediate children.
1428-
build_reduced_graph::populate_module_if_necessary(self, &module_);
1429-
1430-
if let Some(binding) = module_.get_child(name, namespace) {
1431-
debug!("top name bindings succeeded");
1432-
return Success((Target::new(module_, binding, Shadowable::Never), false));
1433-
}
1426+
// Proceed up the scope chain looking for parent modules.
1427+
let mut search_module = module_;
1428+
loop {
1429+
// Resolve the name in the parent module.
1430+
match self.resolve_name_in_module(search_module, name, namespace, true, record_used) {
1431+
Failed(Some((span, msg))) => {
1432+
resolve_error(self, span, ResolutionError::FailedToResolve(&*msg));
1433+
}
1434+
Failed(None) => (), // Continue up the search chain.
1435+
Indeterminate => {
1436+
// We couldn't see through the higher scope because of an
1437+
// unresolved import higher up. Bail.
14341438

1435-
// Now check for its import directives. We don't have to have resolved
1436-
// all its imports in the usual way; this is because chains of
1437-
// adjacent import statements are processed as though they mutated the
1438-
// current scope.
1439-
if let Some(import_resolution) =
1440-
module_.import_resolutions.borrow().get(&(name, namespace)) {
1441-
match import_resolution.target.clone() {
1442-
None => {
1443-
// Not found; continue.
1444-
debug!("(resolving item in lexical scope) found import resolution, but not \
1445-
in namespace {:?}",
1446-
namespace);
1439+
debug!("(resolving item in lexical scope) indeterminate higher scope; bailing");
1440+
return Indeterminate;
14471441
}
1448-
Some(target) => {
1449-
debug!("(resolving item in lexical scope) using import resolution");
1450-
// track used imports and extern crates as well
1451-
let id = import_resolution.id;
1452-
if record_used {
1453-
self.used_imports.insert((id, namespace));
1454-
self.record_import_use(id, name);
1455-
if let Some(DefId{krate: kid, ..}) = target.target_module.def_id() {
1456-
self.used_crates.insert(kid);
1457-
}
1458-
}
1459-
return Success((target, false));
1442+
Success((target, used_reexport)) => {
1443+
// We found the module.
1444+
debug!("(resolving item in lexical scope) found name in module, done");
1445+
return Success((target, used_reexport));
14601446
}
14611447
}
1462-
}
14631448

1464-
// Finally, proceed up the scope chain looking for parent modules.
1465-
let mut search_module = module_;
1466-
loop {
14671449
// Go to the next parent.
14681450
match search_module.parent_link {
14691451
NoParentLink => {
@@ -1485,26 +1467,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
14851467
search_module = parent_module_node;
14861468
}
14871469
}
1488-
1489-
// Resolve the name in the parent module.
1490-
match self.resolve_name_in_module(search_module, name, namespace, true, record_used) {
1491-
Failed(Some((span, msg))) => {
1492-
resolve_error(self, span, ResolutionError::FailedToResolve(&*msg));
1493-
}
1494-
Failed(None) => (), // Continue up the search chain.
1495-
Indeterminate => {
1496-
// We couldn't see through the higher scope because of an
1497-
// unresolved import higher up. Bail.
1498-
1499-
debug!("(resolving item in lexical scope) indeterminate higher scope; bailing");
1500-
return Indeterminate;
1501-
}
1502-
Success((target, used_reexport)) => {
1503-
// We found the module.
1504-
debug!("(resolving item in lexical scope) found name in module, done");
1505-
return Success((target, used_reexport));
1506-
}
1507-
}
15081470
}
15091471
}
15101472

0 commit comments

Comments
 (0)