@@ -17,7 +17,7 @@ use {NameBinding, NameBindingKind, PrivacyError};
17
17
use ResolveResult ;
18
18
use ResolveResult :: * ;
19
19
use Resolver ;
20
- use UseLexicalScopeFlag ;
20
+ use UseLexicalScopeFlag :: DontUseLexicalScope ;
21
21
use { names_to_string, module_to_string} ;
22
22
use { resolve_error, ResolutionError } ;
23
23
@@ -382,7 +382,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
382
382
debug ! ( "(resolving imports for module subtree) resolving {}" ,
383
383
module_to_string( & module_) ) ;
384
384
let orig_module = replace ( & mut self . resolver . current_module , module_) ;
385
- self . resolve_imports_for_module ( module_ , errors) ;
385
+ self . resolve_imports_in_current_module ( errors) ;
386
386
self . resolver . current_module = orig_module;
387
387
388
388
for ( _, child_module) in module_. module_children . borrow ( ) . iter ( ) {
@@ -391,22 +391,20 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
391
391
}
392
392
393
393
/// Attempts to resolve imports for the given module only.
394
- fn resolve_imports_for_module ( & mut self ,
395
- module : Module < ' b > ,
396
- errors : & mut Vec < ImportResolvingError < ' b > > ) {
394
+ fn resolve_imports_in_current_module ( & mut self , errors : & mut Vec < ImportResolvingError < ' b > > ) {
397
395
let mut imports = Vec :: new ( ) ;
398
- let mut unresolved_imports = module . unresolved_imports . borrow_mut ( ) ;
396
+ let mut unresolved_imports = self . resolver . current_module . unresolved_imports . borrow_mut ( ) ;
399
397
:: std:: mem:: swap ( & mut imports, & mut unresolved_imports) ;
400
398
401
399
for import_directive in imports {
402
- match self . resolve_import_for_module ( module , & import_directive) {
400
+ match self . resolve_import_for_module ( & import_directive) {
403
401
Failed ( err) => {
404
402
let ( span, help) = match err {
405
403
Some ( ( span, msg) ) => ( span, format ! ( ". {}" , msg) ) ,
406
404
None => ( import_directive. span , String :: new ( ) ) ,
407
405
} ;
408
406
errors. push ( ImportResolvingError {
409
- source_module : module ,
407
+ source_module : self . resolver . current_module ,
410
408
import_directive : import_directive,
411
409
span : span,
412
410
help : help,
@@ -423,23 +421,15 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
423
421
/// don't know whether the name exists at the moment due to other
424
422
/// currently-unresolved imports, or success if we know the name exists.
425
423
/// If successful, the resolved bindings are written into the module.
426
- fn resolve_import_for_module ( & mut self ,
427
- module_ : Module < ' b > ,
428
- import_directive : & ' b ImportDirective )
429
- -> ResolveResult < ( ) > {
424
+ fn resolve_import_for_module ( & mut self , directive : & ' b ImportDirective ) -> ResolveResult < ( ) > {
430
425
debug ! ( "(resolving import for module) resolving import `{}::...` in `{}`" ,
431
- names_to_string( & import_directive . module_path) ,
432
- module_to_string( & module_ ) ) ;
426
+ names_to_string( & directive . module_path) ,
427
+ module_to_string( self . resolver . current_module ) ) ;
433
428
434
429
self . resolver
435
- . resolve_module_path ( & import_directive. module_path ,
436
- UseLexicalScopeFlag :: DontUseLexicalScope ,
437
- import_directive. span )
438
- . and_then ( |containing_module| {
439
- // We found the module that the target is contained
440
- // within. Attempt to resolve the import within it.
441
- self . resolve_import ( module_, containing_module, import_directive)
442
- } )
430
+ . resolve_module_path ( & directive. module_path , DontUseLexicalScope , directive. span )
431
+ // Once we have the module that contains the target, we can resolve the import.
432
+ . and_then ( |containing_module| self . resolve_import ( containing_module, directive) )
443
433
. and_then ( |( ) | {
444
434
// Decrement the count of unresolved imports.
445
435
assert ! ( self . resolver. unresolved_imports >= 1 ) ;
@@ -448,18 +438,16 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
448
438
} )
449
439
}
450
440
451
- fn resolve_import ( & mut self ,
452
- module_ : Module < ' b > ,
453
- target_module : Module < ' b > ,
454
- directive : & ' b ImportDirective )
441
+ fn resolve_import ( & mut self , target_module : Module < ' b > , directive : & ' b ImportDirective )
455
442
-> ResolveResult < ( ) > {
456
443
let ( source, target, value_determined, type_determined) = match directive. subclass {
457
444
SingleImport { source, target, ref value_determined, ref type_determined } =>
458
445
( source, target, value_determined, type_determined) ,
459
- GlobImport => return self . resolve_glob_import ( module_ , target_module, directive) ,
446
+ GlobImport => return self . resolve_glob_import ( target_module, directive) ,
460
447
} ;
461
448
462
449
// We need to resolve both namespaces for this to succeed.
450
+ let module_ = self . resolver . current_module ;
463
451
let ( value_result, type_result) = {
464
452
let mut resolve_in_ns = |ns, determined : bool | {
465
453
// Temporarily count the directive as determined so that the resolution fails
@@ -594,15 +582,13 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
594
582
// succeeds or bails out (as importing * from an empty module or a module
595
583
// that exports nothing is valid). target_module is the module we are
596
584
// actually importing, i.e., `foo` in `use foo::*`.
597
- fn resolve_glob_import ( & mut self ,
598
- module_ : Module < ' b > ,
599
- target_module : Module < ' b > ,
600
- directive : & ' b ImportDirective )
585
+ fn resolve_glob_import ( & mut self , target_module : Module < ' b > , directive : & ' b ImportDirective )
601
586
-> ResolveResult < ( ) > {
602
587
if let Some ( Def :: Trait ( _) ) = target_module. def {
603
588
self . resolver . session . span_err ( directive. span , "items in traits are not importable." ) ;
604
589
}
605
590
591
+ let module_ = self . resolver . current_module ;
606
592
if module_. def_id ( ) == target_module. def_id ( ) {
607
593
// This means we are trying to glob import a module into itself, and it is a no-go
608
594
let msg = "Cannot glob-import a module into itself." . into ( ) ;
0 commit comments