11//! A bunch of methods and structures more or less related to resolving imports.
22
3+ use std:: cmp:: Ordering ;
34use std:: mem;
45
56use rustc_ast:: { Item , NodeId } ;
@@ -373,24 +374,21 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
373374 pub ( crate ) fn import_decl_vis ( & self , decl : Decl < ' ra > , import : ImportSummary ) -> Visibility {
374375 assert ! ( import. vis. is_accessible_from( import. nearest_parent_mod, self . tcx) ) ;
375376 let decl_vis = decl. vis ( ) ;
376- if decl_vis. is_at_least ( import. vis , self . tcx ) {
377- // Ordered, import is less visible than the imported declaration, or the same,
378- // use the import's visibility.
379- import. vis
380- } else if decl_vis. is_accessible_from ( import. nearest_parent_mod , self . tcx ) {
381- // Ordered, imported declaration is less visible than the import, but is still visible
377+ if decl_vis. partial_cmp ( import. vis , self . tcx ) == Some ( Ordering :: Less )
378+ && decl_vis. is_accessible_from ( import. nearest_parent_mod , self . tcx )
379+ && pub_use_of_private_extern_crate_hack ( import, decl) . is_none ( )
380+ {
381+ // Imported declaration is less visible than the import, but is still visible
382382 // from the current module, use the declaration's visibility.
383- assert ! ( import. vis. is_at_least( decl_vis, self . tcx) ) ;
384- if pub_use_of_private_extern_crate_hack ( import, decl) . is_some ( ) {
385- import. vis
386- } else {
387- decl_vis. expect_local ( )
388- }
383+ decl_vis. expect_local ( )
389384 } else {
390- // Ordered or not, the imported declaration is too private for the current module.
385+ // Good case - imported declaration is more visible than the import, or the same,
386+ // use the import's visibility.
387+ // Bad case - imported declaration is too private for the current module.
391388 // It doesn't matter what visibility we choose here (except in the `PRIVATE_MACRO_USE`
392- // case), because either some error will be reported, or the import declaration
393- // will be thrown away (unfortunately cannot use delayed bug here for this reason).
389+ // and `PUB_USE_OF_PRIVATE_EXTERN_CRATE` cases), because either some error will be
390+ // reported, or the import declaration will be thrown away (unfortunately cannot use
391+ // delayed bug here for this reason).
394392 // Use import visibility to keep the all declaration visibilities in a module ordered.
395393 import. vis
396394 }
@@ -403,7 +401,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
403401
404402 if let ImportKind :: Glob { ref max_vis, .. } = import. kind
405403 && ( vis == import. vis
406- || max_vis. get ( ) . is_none_or ( |max_vis| vis. is_at_least ( max_vis, self . tcx ) ) )
404+ || max_vis. get ( ) . is_none_or ( |max_vis| vis. greater_than ( max_vis, self . tcx ) ) )
407405 {
408406 max_vis. set_unchecked ( Some ( vis) )
409407 }
@@ -474,7 +472,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
474472 // FIXME: remove this when `warn_ambiguity` is removed (#149195).
475473 self . arenas . alloc_decl ( ( * old_glob_decl) . clone ( ) )
476474 }
477- } else if !old_glob_decl . vis ( ) . is_at_least ( glob_decl . vis ( ) , self . tcx ) {
475+ } else if glob_decl . vis ( ) . greater_than ( old_glob_decl . vis ( ) , self . tcx ) {
478476 // We are glob-importing the same item but with greater visibility.
479477 // All visibilities here are ordered because all of them are ancestors of `module`.
480478 // FIXME: Update visibility in place, but without regressions
@@ -1244,7 +1242,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
12441242 } ) ;
12451243 }
12461244 if let Some ( max_vis) = max_vis. get ( )
1247- && !max_vis . is_at_least ( import. vis , self . tcx )
1245+ && import. vis . greater_than ( max_vis , self . tcx )
12481246 {
12491247 let def_id = self . local_def_id ( id) ;
12501248 self . lint_buffer . buffer_lint (
@@ -1493,7 +1491,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
14931491 return ;
14941492 } ;
14951493
1496- if !binding . vis ( ) . is_at_least ( import . vis , this. tcx ) {
1494+ if import . vis . greater_than ( binding . vis ( ) , this. tcx ) {
14971495 reexport_error = Some ( ( ns, binding) ) ;
14981496 if let Visibility :: Restricted ( binding_def_id) = binding. vis ( )
14991497 && binding_def_id. is_top_level_module ( )
0 commit comments