@@ -173,13 +173,14 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
173173 fn resolve_imports ( & mut self ) {
174174 let mut i = 0 ;
175175 let mut prev_unresolved_imports = 0 ;
176+ let mut errors = Vec :: new ( ) ;
177+
176178 loop {
177179 debug ! ( "(resolving imports) iteration {}, {} imports left" ,
178180 i,
179181 self . resolver. unresolved_imports) ;
180182
181- let module_root = self . resolver . graph_root ;
182- let errors = self . resolve_imports_for_module_subtree ( module_root) ;
183+ self . resolve_imports_for_module_subtree ( self . resolver . graph_root , & mut errors) ;
183184
184185 if self . resolver . unresolved_imports == 0 {
185186 debug ! ( "(resolving imports) success" ) ;
@@ -197,7 +198,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
197198 // to avoid generating multiple errors on the same import.
198199 // Imports that are still indeterminate at this point are actually blocked
199200 // by errored imports, so there is no point reporting them.
200- self . resolver . report_unresolved_imports ( module_root ) ;
201+ self . resolver . report_unresolved_imports ( self . resolver . graph_root ) ;
201202 }
202203 break ;
203204 }
@@ -234,30 +235,27 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
234235 /// Attempts to resolve imports for the given module and all of its
235236 /// submodules.
236237 fn resolve_imports_for_module_subtree ( & mut self ,
237- module_ : Module < ' b > )
238- -> Vec < ImportResolvingError < ' b > > {
239- let mut errors = Vec :: new ( ) ;
238+ module_ : Module < ' b > ,
239+ errors : & mut Vec < ImportResolvingError < ' b > > ) {
240240 debug ! ( "(resolving imports for module subtree) resolving {}" ,
241241 module_to_string( & module_) ) ;
242242 let orig_module = replace ( & mut self . resolver . current_module , module_) ;
243- errors . extend ( self . resolve_imports_for_module ( module_) ) ;
243+ self . resolve_imports_for_module ( module_, errors ) ;
244244 self . resolver . current_module = orig_module;
245245
246246 for ( _, child_module) in module_. module_children . borrow ( ) . iter ( ) {
247- errors . extend ( self . resolve_imports_for_module_subtree ( child_module) ) ;
247+ self . resolve_imports_for_module_subtree ( child_module, errors ) ;
248248 }
249-
250- errors
251249 }
252250
253251 /// Attempts to resolve imports for the given module only.
254- fn resolve_imports_for_module ( & mut self , module : Module < ' b > ) -> Vec < ImportResolvingError < ' b > > {
255- let mut errors = Vec :: new ( ) ;
256-
252+ fn resolve_imports_for_module ( & mut self ,
253+ module : Module < ' b > ,
254+ errors : & mut Vec < ImportResolvingError < ' b > > ) {
257255 if module. all_imports_resolved ( ) {
258256 debug ! ( "(resolving imports for module) all imports resolved for {}" ,
259257 module_to_string( & module) ) ;
260- return errors ;
258+ return ;
261259 }
262260
263261 let mut imports = module. imports . borrow_mut ( ) ;
@@ -278,6 +276,8 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
278276 span : span,
279277 help : help,
280278 } ) ;
279+ module. resolved_import_count . set ( module. resolved_import_count . get ( ) + 1 ) ;
280+ continue ;
281281 }
282282 ResolveResult :: Indeterminate => { }
283283 ResolveResult :: Success ( ( ) ) => {
@@ -293,8 +293,6 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
293293 }
294294
295295 imports. extend ( indeterminate_imports) ;
296-
297- errors
298296 }
299297
300298 /// Attempts to resolve the given import. The return value indicates
@@ -562,6 +560,13 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
562560 ns : Namespace ,
563561 binding : & ' b NameBinding < ' b > ,
564562 old_binding : & ' b NameBinding < ' b > ) {
563+ // Error on the second of two conflicting imports
564+ if old_binding. is_import ( ) && binding. is_import ( ) &&
565+ old_binding. span . unwrap ( ) . lo > binding. span . unwrap ( ) . lo {
566+ self . report_conflict ( name, ns, old_binding, binding) ;
567+ return ;
568+ }
569+
565570 if old_binding. is_extern_crate ( ) {
566571 let msg = format ! ( "import `{0}` conflicts with imported crate \
567572 in this module (maybe you meant `use {0}::*`?)",
0 commit comments