about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc/middle/resolve.rs34
1 files changed, 29 insertions, 5 deletions
diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs
index b958bdce0a7..17dff18c3c3 100644
--- a/src/librustc/middle/resolve.rs
+++ b/src/librustc/middle/resolve.rs
@@ -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 {