@@ -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 }
@@ -236,67 +237,45 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
236237 /// Attempts to resolve imports for the given module and all of its
237238 /// submodules.
238239 fn resolve_imports_for_module_subtree ( & mut self ,
239- module_ : Module < ' b > )
240- -> Vec < ImportResolvingError < ' b > > {
241- let mut errors = Vec :: new ( ) ;
240+ module_ : Module < ' b > ,
241+ errors : & mut Vec < ImportResolvingError < ' b > > ) {
242242 debug ! ( "(resolving imports for module subtree) resolving {}" ,
243243 module_to_string( & module_) ) ;
244244 let orig_module = replace ( & mut self . resolver . current_module , module_) ;
245- errors . extend ( self . resolve_imports_for_module ( module_) ) ;
245+ self . resolve_imports_for_module ( module_, errors ) ;
246246 self . resolver . current_module = orig_module;
247247
248248 for ( _, child_module) in module_. module_children . borrow ( ) . iter ( ) {
249- errors . extend ( self . resolve_imports_for_module_subtree ( child_module) ) ;
249+ self . resolve_imports_for_module_subtree ( child_module, errors ) ;
250250 }
251-
252- errors
253251 }
254252
255253 /// Attempts to resolve imports for the given module only.
256- fn resolve_imports_for_module ( & mut self , module : Module < ' b > ) -> Vec < ImportResolvingError < ' b > > {
257- let mut errors = Vec :: new ( ) ;
258-
259- if module. all_imports_resolved ( ) {
260- debug ! ( "(resolving imports for module) all imports resolved for {}" ,
261- module_to_string( & module) ) ;
262- return errors;
263- }
264-
265- let mut imports = module. imports . borrow_mut ( ) ;
266- let import_count = imports. len ( ) ;
267- let mut indeterminate_imports = Vec :: new ( ) ;
268- while module. resolved_import_count . get ( ) + indeterminate_imports. len ( ) < import_count {
269- let import_index = module. resolved_import_count . get ( ) ;
270- match self . resolve_import_for_module ( module, & imports[ import_index] ) {
271- ResolveResult :: Failed ( err) => {
272- let import_directive = & imports[ import_index] ;
254+ fn resolve_imports_for_module ( & mut self ,
255+ module : Module < ' b > ,
256+ errors : & mut Vec < ImportResolvingError < ' b > > ) {
257+ let mut imports = Vec :: new ( ) ;
258+ let mut unresolved_imports = module. unresolved_imports . borrow_mut ( ) ;
259+ :: std:: mem:: swap ( & mut imports, & mut unresolved_imports) ;
260+
261+ for import_directive in imports {
262+ match self . resolve_import_for_module ( module, & import_directive) {
263+ Failed ( err) => {
273264 let ( span, help) = match err {
274265 Some ( ( span, msg) ) => ( span, format ! ( ". {}" , msg) ) ,
275266 None => ( import_directive. span , String :: new ( ) ) ,
276267 } ;
277268 errors. push ( ImportResolvingError {
278269 source_module : module,
279- import_directive : import_directive. clone ( ) ,
270+ import_directive : import_directive,
280271 span : span,
281272 help : help,
282273 } ) ;
283274 }
284- ResolveResult :: Indeterminate => { }
285- ResolveResult :: Success ( ( ) ) => {
286- // count success
287- module. resolved_import_count
288- . set ( module. resolved_import_count . get ( ) + 1 ) ;
289- continue ;
290- }
275+ Indeterminate => unresolved_imports. push ( import_directive) ,
276+ Success ( ( ) ) => { }
291277 }
292- // This resolution was not successful, keep it for later
293- indeterminate_imports. push ( imports. swap_remove ( import_index) ) ;
294-
295278 }
296-
297- imports. extend ( indeterminate_imports) ;
298-
299- errors
300279 }
301280
302281 /// Attempts to resolve the given import. The return value indicates
@@ -564,6 +543,13 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
564543 ns : Namespace ,
565544 binding : & ' b NameBinding < ' b > ,
566545 old_binding : & ' b NameBinding < ' b > ) {
546+ // Error on the second of two conflicting imports
547+ if old_binding. is_import ( ) && binding. is_import ( ) &&
548+ old_binding. span . unwrap ( ) . lo > binding. span . unwrap ( ) . lo {
549+ self . report_conflict ( name, ns, old_binding, binding) ;
550+ return ;
551+ }
552+
567553 if old_binding. is_extern_crate ( ) {
568554 let msg = format ! ( "import `{0}` conflicts with imported crate \
569555 in this module (maybe you meant `use {0}::*`?)",
0 commit comments