@@ -15,8 +15,8 @@ use rustc_hir::def_id::{DefId, CRATE_DEF_ID};
1515use rustc_hir:: Mutability ;
1616use rustc_middle:: ty:: { fast_reject:: TreatProjections , Ty , TyCtxt } ;
1717use 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 } ;
2020use rustc_session:: lint:: Lint ;
2121use rustc_span:: hygiene:: MacroKind ;
2222use rustc_span:: symbol:: { sym, Ident , Symbol } ;
@@ -899,6 +899,15 @@ fn preprocessed_markdown_links(s: &str) -> Vec<PreprocessedMarkdownLink> {
899899
900900impl LinkCollector < ' _ , ' _ > {
901901 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+
902911 // We want to resolve in the lexical scope of the documentation.
903912 // In the presence of re-exports, this is not the same as the module of the item.
904913 // Rather than merging all documentation into one, resolve it one attribute at a time
0 commit comments