Skip to content

Commit 0c40621

Browse files
committed
Refactor away resolve_module_in_lexical_scope
1 parent 23bdbb1 commit 0c40621

File tree

1 file changed

+11
-34
lines changed

1 file changed

+11
-34
lines changed

src/librustc_resolve/lib.rs

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,16 +1387,22 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
13871387
// This is not a crate-relative path. We resolve the
13881388
// first component of the path in the current lexical
13891389
// scope and then proceed to resolve below that.
1390-
match self.resolve_module_in_lexical_scope(module_, module_path[0]) {
1390+
match self.resolve_item_in_lexical_scope(module_,
1391+
module_path[0],
1392+
TypeNS,
1393+
true) {
13911394
Failed(err) => return Failed(err),
13921395
Indeterminate => {
13931396
debug!("(resolving module path for import) indeterminate; bailing");
13941397
return Indeterminate;
13951398
}
1396-
Success(containing_module) => {
1397-
search_module = containing_module;
1398-
start_index = 1;
1399-
last_private = LastMod(AllPublic);
1399+
Success((target, _)) => match target.binding.module() {
1400+
Some(containing_module) => {
1401+
search_module = containing_module;
1402+
start_index = 1;
1403+
last_private = LastMod(AllPublic);
1404+
}
1405+
None => return Failed(None),
14001406
}
14011407
}
14021408
}
@@ -1477,35 +1483,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
14771483
}
14781484
}
14791485

1480-
/// Resolves a module name in the current lexical scope.
1481-
fn resolve_module_in_lexical_scope(&mut self,
1482-
module_: Module<'a>,
1483-
name: Name)
1484-
-> ResolveResult<Module<'a>> {
1485-
// If this module is an anonymous module, resolve the item in the
1486-
// lexical scope. Otherwise, resolve the item from the crate root.
1487-
let resolve_result = self.resolve_item_in_lexical_scope(module_, name, TypeNS, true);
1488-
match resolve_result {
1489-
Success((target, _)) => {
1490-
if let Some(module_def) = target.binding.module() {
1491-
return Success(module_def)
1492-
} else {
1493-
debug!("!!! (resolving module in lexical scope) module \
1494-
wasn't actually a module!");
1495-
return Failed(None);
1496-
}
1497-
}
1498-
Indeterminate => {
1499-
debug!("(resolving module in lexical scope) indeterminate; bailing");
1500-
return Indeterminate;
1501-
}
1502-
Failed(err) => {
1503-
debug!("(resolving module in lexical scope) failed to resolve");
1504-
return Failed(err);
1505-
}
1506-
}
1507-
}
1508-
15091486
/// Returns the nearest normal module parent of the given module.
15101487
fn get_nearest_normal_module_parent(&mut self, module_: Module<'a>) -> Option<Module<'a>> {
15111488
let mut module_ = module_;

0 commit comments

Comments
 (0)