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 itertools:: Itertools ;
@@ -374,24 +375,21 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
374375 pub ( crate ) fn import_decl_vis ( & self , decl : Decl < ' ra > , import : ImportSummary ) -> Visibility {
375376 assert ! ( import. vis. is_accessible_from( import. nearest_parent_mod, self . tcx) ) ;
376377 let decl_vis = decl. vis ( ) ;
377- if decl_vis. is_at_least ( import. vis , self . tcx ) {
378- // Ordered, import is less visible than the imported declaration, or the same,
379- // use the import's visibility.
380- import. vis
381- } else if decl_vis. is_accessible_from ( import. nearest_parent_mod , self . tcx ) {
382- // Ordered, imported declaration is less visible than the import, but is still visible
378+ if decl_vis. partial_cmp ( import. vis , self . tcx ) == Some ( Ordering :: Less )
379+ && decl_vis. is_accessible_from ( import. nearest_parent_mod , self . tcx )
380+ && pub_use_of_private_extern_crate_hack ( import, decl) . is_none ( )
381+ {
382+ // Imported declaration is less visible than the import, but is still visible
383383 // from the current module, use the declaration's visibility.
384- assert ! ( import. vis. is_at_least( decl_vis, self . tcx) ) ;
385- if pub_use_of_private_extern_crate_hack ( import, decl) . is_some ( ) {
386- import. vis
387- } else {
388- decl_vis. expect_local ( )
389- }
384+ decl_vis. expect_local ( )
390385 } else {
391- // Ordered or not, the imported declaration is too private for the current module.
386+ // Good case - imported declaration is more visible than the import, or the same,
387+ // use the import's visibility.
388+ // Bad case - imported declaration is too private for the current module.
392389 // It doesn't matter what visibility we choose here (except in the `PRIVATE_MACRO_USE`
393- // case), because either some error will be reported, or the import declaration
394- // will be thrown away (unfortunately cannot use delayed bug here for this reason).
390+ // and `PUB_USE_OF_PRIVATE_EXTERN_CRATE` cases), because either some error will be
391+ // reported, or the import declaration will be thrown away (unfortunately cannot use
392+ // delayed bug here for this reason).
395393 // Use import visibility to keep the all declaration visibilities in a module ordered.
396394 import. vis
397395 }
@@ -404,7 +402,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
404402
405403 if let ImportKind :: Glob { ref max_vis, .. } = import. kind
406404 && ( vis == import. vis
407- || max_vis. get ( ) . is_none_or ( |max_vis| vis. is_at_least ( max_vis, self . tcx ) ) )
405+ || max_vis. get ( ) . is_none_or ( |max_vis| vis. greater_than ( max_vis, self . tcx ) ) )
408406 {
409407 max_vis. set_unchecked ( Some ( vis) )
410408 }
@@ -475,7 +473,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
475473 // FIXME: remove this when `warn_ambiguity` is removed (#149195).
476474 self . arenas . alloc_decl ( ( * old_glob_decl) . clone ( ) )
477475 }
478- } else if !old_glob_decl . vis ( ) . is_at_least ( glob_decl . vis ( ) , self . tcx ) {
476+ } else if glob_decl . vis ( ) . greater_than ( old_glob_decl . vis ( ) , self . tcx ) {
479477 // We are glob-importing the same item but with greater visibility.
480478 // All visibilities here are ordered because all of them are ancestors of `module`.
481479 // FIXME: Update visibility in place, but without regressions
@@ -1251,7 +1249,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
12511249 } ) ;
12521250 }
12531251 if let Some ( max_vis) = max_vis. get ( )
1254- && !max_vis . is_at_least ( import. vis , self . tcx )
1252+ && import. vis . greater_than ( max_vis , self . tcx )
12551253 {
12561254 let def_id = self . local_def_id ( id) ;
12571255 self . lint_buffer . buffer_lint (
@@ -1500,7 +1498,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15001498 return ;
15011499 } ;
15021500
1503- if !binding . vis ( ) . is_at_least ( import . vis , this. tcx ) {
1501+ if import . vis . greater_than ( binding . vis ( ) , this. tcx ) {
15041502 reexport_error = Some ( ( ns, binding) ) ;
15051503 if let Visibility :: Restricted ( binding_def_id) = binding. vis ( )
15061504 && binding_def_id. is_top_level_module ( )
0 commit comments