@@ -787,6 +787,29 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
787787 let resolution = resolution. borrow ( ) ;
788788 let Some ( binding) = resolution. best_decl ( ) else { continue } ;
789789
790+ // Report "cannot reexport" errors for exotic cases involving macros 2.0
791+ // privacy bending or invariant-breaking code under deprecation lints.
792+ for decl in [ resolution. non_glob_decl , resolution. glob_decl ] {
793+ if let Some ( decl) = decl
794+ && let DeclKind :: Import { source_decl, import } = decl. kind
795+ {
796+ // The source entity is too private to be reexported
797+ // with the given import declaration's visibility.
798+ let ord = source_decl. vis ( ) . partial_cmp ( decl. vis ( ) , self . tcx ) ;
799+ if matches ! ( ord, None | Some ( Ordering :: Less ) ) {
800+ let ident = match import. kind {
801+ ImportKind :: Single { source, .. } => source,
802+ _ => key. ident . orig ( resolution. orig_ident_span ) ,
803+ } ;
804+ if let Some ( lint) =
805+ self . report_cannot_reexport ( import, source_decl, ident, key. ns )
806+ {
807+ self . lint_buffer . add_early_lint ( lint) ;
808+ }
809+ }
810+ }
811+ }
812+
790813 if let DeclKind :: Import { import, .. } = binding. kind
791814 && let Some ( amb_binding) = binding. ambiguity . get ( )
792815 && binding. res ( ) != Res :: Err
@@ -1498,18 +1521,20 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
14981521 let mut reexport_error = None ;
14991522 let mut any_successful_reexport = false ;
15001523 self . per_ns ( |this, ns| {
1501- let Some ( binding) = bindings[ ns] . get ( ) . decl ( ) . map ( |b| b . import_source ( ) ) else {
1524+ let Some ( binding) = bindings[ ns] . get ( ) . decl ( ) else {
15021525 return ;
15031526 } ;
15041527
15051528 if import. vis . greater_than ( binding. vis ( ) , this. tcx ) {
1506- reexport_error = Some ( ( ns, binding) ) ;
1529+ // In isolation, a declaration like this is not an error, but if *all* 1-3
1530+ // declarations introduced by the import are more private than the import item's
1531+ // nominal visibility, then it's an error.
1532+ reexport_error = Some ( ( ns, binding. import_source ( ) ) ) ;
15071533 } else {
15081534 any_successful_reexport = true ;
15091535 }
15101536 } ) ;
15111537
1512- // All namespaces must be re-exported with extra visibility for an error to occur.
15131538 if !any_successful_reexport {
15141539 let ( ns, binding) = reexport_error. unwrap ( ) ;
15151540 if let Some ( lint) = self . report_cannot_reexport ( import, binding, ident, ns) {
0 commit comments