resolve: Fix a false positive "cannot reexport" error for ambiguous glob sets

This commit is contained in:
Vadim Petrochenkov
2026-05-07 19:18:22 +03:00
parent f95f341082
commit 235fa6b34c
3 changed files with 6 additions and 12 deletions
+4
View File
@@ -822,6 +822,10 @@ pub(crate) fn lint_reexports(&mut self, exported_ambiguities: FxHashSet<Decl<'ra
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.
@@ -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() {}
@@ -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`.