Skip to content

Commit cc0952f

Browse files
committed
resolve: Mark items under ambigous imports as exported
1 parent 7dc430e commit cc0952f

5 files changed

Lines changed: 16 additions & 43 deletions

File tree

compiler/rustc_resolve/src/effective_visibilities.rs

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,10 @@ impl<'a, 'ra, 'tcx> EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx> {
9696
// is the maximum value among visibilities of bindings corresponding to that def id.
9797
for (binding, eff_vis) in visitor.import_effective_visibilities.iter() {
9898
let NameBindingKind::Import { import, .. } = binding.kind else { unreachable!() };
99-
if !binding.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 binding.ambiguity.is_some() && eff_vis.is_public_at_level(Level::Reexported) {
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 binding.ambiguity.is_some() && eff_vis.is_public_at_level(Level::Reexported) {
104103
exported_ambiguities.insert(*binding);
105104
}
106105
}
@@ -121,31 +120,13 @@ impl<'a, 'ra, 'tcx> EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx> {
121120
// Set the given effective visibility level to `Level::Direct` and
122121
// sets the rest of the `use` chain to `Level::Reexported` until
123122
// we hit the actual exported item.
124-
//
125-
// If the binding is ambiguous, put the root ambiguity binding and all reexports
126-
// leading to it into the table. They are used by the `ambiguous_glob_reexports`
127-
// lint. For all bindings added to the table this way `is_ambiguity` returns true.
128-
let is_ambiguity =
129-
|binding: NameBinding<'ra>, warn: bool| binding.ambiguity.is_some() && !warn;
130123
let mut parent_id = ParentId::Def(module_id);
131-
let mut warn_ambiguity = binding.warn_ambiguity;
132124
while let NameBindingKind::Import { binding: nested_binding, .. } = binding.kind {
133125
self.update_import(binding, parent_id);
134-
135-
if is_ambiguity(binding, warn_ambiguity) {
136-
// Stop at the root ambiguity, further bindings in the chain should not
137-
// be reexported because the root ambiguity blocks any access to them.
138-
// (Those further bindings are most likely not ambiguities themselves.)
139-
break;
140-
}
141-
142126
parent_id = ParentId::Import(binding);
143127
binding = nested_binding;
144-
warn_ambiguity |= nested_binding.warn_ambiguity;
145128
}
146-
if !is_ambiguity(binding, warn_ambiguity)
147-
&& let Some(def_id) = binding.res().opt_def_id().and_then(|id| id.as_local())
148-
{
129+
if let Some(def_id) = binding.res().opt_def_id().and_then(|id| id.as_local()) {
149130
self.update_def(def_id, binding.vis.expect_local(), parent_id);
150131
}
151132
}

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() {}

tests/rustdoc/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"
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)