@@ -15,8 +15,8 @@ use rustc_hir::def_id::{DefId, CRATE_DEF_ID};
15
15
use rustc_hir:: Mutability ;
16
16
use rustc_middle:: ty:: { fast_reject:: TreatProjections , Ty , TyCtxt } ;
17
17
use rustc_middle:: { bug, ty} ;
18
- use rustc_resolve:: rustdoc:: MalformedGenerics ;
19
- use rustc_resolve:: rustdoc:: { prepare_to_doc_link_resolution , strip_generics_from_path } ;
18
+ use rustc_resolve:: rustdoc:: { has_primitive_or_keyword_docs , prepare_to_doc_link_resolution } ;
19
+ use rustc_resolve:: rustdoc:: { strip_generics_from_path , MalformedGenerics } ;
20
20
use rustc_session:: lint:: Lint ;
21
21
use rustc_span:: hygiene:: MacroKind ;
22
22
use rustc_span:: symbol:: { sym, Ident , Symbol } ;
@@ -899,6 +899,15 @@ fn preprocessed_markdown_links(s: &str) -> Vec<PreprocessedMarkdownLink> {
899
899
900
900
impl LinkCollector < ' _ , ' _ > {
901
901
fn resolve_links ( & mut self , item : & Item ) {
902
+ if !self . cx . render_options . document_private
903
+ && let Some ( def_id) = item. item_id . as_def_id ( )
904
+ && let Some ( def_id) = def_id. as_local ( )
905
+ && !self . cx . tcx . effective_visibilities ( ( ) ) . is_exported ( def_id)
906
+ && !has_primitive_or_keyword_docs ( & item. attrs . other_attrs ) {
907
+ // Skip link resolution for non-exported items.
908
+ return ;
909
+ }
910
+
902
911
// We want to resolve in the lexical scope of the documentation.
903
912
// In the presence of re-exports, this is not the same as the module of the item.
904
913
// Rather than merging all documentation into one, resolve it one attribute at a time
0 commit comments