Skip to content

Commit 66f2439

Browse files
committed
Feed visibilities for import stems and opaque types too
1 parent 6a1770d commit 66f2439

File tree

3 files changed

+14
-21
lines changed

3 files changed

+14
-21
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ use rustc_hir::{ConstArg, GenericArg, ItemLocalId, ParamName, TraitCandidate};
6262
use rustc_index::{Idx, IndexSlice, IndexVec};
6363
use rustc_middle::{
6464
span_bug,
65-
ty::{ResolverAstLowering, TyCtxt},
65+
ty::{ResolverAstLowering, TyCtxt, Visibility},
6666
};
6767
use rustc_session::parse::{add_feature_diagnostics, feature_err};
6868
use rustc_span::symbol::{kw, sym, Ident, Symbol};
@@ -1624,6 +1624,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16241624
);
16251625
debug!(?opaque_ty_def_id);
16261626

1627+
// Meaningless, but provided so that all items have visibilities.
1628+
let parent_mod = self.tcx.parent_module_from_def_id(opaque_ty_def_id).to_def_id();
1629+
self.tcx.feed_local_def_id(opaque_ty_def_id).visibility(Visibility::Restricted(parent_mod));
1630+
16271631
// Map from captured (old) lifetime to synthetic (new) lifetime.
16281632
// Used to resolve lifetimes in the bounds of the opaque.
16291633
let mut captured_to_synthesized_mapping = FxHashMap::default();

compiler/rustc_privacy/src/lib.rs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,25 +1774,12 @@ pub fn provide(providers: &mut Providers) {
17741774
}
17751775

17761776
fn visibility(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Visibility<DefId> {
1777-
local_visibility(tcx, def_id).to_def_id()
1778-
}
1779-
1780-
fn local_visibility(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Visibility {
1781-
let hir_id = tcx.local_def_id_to_hir_id(def_id);
1782-
match tcx.hir().get(hir_id) {
1777+
match tcx.hir().get_by_def_id(def_id) {
17831778
// Unique types created for closures participate in type privacy checking.
17841779
// They have visibilities inherited from the module they are defined in.
1785-
Node::Expr(hir::Expr { kind: hir::ExprKind::Closure{..}, .. })
1786-
// - AST lowering creates dummy `use` items which don't
1787-
// get their entries in the resolver's visibility table.
1788-
// - AST lowering also creates opaque type items with inherited visibilities.
1789-
// Visibility on them should have no effect, but to avoid the visibility
1790-
// query failing on some items, we provide it for opaque types as well.
1791-
| Node::Item(hir::Item {
1792-
kind: hir::ItemKind::Use(_, hir::UseKind::ListStem)
1793-
| hir::ItemKind::OpaqueTy(..),
1794-
..
1795-
}) => ty::Visibility::Restricted(tcx.parent_module(hir_id).to_local_def_id()),
1780+
Node::Expr(hir::Expr { kind: hir::ExprKind::Closure { .. }, .. }) => {
1781+
ty::Visibility::Restricted(tcx.parent_module_from_def_id(def_id).to_def_id())
1782+
}
17961783
_ => span_bug!(
17971784
tcx.def_span(def_id),
17981785
"visibility table unexpectedly missing a def-id: {:?}",

compiler/rustc_resolve/src/build_reduced_graph.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,10 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
399399
parent_prefix, use_tree, nested
400400
);
401401

402+
if nested {
403+
self.r.feed_visibility(self.r.local_def_id(id), vis);
404+
}
405+
402406
let mut prefix_iter = parent_prefix
403407
.iter()
404408
.cloned()
@@ -437,8 +441,6 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
437441
let mut source = module_path.pop().unwrap();
438442
let mut type_ns_only = false;
439443

440-
self.r.feed_visibility(self.r.local_def_id(id), vis);
441-
442444
if nested {
443445
// Correctly handle `self`
444446
if source.ident.name == kw::SelfLower {
@@ -552,7 +554,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
552554
max_vis: Cell::new(None),
553555
id,
554556
};
555-
self.r.feed_visibility(self.r.local_def_id(id), vis);
557+
556558
self.add_import(prefix, kind, use_tree.span, item, root_span, item.id, vis);
557559
}
558560
ast::UseTreeKind::Nested(ref items) => {

0 commit comments

Comments
 (0)