Skip to content

Commit 425c517

Browse files
committed
rustdoc: factor out duplicate code for checking if a DefId is public
1 parent 2e99f5f commit 425c517

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

Diff for: src/librustdoc/clean/inline.rs

+16-14
Original file line numberDiff line numberDiff line change
@@ -380,23 +380,29 @@ pub(crate) fn build_impl(
380380
let associated_trait = tcx.impl_trait_ref(did);
381381

382382
// Do not inline compiler-internal items unless we're a compiler-internal crate.
383-
let document_compiler_internal =
384-
if let Some(stab) = tcx.lookup_stability(LOCAL_CRATE.as_def_id()) {
383+
let is_compiler_internal = |did| {
384+
if let Some(stab) = tcx.lookup_stability(did) {
385385
stab.is_unstable() && stab.feature == sym::rustc_private
386386
} else {
387387
false
388-
};
388+
}
389+
};
390+
let document_compiler_internal = is_compiler_internal(LOCAL_CRATE.as_def_id());
391+
let is_directly_public = |cx: &mut DocContext<'_>, did| {
392+
if !cx.cache.effective_visibilities.is_directly_public(tcx, did) {
393+
return false;
394+
}
395+
if !document_compiler_internal && is_compiler_internal(did) {
396+
return false;
397+
}
398+
true
399+
};
389400

390401
// Only inline impl if the implemented trait is
391402
// reachable in rustdoc generated documentation
392403
if !did.is_local() {
393404
if let Some(traitref) = associated_trait {
394-
let did = traitref.def_id;
395-
if !cx.cache.effective_visibilities.is_directly_public(tcx, did) {
396-
return;
397-
}
398-
399-
if !document_compiler_internal && let Some(stab) = tcx.lookup_stability(did) && stab.is_unstable() && stab.feature == sym::rustc_private {
405+
if !is_directly_public(cx, traitref.def_id) {
400406
return;
401407
}
402408
}
@@ -419,11 +425,7 @@ pub(crate) fn build_impl(
419425
// reachable in rustdoc generated documentation
420426
if !did.is_local() {
421427
if let Some(did) = for_.def_id(&cx.cache) {
422-
if !cx.cache.effective_visibilities.is_directly_public(tcx, did) {
423-
return;
424-
}
425-
426-
if !document_compiler_internal && let Some(stab) = tcx.lookup_stability(did) && stab.is_unstable() && stab.feature == sym::rustc_private {
428+
if !is_directly_public(cx, did) {
427429
return;
428430
}
429431
}

0 commit comments

Comments
 (0)