Handle conflicting import of items declared in the same module

Fixes #19498
This commit is contained in:
Mukilan Thiyagarajan 2014-12-04 18:51:44 +05:30
parent 3a325c666d
commit 7403b0ceaa

View File

@ -2654,10 +2654,34 @@ impl<'a> Resolver<'a> {
}
Some(_) => {
// The import is unresolved. Bail out.
debug!("(resolving single import) unresolved import; \
bailing out");
return Indeterminate;
// If containing_module is the same module whose import we are resolving
// and there it has an unresolved import with the same name as `source`,
// then the user is actually trying to import an item that is declared
// in the same scope
//
// e.g
// use self::submodule;
// pub mod submodule;
//
// In this case we continue as if we resolved the import and let the
// check_for_conflicts_between_imports_and_items call below handle
// the conflict
match (module_.def_id.get(), containing_module.def_id.get()) {
(Some(id1), Some(id2)) if id1 == id2 => {
if value_result.is_unknown() {
value_result = UnboundResult;
}
if type_result.is_unknown() {
type_result = UnboundResult;
}
}
_ => {
// The import is unresolved. Bail out.
debug!("(resolving single import) unresolved import; \
bailing out");
return Indeterminate;
}
}
}
}
}
@ -3018,7 +3042,7 @@ impl<'a> Resolver<'a> {
fn check_for_conflicts_between_imports_and_items(&mut self,
module: &Module,
import_resolution:
&mut ImportResolution,
&ImportResolution,
import_span: Span,
name: Name) {
if self.session.features.borrow().import_shadowing {