@@ -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
}
@@ -236,67 +237,45 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
236
237
/// Attempts to resolve imports for the given module and all of its
237
238
/// submodules.
238
239
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 > > ) {
242
242
debug ! ( "(resolving imports for module subtree) resolving {}" ,
243
243
module_to_string( & module_) ) ;
244
244
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 ) ;
246
246
self . resolver . current_module = orig_module;
247
247
248
248
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 ) ;
250
250
}
251
-
252
- errors
253
251
}
254
252
255
253
/// 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) => {
273
264
let ( span, help) = match err {
274
265
Some ( ( span, msg) ) => ( span, format ! ( ". {}" , msg) ) ,
275
266
None => ( import_directive. span , String :: new ( ) ) ,
276
267
} ;
277
268
errors. push ( ImportResolvingError {
278
269
source_module : module,
279
- import_directive : import_directive. clone ( ) ,
270
+ import_directive : import_directive,
280
271
span : span,
281
272
help : help,
282
273
} ) ;
283
274
}
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 ( ( ) ) => { }
291
277
}
292
- // This resolution was not successful, keep it for later
293
- indeterminate_imports. push ( imports. swap_remove ( import_index) ) ;
294
-
295
278
}
296
-
297
- imports. extend ( indeterminate_imports) ;
298
-
299
- errors
300
279
}
301
280
302
281
/// Attempts to resolve the given import. The return value indicates
@@ -564,6 +543,13 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
564
543
ns : Namespace ,
565
544
binding : & ' b NameBinding < ' b > ,
566
545
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
+
567
553
if old_binding. is_extern_crate ( ) {
568
554
let msg = format ! ( "import `{0}` conflicts with imported crate \
569
555
in this module (maybe you meant `use {0}::*`?)",
0 commit comments