Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit f1bf6d0

Browse files
committed
Iterate DefId to encode visibility.
1 parent a185cdb commit f1bf6d0

File tree

1 file changed

+38
-10
lines changed

1 file changed

+38
-10
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,41 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
716716
}
717717
}
718718

719+
fn should_encode_visibility(def_kind: DefKind) -> bool {
720+
match def_kind {
721+
DefKind::Mod
722+
| DefKind::Struct
723+
| DefKind::Union
724+
| DefKind::Enum
725+
| DefKind::Variant
726+
| DefKind::Trait
727+
| DefKind::TyAlias
728+
| DefKind::ForeignTy
729+
| DefKind::TraitAlias
730+
| DefKind::AssocTy
731+
| DefKind::Fn
732+
| DefKind::Const
733+
| DefKind::Static
734+
| DefKind::Ctor(..)
735+
| DefKind::AssocFn
736+
| DefKind::AssocConst
737+
| DefKind::Macro(..)
738+
| DefKind::Use
739+
| DefKind::ForeignMod
740+
| DefKind::OpaqueTy
741+
| DefKind::Impl
742+
| DefKind::Field => true,
743+
DefKind::TyParam
744+
| DefKind::ConstParam
745+
| DefKind::LifetimeParam
746+
| DefKind::AnonConst
747+
| DefKind::GlobalAsm
748+
| DefKind::Closure
749+
| DefKind::Generator
750+
| DefKind::ExternCrate => false,
751+
}
752+
}
753+
719754
impl EncodeContext<'a, 'tcx> {
720755
fn encode_def_ids(&mut self) {
721756
if self.is_proc_macro {
@@ -734,6 +769,9 @@ impl EncodeContext<'a, 'tcx> {
734769
def_kind => def_kind,
735770
});
736771
record!(self.tables.span[def_id] <- tcx.def_span(def_id));
772+
if should_encode_visibility(def_kind) {
773+
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
774+
}
737775
}
738776
}
739777

@@ -761,7 +799,6 @@ impl EncodeContext<'a, 'tcx> {
761799
};
762800

763801
record!(self.tables.kind[def_id] <- EntryKind::Variant(self.lazy(data)));
764-
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
765802
record!(self.tables.attributes[def_id] <- &self.tcx.get_attrs(def_id)[..]);
766803
record!(self.tables.expn_that_defined[def_id] <- self.tcx.expansion_that_defined(def_id));
767804
record!(self.tables.children[def_id] <- variant.fields.iter().map(|f| {
@@ -800,7 +837,6 @@ impl EncodeContext<'a, 'tcx> {
800837
};
801838

802839
record!(self.tables.kind[def_id] <- EntryKind::Variant(self.lazy(data)));
803-
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
804840
self.encode_stability(def_id);
805841
self.encode_deprecation(def_id);
806842
self.encode_item_type(def_id);
@@ -851,7 +887,6 @@ impl EncodeContext<'a, 'tcx> {
851887
};
852888

853889
record!(self.tables.kind[def_id] <- EntryKind::Mod(self.lazy(data)));
854-
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
855890
record!(self.tables.attributes[def_id] <- attrs);
856891
if self.is_proc_macro {
857892
record!(self.tables.children[def_id] <- &[]);
@@ -881,7 +916,6 @@ impl EncodeContext<'a, 'tcx> {
881916
let variant_data = tcx.hir().expect_variant_data(variant_id);
882917

883918
record!(self.tables.kind[def_id] <- EntryKind::Field);
884-
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
885919
record!(self.tables.attributes[def_id] <- variant_data.fields()[field_index].attrs);
886920
record!(self.tables.expn_that_defined[def_id] <- self.tcx.expansion_that_defined(def_id));
887921
self.encode_ident_span(def_id, field.ident);
@@ -906,7 +940,6 @@ impl EncodeContext<'a, 'tcx> {
906940
};
907941

908942
record!(self.tables.kind[def_id] <- EntryKind::Struct(self.lazy(data), adt_def.repr));
909-
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
910943
record!(self.tables.expn_that_defined[def_id] <- self.tcx.expansion_that_defined(def_id));
911944
self.encode_stability(def_id);
912945
self.encode_deprecation(def_id);
@@ -1010,7 +1043,6 @@ impl EncodeContext<'a, 'tcx> {
10101043
record!(self.tables.kind[def_id] <- EntryKind::AssocType(container));
10111044
}
10121045
}
1013-
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
10141046
record!(self.tables.attributes[def_id] <- ast_item.attrs);
10151047
self.encode_ident_span(def_id, ast_item.ident);
10161048
self.encode_stability(def_id);
@@ -1113,7 +1145,6 @@ impl EncodeContext<'a, 'tcx> {
11131145
record!(self.tables.kind[def_id] <- EntryKind::AssocType(container));
11141146
}
11151147
}
1116-
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
11171148
record!(self.tables.attributes[def_id] <- ast_item.attrs);
11181149
self.encode_ident_span(def_id, impl_item.ident);
11191150
self.encode_stability(def_id);
@@ -1358,7 +1389,6 @@ impl EncodeContext<'a, 'tcx> {
13581389
}
13591390
};
13601391
record!(self.tables.kind[def_id] <- entry_kind);
1361-
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
13621392
record!(self.tables.attributes[def_id] <- item.attrs);
13631393
record!(self.tables.expn_that_defined[def_id] <- self.tcx.expansion_that_defined(def_id));
13641394
// FIXME(eddyb) there should be a nicer way to do this.
@@ -1477,7 +1507,6 @@ impl EncodeContext<'a, 'tcx> {
14771507
fn encode_info_for_macro_def(&mut self, macro_def: &hir::MacroDef<'_>) {
14781508
let def_id = self.tcx.hir().local_def_id(macro_def.hir_id).to_def_id();
14791509
record!(self.tables.kind[def_id] <- EntryKind::MacroDef(self.lazy(macro_def.ast.clone())));
1480-
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
14811510
record!(self.tables.attributes[def_id] <- macro_def.attrs);
14821511
self.encode_ident_span(def_id, macro_def.ident);
14831512
self.encode_stability(def_id);
@@ -1808,7 +1837,6 @@ impl EncodeContext<'a, 'tcx> {
18081837
record!(self.tables.kind[def_id] <- EntryKind::ForeignType);
18091838
}
18101839
}
1811-
record!(self.tables.visibility[def_id] <- self.tcx.visibility(def_id));
18121840
record!(self.tables.attributes[def_id] <- nitem.attrs);
18131841
self.encode_ident_span(def_id, nitem.ident);
18141842
self.encode_stability(def_id);

0 commit comments

Comments
 (0)