@@ -68,7 +68,7 @@ pub struct ImportDirective<'a> {
6868 target_module : Cell < Option < Module < ' a > > > , // the resolution of `module_path`
6969 subclass : ImportDirectiveSubclass < ' a > ,
7070 span : Span ,
71- vis : ty:: Visibility , // see note in ImportResolutionPerNamespace about how to use this
71+ vis : Cell < ty:: Visibility > ,
7272}
7373
7474impl < ' a > ImportDirective < ' a > {
@@ -191,7 +191,7 @@ impl<'a> Resolver<'a> {
191191
192192 // Check if the globs are determined
193193 for directive in module. globs . borrow ( ) . iter ( ) {
194- if self . is_accessible ( directive. vis ) {
194+ if self . is_accessible ( directive. vis . get ( ) ) {
195195 if let Some ( target_module) = directive. target_module . get ( ) {
196196 let result = self . resolve_name_in_module ( target_module, name, ns, true , None ) ;
197197 if let Indeterminate = result {
@@ -219,7 +219,7 @@ impl<'a> Resolver<'a> {
219219 // Check if a single import can still define the name.
220220 match resolution. single_imports {
221221 SingleImports :: AtLeastOne => return Some ( Indeterminate ) ,
222- SingleImports :: MaybeOne ( directive) if self . is_accessible ( directive. vis ) => {
222+ SingleImports :: MaybeOne ( directive) if self . is_accessible ( directive. vis . get ( ) ) => {
223223 let target_module = match directive. target_module . get ( ) {
224224 Some ( target_module) => target_module,
225225 None => return Some ( Indeterminate ) ,
@@ -254,7 +254,7 @@ impl<'a> Resolver<'a> {
254254 subclass : subclass,
255255 span : span,
256256 id : id,
257- vis : vis,
257+ vis : Cell :: new ( vis) ,
258258 } ) ;
259259
260260 self . indeterminate_imports . push ( directive) ;
@@ -282,7 +282,7 @@ impl<'a> Resolver<'a> {
282282 directive : directive,
283283 } ,
284284 span : directive. span ,
285- vis : directive. vis ,
285+ vis : directive. vis . get ( ) ,
286286 }
287287 }
288288
@@ -488,13 +488,22 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
488488 let module = directive. parent ;
489489 self . set_current_module ( module) ;
490490
491- let target_module = match directive. target_module . get ( ) {
492- Some ( module) => module,
493- _ => match self . resolve_module_path ( & directive. module_path , DontUseLexicalScope , None ) {
491+ let target_module = if let Some ( module) = directive. target_module . get ( ) {
492+ module
493+ } else {
494+ let vis = directive. vis . get ( ) ;
495+ // For better failure detection, pretend that the import will not define any names
496+ // while resolving its module path.
497+ directive. vis . set ( ty:: Visibility :: PrivateExternal ) ;
498+ let result =
499+ self . resolve_module_path ( & directive. module_path , DontUseLexicalScope , None ) ;
500+ directive. vis . set ( vis) ;
501+
502+ match result {
494503 Success ( module) => module,
495504 Indeterminate => return Indeterminate ,
496505 Failed ( err) => return Failed ( err) ,
497- } ,
506+ }
498507 } ;
499508
500509 directive. target_module . set ( Some ( target_module) ) ;
@@ -614,7 +623,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
614623 }
615624
616625 match ( value_result, type_result) {
617- ( Ok ( binding) , _) if !binding. pseudo_vis ( ) . is_at_least ( directive. vis , self ) => {
626+ ( Ok ( binding) , _) if !binding. pseudo_vis ( ) . is_at_least ( directive. vis . get ( ) , self ) => {
618627 let msg = format ! ( "`{}` is private, and cannot be reexported" , source) ;
619628 let note_msg = format ! ( "consider marking `{}` as `pub` in the imported module" ,
620629 source) ;
@@ -623,7 +632,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
623632 . emit ( ) ;
624633 }
625634
626- ( _, Ok ( binding) ) if !binding. pseudo_vis ( ) . is_at_least ( directive. vis , self ) => {
635+ ( _, Ok ( binding) ) if !binding. pseudo_vis ( ) . is_at_least ( directive. vis . get ( ) , self ) => {
627636 if binding. is_extern_crate ( ) {
628637 let msg = format ! ( "extern crate `{}` is private, and cannot be reexported \
629638 (error E0364), consider declaring with `pub`",
0 commit comments