Remove doc comments only for private items or some specific doc comments
This commit is contained in:
parent
b12b65c1b7
commit
72d6fde130
@ -3,6 +3,7 @@
|
||||
use crate::rmeta::table::TableBuilder;
|
||||
use crate::rmeta::*;
|
||||
|
||||
use rustc_ast::Attribute;
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
|
||||
use rustc_data_structures::memmap::{Mmap, MmapMut};
|
||||
@ -764,6 +765,26 @@ macro_rules! stat {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn should_encode_attr(
|
||||
tcx: TyCtxt<'_>,
|
||||
attr: &Attribute,
|
||||
def_id: LocalDefId,
|
||||
is_def_id_public: &mut Option<bool>,
|
||||
) -> bool {
|
||||
if rustc_feature::is_builtin_only_local(attr.name_or_empty()) {
|
||||
false
|
||||
} else if attr.doc_str().is_some() {
|
||||
*is_def_id_public.get_or_insert_with(|| {
|
||||
tcx.privacy_access_levels(()).get_effective_vis(def_id).is_some()
|
||||
})
|
||||
} else if attr.has_name(sym::doc) {
|
||||
attr.meta_item_list().map(|l| l.iter().any(|l| !l.has_name(sym::inline))).unwrap_or(false)
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
fn should_encode_visibility(def_kind: DefKind) -> bool {
|
||||
match def_kind {
|
||||
DefKind::Mod
|
||||
@ -1126,12 +1147,14 @@ fn should_encode_trait_impl_trait_tys<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) ->
|
||||
|
||||
impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||
fn encode_attrs(&mut self, def_id: LocalDefId) {
|
||||
let mut attrs = self
|
||||
.tcx
|
||||
let tcx = self.tcx;
|
||||
let mut is_public: Option<bool> = None;
|
||||
|
||||
let mut attrs = tcx
|
||||
.hir()
|
||||
.attrs(self.tcx.hir().local_def_id_to_hir_id(def_id))
|
||||
.attrs(tcx.hir().local_def_id_to_hir_id(def_id))
|
||||
.iter()
|
||||
.filter(|attr| !rustc_feature::is_builtin_only_local(attr.name_or_empty()));
|
||||
.filter(move |attr| should_encode_attr(tcx, attr, def_id, &mut is_public));
|
||||
|
||||
record_array!(self.tables.attributes[def_id.to_def_id()] <- attrs.clone());
|
||||
if attrs.any(|attr| attr.may_have_doc_links()) {
|
||||
|
Loading…
Reference in New Issue
Block a user