From f95f3410826bba0b95076d7e026e0a5aafb227f7 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 7 May 2026 18:56:45 +0300 Subject: [PATCH 1/2] Add a regression test for issue #156264 --- ...biguous-import-visibility-globglob-reexport.rs | 15 +++++++++++++++ ...ous-import-visibility-globglob-reexport.stderr | 11 +++++++++++ 2 files changed, 26 insertions(+) create mode 100644 tests/ui/imports/ambiguous-import-visibility-globglob-reexport.rs create mode 100644 tests/ui/imports/ambiguous-import-visibility-globglob-reexport.stderr diff --git a/tests/ui/imports/ambiguous-import-visibility-globglob-reexport.rs b/tests/ui/imports/ambiguous-import-visibility-globglob-reexport.rs new file mode 100644 index 0000000000000..136fd6de31750 --- /dev/null +++ b/tests/ui/imports/ambiguous-import-visibility-globglob-reexport.rs @@ -0,0 +1,15 @@ +// Regression test for issue #156264 + +mod m_pub { + pub struct S {} +} + +mod m_crate { + pub(crate) use crate::m_pub::S; +} + +pub(crate) use m_crate::*; +//~^ ERROR `S` is only public within the crate, and cannot be re-exported outside +pub use m_pub::*; + +fn main() {} diff --git a/tests/ui/imports/ambiguous-import-visibility-globglob-reexport.stderr b/tests/ui/imports/ambiguous-import-visibility-globglob-reexport.stderr new file mode 100644 index 0000000000000..be845fbe05c79 --- /dev/null +++ b/tests/ui/imports/ambiguous-import-visibility-globglob-reexport.stderr @@ -0,0 +1,11 @@ +error[E0365]: `S` is only public within the crate, and cannot be re-exported outside + --> $DIR/ambiguous-import-visibility-globglob-reexport.rs:11:16 + | +LL | pub(crate) use m_crate::*; + | ^^^^^^^^^^ re-export of crate public `S` + | + = note: consider declaring type or module `S` with `pub` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0365`. From 235fa6b34cc06a04660e64aae775933eb7ae490a Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 7 May 2026 19:18:22 +0300 Subject: [PATCH 2/2] resolve: Fix a false positive "cannot reexport" error for ambiguous glob sets --- compiler/rustc_resolve/src/imports.rs | 4 ++++ .../ambiguous-import-visibility-globglob-reexport.rs | 3 ++- ...biguous-import-visibility-globglob-reexport.stderr | 11 ----------- 3 files changed, 6 insertions(+), 12 deletions(-) delete mode 100644 tests/ui/imports/ambiguous-import-visibility-globglob-reexport.stderr diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index 1b9e5d2a2daa6..b36dd1ef31bb9 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -822,6 +822,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { for decl in [resolution.non_glob_decl, resolution.glob_decl] { if let Some(decl) = decl && let DeclKind::Import { source_decl, import } = decl.kind + // FIXME: Do not check visibility-ambiguous imports for now. To check them + // properly we need to preserve all imports in ambiguous glob sets and + // check them all individually. + && decl.ambiguity_vis_max.get().is_none() { // The source entity is too private to be reexported // with the given import declaration's visibility. diff --git a/tests/ui/imports/ambiguous-import-visibility-globglob-reexport.rs b/tests/ui/imports/ambiguous-import-visibility-globglob-reexport.rs index 136fd6de31750..25dd51141c936 100644 --- a/tests/ui/imports/ambiguous-import-visibility-globglob-reexport.rs +++ b/tests/ui/imports/ambiguous-import-visibility-globglob-reexport.rs @@ -1,5 +1,7 @@ // Regression test for issue #156264 +//@ check-pass + mod m_pub { pub struct S {} } @@ -9,7 +11,6 @@ mod m_crate { } pub(crate) use m_crate::*; -//~^ ERROR `S` is only public within the crate, and cannot be re-exported outside pub use m_pub::*; fn main() {} diff --git a/tests/ui/imports/ambiguous-import-visibility-globglob-reexport.stderr b/tests/ui/imports/ambiguous-import-visibility-globglob-reexport.stderr deleted file mode 100644 index be845fbe05c79..0000000000000 --- a/tests/ui/imports/ambiguous-import-visibility-globglob-reexport.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0365]: `S` is only public within the crate, and cannot be re-exported outside - --> $DIR/ambiguous-import-visibility-globglob-reexport.rs:11:16 - | -LL | pub(crate) use m_crate::*; - | ^^^^^^^^^^ re-export of crate public `S` - | - = note: consider declaring type or module `S` with `pub` - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0365`.