@@ -173,13 +173,14 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
173
173
fn resolve_imports ( & mut self ) {
174
174
let mut i = 0 ;
175
175
let mut prev_unresolved_imports = 0 ;
176
+ let mut errors = Vec :: new ( ) ;
177
+
176
178
loop {
177
179
debug ! ( "(resolving imports) iteration {}, {} imports left" ,
178
180
i,
179
181
self . resolver. unresolved_imports) ;
180
182
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) ;
183
184
184
185
if self . resolver . unresolved_imports == 0 {
185
186
debug ! ( "(resolving imports) success" ) ;
@@ -197,7 +198,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
197
198
// to avoid generating multiple errors on the same import.
198
199
// Imports that are still indeterminate at this point are actually blocked
199
200
// 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 ) ;
201
202
}
202
203
break ;
203
204
}
@@ -234,30 +235,27 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
234
235
/// Attempts to resolve imports for the given module and all of its
235
236
/// submodules.
236
237
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 > > ) {
240
240
debug ! ( "(resolving imports for module subtree) resolving {}" ,
241
241
module_to_string( & module_) ) ;
242
242
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 ) ;
244
244
self . resolver . current_module = orig_module;
245
245
246
246
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 ) ;
248
248
}
249
-
250
- errors
251
249
}
252
250
253
251
/// 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 > > ) {
257
255
if module. all_imports_resolved ( ) {
258
256
debug ! ( "(resolving imports for module) all imports resolved for {}" ,
259
257
module_to_string( & module) ) ;
260
- return errors ;
258
+ return ;
261
259
}
262
260
263
261
let mut imports = module. imports . borrow_mut ( ) ;
@@ -278,6 +276,8 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
278
276
span : span,
279
277
help : help,
280
278
} ) ;
279
+ module. resolved_import_count . set ( module. resolved_import_count . get ( ) + 1 ) ;
280
+ continue ;
281
281
}
282
282
ResolveResult :: Indeterminate => { }
283
283
ResolveResult :: Success ( ( ) ) => {
@@ -293,8 +293,6 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
293
293
}
294
294
295
295
imports. extend ( indeterminate_imports) ;
296
-
297
- errors
298
296
}
299
297
300
298
/// Attempts to resolve the given import. The return value indicates
@@ -562,6 +560,13 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
562
560
ns : Namespace ,
563
561
binding : & ' b NameBinding < ' b > ,
564
562
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
+
565
570
if old_binding. is_extern_crate ( ) {
566
571
let msg = format ! ( "import `{0}` conflicts with imported crate \
567
572
in this module (maybe you meant `use {0}::*`?)",
0 commit comments