From f5046d570c1d004b7e81657e0c472ea451105485 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 28 Dec 2025 23:11:15 +0300 Subject: [PATCH 1/2] tests: Reproduce the issue with missing MIR for ambiguous reexports --- tests/ui/imports/ambiguous-reachable.rs | 10 ++++++ tests/ui/imports/ambiguous-reachable.stderr | 31 +++++++++++++++++++ .../auxiliary/ambiguous-reachable-extern.rs | 14 +++++++++ 3 files changed, 55 insertions(+) create mode 100644 tests/ui/imports/ambiguous-reachable.rs create mode 100644 tests/ui/imports/ambiguous-reachable.stderr create mode 100644 tests/ui/imports/auxiliary/ambiguous-reachable-extern.rs diff --git a/tests/ui/imports/ambiguous-reachable.rs b/tests/ui/imports/ambiguous-reachable.rs new file mode 100644 index 0000000000000..1ca31c402ae61 --- /dev/null +++ b/tests/ui/imports/ambiguous-reachable.rs @@ -0,0 +1,10 @@ +//@ build-fail +//@ aux-crate: ambiguous_reachable_extern=ambiguous-reachable-extern.rs + +#![allow(ambiguous_glob_imports)] + +fn main() { + ambiguous_reachable_extern::generic::(); +} + +//~? ERROR missing optimized MIR diff --git a/tests/ui/imports/ambiguous-reachable.stderr b/tests/ui/imports/ambiguous-reachable.stderr new file mode 100644 index 0000000000000..5ba00970a23a0 --- /dev/null +++ b/tests/ui/imports/ambiguous-reachable.stderr @@ -0,0 +1,31 @@ +error: missing optimized MIR for `ambiguous_reachable_extern::m1::generic::` in the crate `ambiguous_reachable_extern` + | +note: missing optimized MIR for this item (was the crate `ambiguous_reachable_extern` compiled with `--emit=metadata`?) + --> $DIR/auxiliary/ambiguous-reachable-extern.rs:2:5 + | +LL | pub fn generic() { + | ^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + +Future incompatibility report: Future breakage diagnostic: +warning: `generic` is ambiguous + --> $DIR/ambiguous-reachable.rs:7:33 + | +LL | ambiguous_reachable_extern::generic::(); + | ^^^^^^^ ambiguous name + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #114095 + = note: ambiguous because of multiple glob imports of a name in the same module +note: `generic` could refer to the function defined here + --> $DIR/auxiliary/ambiguous-reachable-extern.rs:13:9 + | +LL | pub use m1::*; + | ^^ +note: `generic` could also refer to the function defined here + --> $DIR/auxiliary/ambiguous-reachable-extern.rs:14:9 + | +LL | pub use m2::*; + | ^^ + diff --git a/tests/ui/imports/auxiliary/ambiguous-reachable-extern.rs b/tests/ui/imports/auxiliary/ambiguous-reachable-extern.rs new file mode 100644 index 0000000000000..af81812560e38 --- /dev/null +++ b/tests/ui/imports/auxiliary/ambiguous-reachable-extern.rs @@ -0,0 +1,14 @@ +mod m1 { + pub fn generic() { + let x = 10; + let y = 11; + println!("hello {x} world {:?}", y); + } +} + +mod m2 { + pub fn generic() {} +} + +pub use m1::*; +pub use m2::*; From 6ada0d2639347ab356da55578a798db383e3db56 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 8 Jan 2026 23:48:46 +0300 Subject: [PATCH 2/2] resolve: Mark items under ambigous imports as exported --- .../src/effective_visibilities.rs | 31 +++---------------- tests/rustdoc-html/glob-shadowing.rs | 12 ++++--- tests/rustdoc-json/reexport/glob_collision.rs | 4 ++- tests/ui/imports/ambiguous-reachable.rs | 4 +-- tests/ui/imports/ambiguous-reachable.stderr | 10 ------ 5 files changed, 16 insertions(+), 45 deletions(-) diff --git a/compiler/rustc_resolve/src/effective_visibilities.rs b/compiler/rustc_resolve/src/effective_visibilities.rs index ebdb0060e1b94..75f03d59157fd 100644 --- a/compiler/rustc_resolve/src/effective_visibilities.rs +++ b/compiler/rustc_resolve/src/effective_visibilities.rs @@ -96,13 +96,10 @@ impl<'a, 'ra, 'tcx> EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx> { // is the maximum value among visibilities of declarations corresponding to that def id. for (decl, eff_vis) in visitor.import_effective_visibilities.iter() { let DeclKind::Import { import, .. } = decl.kind else { unreachable!() }; - if !decl.is_ambiguity_recursive() { - if let Some(node_id) = import.id() { - r.effective_visibilities.update_eff_vis(r.local_def_id(node_id), eff_vis, r.tcx) - } - } else if decl.ambiguity.get().is_some() - && eff_vis.is_public_at_level(Level::Reexported) - { + if let Some(node_id) = import.id() { + r.effective_visibilities.update_eff_vis(r.local_def_id(node_id), eff_vis, r.tcx) + } + if decl.ambiguity.get().is_some() && eff_vis.is_public_at_level(Level::Reexported) { exported_ambiguities.insert(*decl); } } @@ -123,31 +120,13 @@ impl<'a, 'ra, 'tcx> EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx> { // Set the given effective visibility level to `Level::Direct` and // sets the rest of the `use` chain to `Level::Reexported` until // we hit the actual exported item. - // - // If the binding is ambiguous, put the root ambiguity binding and all reexports - // leading to it into the table. They are used by the `ambiguous_glob_reexports` - // lint. For all bindings added to the table this way `is_ambiguity` returns true. - let is_ambiguity = - |decl: Decl<'ra>, warn: bool| decl.ambiguity.get().is_some() && !warn; let mut parent_id = ParentId::Def(module_id); - let mut warn_ambiguity = decl.warn_ambiguity.get(); while let DeclKind::Import { source_decl, .. } = decl.kind { self.update_import(decl, parent_id); - - if is_ambiguity(decl, warn_ambiguity) { - // Stop at the root ambiguity, further bindings in the chain should not - // be reexported because the root ambiguity blocks any access to them. - // (Those further bindings are most likely not ambiguities themselves.) - break; - } - parent_id = ParentId::Import(decl); decl = source_decl; - warn_ambiguity |= source_decl.warn_ambiguity.get(); } - if !is_ambiguity(decl, warn_ambiguity) - && let Some(def_id) = decl.res().opt_def_id().and_then(|id| id.as_local()) - { + if let Some(def_id) = decl.res().opt_def_id().and_then(|id| id.as_local()) { self.update_def(def_id, decl.vis().expect_local(), parent_id); } } diff --git a/tests/rustdoc-html/glob-shadowing.rs b/tests/rustdoc-html/glob-shadowing.rs index d9e9ead3f9a90..c1eeb7e663e7b 100644 --- a/tests/rustdoc-html/glob-shadowing.rs +++ b/tests/rustdoc-html/glob-shadowing.rs @@ -1,9 +1,9 @@ //@ has 'glob_shadowing/index.html' -//@ count - '//dt' 6 -//@ !has - '//dd' 'sub1::describe' +//@ count - '//dt' 7 +//@ !has - '//dd' 'sub1::describe1' //@ has - '//dd' 'sub2::describe' -//@ !has - '//dd' 'sub1::describe2' +//@ has - '//dd' 'sub1::describe2' //@ !has - '//dd' 'sub1::prelude' //@ has - '//dd' 'mod::prelude' @@ -18,7 +18,7 @@ mod sub1 { // this should be shadowed by sub2::describe - /// sub1::describe + /// sub1::describe1 pub fn describe() -> &'static str { "sub1::describe" } @@ -33,7 +33,9 @@ mod sub1 { pub struct Foo; // this should be shadowed, - // because both sub1::describe2 and sub3::describe2 are from glob reexport + // because both sub1::describe2 and sub3::describe2 are from glob reexport, + // but it is still usable from other crates under the `ambiguous_glob_imports` lint, + // so it is reachable and documented /// sub1::describe2 pub fn describe2() -> &'static str { "sub1::describe2" diff --git a/tests/rustdoc-json/reexport/glob_collision.rs b/tests/rustdoc-json/reexport/glob_collision.rs index 48de1b5e77213..dd6eab6517b09 100644 --- a/tests/rustdoc-json/reexport/glob_collision.rs +++ b/tests/rustdoc-json/reexport/glob_collision.rs @@ -1,7 +1,9 @@ // Regression test for https://github.com/rust-lang/rust/issues/100973 +// Update: the rules has changed after #147984, one of the colliding items is now available +// from other crates under a deprecation lint. //@ set m1 = "$.index[?(@.name == 'm1' && @.inner.module)].id" -//@ is "$.index[?(@.name == 'm1')].inner.module.items" [] +//@ is "$.index[?(@.name == 'm1')].inner.module.items" [0] //@ is "$.index[?(@.name == 'm1')].inner.module.is_stripped" true mod m1 { pub fn f() {} diff --git a/tests/ui/imports/ambiguous-reachable.rs b/tests/ui/imports/ambiguous-reachable.rs index 1ca31c402ae61..fc92315622aa1 100644 --- a/tests/ui/imports/ambiguous-reachable.rs +++ b/tests/ui/imports/ambiguous-reachable.rs @@ -1,4 +1,4 @@ -//@ build-fail +//@ build-pass //@ aux-crate: ambiguous_reachable_extern=ambiguous-reachable-extern.rs #![allow(ambiguous_glob_imports)] @@ -6,5 +6,3 @@ fn main() { ambiguous_reachable_extern::generic::(); } - -//~? ERROR missing optimized MIR diff --git a/tests/ui/imports/ambiguous-reachable.stderr b/tests/ui/imports/ambiguous-reachable.stderr index 5ba00970a23a0..d7adea9ee7f48 100644 --- a/tests/ui/imports/ambiguous-reachable.stderr +++ b/tests/ui/imports/ambiguous-reachable.stderr @@ -1,13 +1,3 @@ -error: missing optimized MIR for `ambiguous_reachable_extern::m1::generic::` in the crate `ambiguous_reachable_extern` - | -note: missing optimized MIR for this item (was the crate `ambiguous_reachable_extern` compiled with `--emit=metadata`?) - --> $DIR/auxiliary/ambiguous-reachable-extern.rs:2:5 - | -LL | pub fn generic() { - | ^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 1 previous error - Future incompatibility report: Future breakage diagnostic: warning: `generic` is ambiguous --> $DIR/ambiguous-reachable.rs:7:33