@@ -52,8 +52,8 @@ pub enum ImportKind<'a> {
5252 } ,
5353 Glob {
5454 is_prelude : bool ,
55- max_vis : Cell < ty:: Visibility > , // The visibility of the greatest re-export.
56- // n.b. `max_vis` is only used in `finalize_import` to check for re-export errors.
55+ max_vis : Cell < Option < ty:: Visibility > > , // The visibility of the greatest re-export.
56+ // n.b. `max_vis` is only used in `finalize_import` to check for re-export errors.
5757 } ,
5858 ExternCrate {
5959 source : Option < Symbol > ,
@@ -144,7 +144,7 @@ pub(crate) struct Import<'a> {
144144 pub module_path : Vec < Segment > ,
145145 /// The resolution of `module_path`.
146146 pub imported_module : Cell < Option < ModuleOrUniformRoot < ' a > > > ,
147- pub vis : Cell < ty:: Visibility > ,
147+ pub vis : Cell < Option < ty:: Visibility > > ,
148148 pub used : Cell < bool > ,
149149}
150150
@@ -159,6 +159,10 @@ impl<'a> Import<'a> {
159159 _ => false ,
160160 }
161161 }
162+
163+ pub ( crate ) fn expect_vis ( & self ) -> ty:: Visibility {
164+ self . vis . get ( ) . expect ( "encountered cleared import visibility" )
165+ }
162166}
163167
164168/// Records information about the resolution of a name in a namespace of a module.
@@ -199,7 +203,7 @@ fn pub_use_of_private_extern_crate_hack(import: &Import<'_>, binding: &NameBindi
199203 import : Import { kind : ImportKind :: ExternCrate { .. } , .. } ,
200204 ..
201205 } ,
202- ) => import. vis . get ( ) . is_public ( ) ,
206+ ) => import. expect_vis ( ) . is_public ( ) ,
203207 _ => false ,
204208 }
205209}
@@ -212,17 +216,20 @@ impl<'a> Resolver<'a> {
212216 binding : & ' a NameBinding < ' a > ,
213217 import : & ' a Import < ' a > ,
214218 ) -> & ' a NameBinding < ' a > {
215- let vis = if binding. vis . is_at_least ( import. vis . get ( ) , self )
219+ let import_vis = import. expect_vis ( ) ;
220+ let vis = if binding. vis . is_at_least ( import_vis, self )
216221 || pub_use_of_private_extern_crate_hack ( import, binding)
217222 {
218- import . vis . get ( )
223+ import_vis
219224 } else {
220225 binding. vis
221226 } ;
222227
223228 if let ImportKind :: Glob { ref max_vis, .. } = import. kind {
224- if vis == import. vis . get ( ) || vis. is_at_least ( max_vis. get ( ) , self ) {
225- max_vis. set ( vis)
229+ if vis == import_vis
230+ || max_vis. get ( ) . map_or ( true , |max_vis| vis. is_at_least ( max_vis, self ) )
231+ {
232+ max_vis. set ( Some ( vis) )
226233 }
227234 }
228235
@@ -536,7 +543,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
536543 } else {
537544 // For better failure detection, pretend that the import will
538545 // not define any names while resolving its module path.
539- let orig_vis = import. vis . replace ( ty :: Visibility :: Invisible ) ;
546+ let orig_vis = import. vis . take ( ) ;
540547 let path_res =
541548 self . r . maybe_resolve_path ( & import. module_path , None , & import. parent_scope ) ;
542549 import. vis . set ( orig_vis) ;
@@ -571,7 +578,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
571578 if let Err ( Undetermined ) = source_bindings[ ns] . get ( ) {
572579 // For better failure detection, pretend that the import will
573580 // not define any names while resolving its module path.
574- let orig_vis = import. vis . replace ( ty :: Visibility :: Invisible ) ;
581+ let orig_vis = import. vis . take ( ) ;
575582 let binding = this. resolve_ident_in_module (
576583 module,
577584 source,
@@ -620,7 +627,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
620627 /// Optionally returns an unresolved import error. This error is buffered and used to
621628 /// consolidate multiple unresolved import errors into a single diagnostic.
622629 fn finalize_import ( & mut self , import : & ' b Import < ' b > ) -> Option < UnresolvedImportError > {
623- let orig_vis = import. vis . replace ( ty :: Visibility :: Invisible ) ;
630+ let orig_vis = import. vis . take ( ) ;
624631 let ignore_binding = match & import. kind {
625632 ImportKind :: Single { target_bindings, .. } => target_bindings[ TypeNS ] . get ( ) ,
626633 _ => None ,
@@ -727,9 +734,9 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
727734 } ) ;
728735 }
729736 }
730- if !is_prelude &&
731- max_vis . get ( ) != ty :: Visibility :: Invisible && // Allow empty globs.
732- !max_vis. get ( ) . is_at_least ( import. vis . get ( ) , & * self . r )
737+ if !is_prelude
738+ && let Some ( max_vis ) = max_vis . get ( )
739+ && !max_vis. is_at_least ( import. expect_vis ( ) , & * self . r )
733740 {
734741 let msg = "glob import doesn't reexport anything because no candidate is public enough" ;
735742 self . r . lint_buffer . buffer_lint ( UNUSED_IMPORTS , import. id , import. span , msg) ;
@@ -742,7 +749,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
742749 let mut all_ns_err = true ;
743750 self . r . per_ns ( |this, ns| {
744751 if !type_ns_only || ns == TypeNS {
745- let orig_vis = import. vis . replace ( ty :: Visibility :: Invisible ) ;
752+ let orig_vis = import. vis . take ( ) ;
746753 let binding = this. resolve_ident_in_module (
747754 module,
748755 ident,
@@ -906,8 +913,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
906913 let mut crate_private_reexport = false ;
907914 self . r . per_ns ( |this, ns| {
908915 if let Ok ( binding) = source_bindings[ ns] . get ( ) {
909- let vis = import. vis . get ( ) ;
910- if !binding. vis . is_at_least ( vis, & * this) {
916+ if !binding. vis . is_at_least ( import. expect_vis ( ) , & * this) {
911917 reexport_error = Some ( ( ns, binding) ) ;
912918 if let ty:: Visibility :: Restricted ( binding_def_id) = binding. vis {
913919 if binding_def_id. is_top_level_module ( ) {
0 commit comments