Skip to content

Commit 6ada0d2

Browse files
committed
resolve: Mark items under ambigous imports as exported
1 parent f5046d5 commit 6ada0d2

File tree

5 files changed

+16
-45
lines changed

5 files changed

+16
-45
lines changed

compiler/rustc_resolve/src/effective_visibilities.rs

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,10 @@ impl<'a, 'ra, 'tcx> EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx> {
9696
// is the maximum value among visibilities of declarations corresponding to that def id.
9797
for (decl, eff_vis) in visitor.import_effective_visibilities.iter() {
9898
let DeclKind::Import { import, .. } = decl.kind else { unreachable!() };
99-
if !decl.is_ambiguity_recursive() {
100-
if let Some(node_id) = import.id() {
101-
r.effective_visibilities.update_eff_vis(r.local_def_id(node_id), eff_vis, r.tcx)
102-
}
103-
} else if decl.ambiguity.get().is_some()
104-
&& eff_vis.is_public_at_level(Level::Reexported)
105-
{
99+
if let Some(node_id) = import.id() {
100+
r.effective_visibilities.update_eff_vis(r.local_def_id(node_id), eff_vis, r.tcx)
101+
}
102+
if decl.ambiguity.get().is_some() && eff_vis.is_public_at_level(Level::Reexported) {
106103
exported_ambiguities.insert(*decl);
107104
}
108105
}
@@ -123,31 +120,13 @@ impl<'a, 'ra, 'tcx> EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx> {
123120
// Set the given effective visibility level to `Level::Direct` and
124121
// sets the rest of the `use` chain to `Level::Reexported` until
125122
// we hit the actual exported item.
126-
//
127-
// If the binding is ambiguous, put the root ambiguity binding and all reexports
128-
// leading to it into the table. They are used by the `ambiguous_glob_reexports`
129-
// lint. For all bindings added to the table this way `is_ambiguity` returns true.
130-
let is_ambiguity =
131-
|decl: Decl<'ra>, warn: bool| decl.ambiguity.get().is_some() && !warn;
132123
let mut parent_id = ParentId::Def(module_id);
133-
let mut warn_ambiguity = decl.warn_ambiguity.get();
134124
while let DeclKind::Import { source_decl, .. } = decl.kind {
135125
self.update_import(decl, parent_id);
136-
137-
if is_ambiguity(decl, warn_ambiguity) {
138-
// Stop at the root ambiguity, further bindings in the chain should not
139-
// be reexported because the root ambiguity blocks any access to them.
140-
// (Those further bindings are most likely not ambiguities themselves.)
141-
break;
142-
}
143-
144126
parent_id = ParentId::Import(decl);
145127
decl = source_decl;
146-
warn_ambiguity |= source_decl.warn_ambiguity.get();
147128
}
148-
if !is_ambiguity(decl, warn_ambiguity)
149-
&& let Some(def_id) = decl.res().opt_def_id().and_then(|id| id.as_local())
150-
{
129+
if let Some(def_id) = decl.res().opt_def_id().and_then(|id| id.as_local()) {
151130
self.update_def(def_id, decl.vis().expect_local(), parent_id);
152131
}
153132
}

tests/rustdoc-html/glob-shadowing.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//@ has 'glob_shadowing/index.html'
2-
//@ count - '//dt' 6
3-
//@ !has - '//dd' 'sub1::describe'
2+
//@ count - '//dt' 7
3+
//@ !has - '//dd' 'sub1::describe1'
44
//@ has - '//dd' 'sub2::describe'
55

6-
//@ !has - '//dd' 'sub1::describe2'
6+
//@ has - '//dd' 'sub1::describe2'
77

88
//@ !has - '//dd' 'sub1::prelude'
99
//@ has - '//dd' 'mod::prelude'
@@ -18,7 +18,7 @@
1818

1919
mod sub1 {
2020
// this should be shadowed by sub2::describe
21-
/// sub1::describe
21+
/// sub1::describe1
2222
pub fn describe() -> &'static str {
2323
"sub1::describe"
2424
}
@@ -33,7 +33,9 @@ mod sub1 {
3333
pub struct Foo;
3434

3535
// this should be shadowed,
36-
// because both sub1::describe2 and sub3::describe2 are from glob reexport
36+
// because both sub1::describe2 and sub3::describe2 are from glob reexport,
37+
// but it is still usable from other crates under the `ambiguous_glob_imports` lint,
38+
// so it is reachable and documented
3739
/// sub1::describe2
3840
pub fn describe2() -> &'static str {
3941
"sub1::describe2"

tests/rustdoc-json/reexport/glob_collision.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Regression test for https://github.com/rust-lang/rust/issues/100973
2+
// Update: the rules has changed after #147984, one of the colliding items is now available
3+
// from other crates under a deprecation lint.
24

35
//@ set m1 = "$.index[?(@.name == 'm1' && @.inner.module)].id"
4-
//@ is "$.index[?(@.name == 'm1')].inner.module.items" []
6+
//@ is "$.index[?(@.name == 'm1')].inner.module.items" [0]
57
//@ is "$.index[?(@.name == 'm1')].inner.module.is_stripped" true
68
mod m1 {
79
pub fn f() {}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
//@ build-fail
1+
//@ build-pass
22
//@ aux-crate: ambiguous_reachable_extern=ambiguous-reachable-extern.rs
33

44
#![allow(ambiguous_glob_imports)]
55

66
fn main() {
77
ambiguous_reachable_extern::generic::<u8>();
88
}
9-
10-
//~? ERROR missing optimized MIR

tests/ui/imports/ambiguous-reachable.stderr

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
error: missing optimized MIR for `ambiguous_reachable_extern::m1::generic::<u8>` in the crate `ambiguous_reachable_extern`
2-
|
3-
note: missing optimized MIR for this item (was the crate `ambiguous_reachable_extern` compiled with `--emit=metadata`?)
4-
--> $DIR/auxiliary/ambiguous-reachable-extern.rs:2:5
5-
|
6-
LL | pub fn generic<T>() {
7-
| ^^^^^^^^^^^^^^^^^^^
8-
9-
error: aborting due to 1 previous error
10-
111
Future incompatibility report: Future breakage diagnostic:
122
warning: `generic` is ambiguous
133
--> $DIR/ambiguous-reachable.rs:7:33

0 commit comments

Comments
 (0)