@@ -3,6 +3,7 @@ use crate::rmeta::def_path_hash_map::DefPathHashMapRef;
3
3
use crate :: rmeta:: table:: TableBuilder ;
4
4
use crate :: rmeta:: * ;
5
5
6
+ use rustc_ast:: Attribute ;
6
7
use rustc_data_structures:: fingerprint:: Fingerprint ;
7
8
use rustc_data_structures:: fx:: { FxHashMap , FxIndexSet } ;
8
9
use rustc_data_structures:: memmap:: { Mmap , MmapMut } ;
@@ -764,6 +765,26 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
764
765
}
765
766
}
766
767
768
+ #[ inline]
769
+ fn should_encode_attr (
770
+ tcx : TyCtxt < ' _ > ,
771
+ attr : & Attribute ,
772
+ def_id : LocalDefId ,
773
+ is_def_id_public : & mut Option < bool > ,
774
+ ) -> bool {
775
+ if rustc_feature:: is_builtin_only_local ( attr. name_or_empty ( ) ) {
776
+ false
777
+ } else if attr. doc_str ( ) . is_some ( ) {
778
+ * is_def_id_public. get_or_insert_with ( || {
779
+ tcx. privacy_access_levels ( ( ) ) . get_effective_vis ( def_id) . is_some ( )
780
+ } )
781
+ } else if attr. has_name ( sym:: doc) {
782
+ attr. meta_item_list ( ) . map ( |l| l. iter ( ) . any ( |l| !l. has_name ( sym:: inline) ) ) . unwrap_or ( false )
783
+ } else {
784
+ true
785
+ }
786
+ }
787
+
767
788
fn should_encode_visibility ( def_kind : DefKind ) -> bool {
768
789
match def_kind {
769
790
DefKind :: Mod
@@ -1126,12 +1147,14 @@ fn should_encode_trait_impl_trait_tys<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) ->
1126
1147
1127
1148
impl < ' a , ' tcx > EncodeContext < ' a , ' tcx > {
1128
1149
fn encode_attrs ( & mut self , def_id : LocalDefId ) {
1129
- let mut attrs = self
1130
- . tcx
1150
+ let tcx = self . tcx ;
1151
+ let mut is_public: Option < bool > = None ;
1152
+
1153
+ let mut attrs = tcx
1131
1154
. hir ( )
1132
- . attrs ( self . tcx . hir ( ) . local_def_id_to_hir_id ( def_id) )
1155
+ . attrs ( tcx. hir ( ) . local_def_id_to_hir_id ( def_id) )
1133
1156
. iter ( )
1134
- . filter ( |attr| !rustc_feature :: is_builtin_only_local ( attr. name_or_empty ( ) ) ) ;
1157
+ . filter ( move |attr| should_encode_attr ( tcx , attr, def_id , & mut is_public ) ) ;
1135
1158
1136
1159
record_array ! ( self . tables. attributes[ def_id. to_def_id( ) ] <- attrs. clone( ) ) ;
1137
1160
if attrs. any ( |attr| attr. may_have_doc_links ( ) ) {
0 commit comments