From 006e0ef18ddd1f4f9de4d528369ebe8b564eb18d Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Wed, 20 Dec 2023 20:02:40 +0300 Subject: [PATCH] resolve: Stop feeding visibilities for import list stems --- compiler/rustc_resolve/src/build_reduced_graph.rs | 9 +++++++-- .../import-list-stem-visibility-issue-119126.rs | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 tests/ui/privacy/import-list-stem-visibility-issue-119126.rs diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index 7ff3c523685..98a9d0ba4c2 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -394,6 +394,7 @@ fn build_reduced_graph_for_use_tree( id: NodeId, parent_prefix: &[Segment], nested: bool, + list_stem: bool, // The whole `use` item item: &Item, vis: ty::Visibility, @@ -404,7 +405,9 @@ fn build_reduced_graph_for_use_tree( parent_prefix, use_tree, nested ); - if nested { + // Top level use tree reuses the item's id and list stems reuse their parent + // use tree's ids, so in both cases their visibilities are already filled. + if nested && !list_stem { self.r.feed_visibility(self.r.local_def_id(id), vis); } @@ -592,7 +595,7 @@ fn build_reduced_graph_for_use_tree( for &(ref tree, id) in items { self.build_reduced_graph_for_use_tree( // This particular use tree - tree, id, &prefix, true, // The whole `use` item + tree, id, &prefix, true, false, // The whole `use` item item, vis, root_span, ); } @@ -613,6 +616,7 @@ fn build_reduced_graph_for_use_tree( id, &prefix, true, + true, // The whole `use` item item, ty::Visibility::Restricted( @@ -648,6 +652,7 @@ fn build_reduced_graph_for_item(&mut self, item: &'b Item) { item.id, &[], false, + false, // The whole `use` item item, vis, diff --git a/tests/ui/privacy/import-list-stem-visibility-issue-119126.rs b/tests/ui/privacy/import-list-stem-visibility-issue-119126.rs new file mode 100644 index 00000000000..21f7828fc84 --- /dev/null +++ b/tests/ui/privacy/import-list-stem-visibility-issue-119126.rs @@ -0,0 +1,14 @@ +// check-pass +// edition: 2018 + +mod outer { + mod inner { + pub mod inner2 {} + } + pub(crate) use inner::{}; + pub(crate) use inner::{{}}; + pub(crate) use inner::{inner2::{}}; + pub(crate) use inner::{inner2::{{}}}; +} + +fn main() {}