@@ -204,7 +204,10 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
204204 return Ok ( ( res, Some ( path_str. to_owned ( ) ) ) ) ;
205205 }
206206 other => {
207- debug ! ( "failed to resolve {} in namespace {:?} (got {:?})" , path_str, ns, other) ;
207+ debug ! (
208+ "failed to resolve {} in namespace {:?} (got {:?})" ,
209+ path_str, ns, other
210+ ) ;
208211 debug ! ( "extra_fragment is {:?}" , extra_fragment) ;
209212 return Ok ( ( res, extra_fragment. clone ( ) ) ) ;
210213 }
@@ -564,10 +567,9 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
564567 let mut path_str;
565568 let ( res, fragment) = {
566569 let mut kind = None ;
567- path_str = if let Some ( prefix) =
568- [ "struct@" , "enum@" , "type@" , "trait@" , "union@" ]
569- . iter ( )
570- . find ( |p| link. starts_with ( * * p) )
570+ path_str = if let Some ( prefix) = [ "struct@" , "enum@" , "type@" , "trait@" , "union@" ]
571+ . iter ( )
572+ . find ( |p| link. starts_with ( * * p) )
571573 {
572574 kind = Some ( TypeNS ) ;
573575 link. trim_start_matches ( prefix)
@@ -766,22 +768,30 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
766768 if let Res :: PrimTy ( _) = res {
767769 item. attrs . links . push ( ( ori_link, None , fragment) ) ;
768770 } else {
769- // ~~WRONG: TODO: I think this happens too late and we need to instead put this in `self.resolve`~~
770- debug ! ( "item {:?} resolved to {:?}" , item, res) ;
771+ debug ! ( "linked item {} resolved to {:?}" , path_str, res) ;
771772 if let Some ( local) = res. opt_def_id ( ) . and_then ( |def_id| def_id. as_local ( ) ) {
773+ use rustc_hir:: def_id:: LOCAL_CRATE ;
774+
772775 let hir_id = self . cx . tcx . hir ( ) . as_local_hir_id ( local) ;
773- if !self . cx . tcx . privacy_access_levels ( rustc_hir:: def_id:: LOCAL_CRATE ) . is_exported ( hir_id) {
776+ if !self . cx . tcx . privacy_access_levels ( LOCAL_CRATE ) . is_exported ( hir_id)
777+ && !self . cx . render_options . document_private
778+ {
774779 let item_name = item. name . as_deref ( ) . unwrap_or ( "<unknown>" ) ;
780+ let err_msg = format ! (
781+ "public documentation for `{}` links to a private item" ,
782+ item_name
783+ ) ;
775784 build_diagnostic (
776785 cx,
777786 & item,
778787 path_str,
779788 & dox,
780789 link_range,
781- & format ! ( "public documentation for `{}` links to a private item" , item_name ) ,
790+ & err_msg ,
782791 "this item is private" ,
783792 None ,
784793 ) ;
794+ continue ;
785795 }
786796 }
787797 let id = register_res ( cx, res) ;
0 commit comments