@@ -28,7 +28,7 @@ use rustc_span::symbol::sym;
2828use tracing:: { debug, info} ;
2929
3030use crate :: clean:: inline:: build_trait;
31- use crate :: clean:: { self , ItemId } ;
31+ use crate :: clean:: { self , ItemId , NestedAttributesExt } ;
3232use crate :: config:: { Options as RustdocOptions , OutputFormat , RenderOptions } ;
3333use crate :: formats:: cache:: Cache ;
3434use crate :: html:: macro_expansion:: { ExpandedCode , source_macro_expansion} ;
@@ -61,8 +61,6 @@ pub(crate) struct DocContext<'tcx> {
6161 // FIXME(eddyb) make this a `ty::TraitRef<'tcx>` set.
6262 pub ( crate ) generated_synthetics : FxHashSet < ( Ty < ' tcx > , DefId ) > ,
6363 pub ( crate ) auto_traits : Vec < DefId > ,
64- /// The options given to rustdoc that could be relevant to a pass.
65- pub ( crate ) render_options : RenderOptions ,
6664 /// This same cache is used throughout rustdoc, including in [`crate::html::render`].
6765 pub ( crate ) cache : Cache ,
6866 /// Used by [`clean::inline`] to tell if an item has already been inlined.
@@ -138,6 +136,16 @@ impl<'tcx> DocContext<'tcx> {
138136 pub ( crate ) fn is_json_output ( & self ) -> bool {
139137 self . output_format . is_json ( ) && !self . show_coverage
140138 }
139+
140+ /// If `--document-private-items` was passed to rustdoc.
141+ pub ( crate ) fn document_private ( & self ) -> bool {
142+ self . cache . document_private
143+ }
144+
145+ /// If `--document-hidden-items` was passed to rustdoc.
146+ pub ( crate ) fn document_hidden ( & self ) -> bool {
147+ self . cache . document_hidden
148+ }
141149}
142150
143151/// Creates a new `DiagCtxt` that can be used to emit warnings and errors.
@@ -328,7 +336,7 @@ pub(crate) fn create_config(
328336pub ( crate ) fn run_global_ctxt (
329337 tcx : TyCtxt < ' _ > ,
330338 show_coverage : bool ,
331- render_options : RenderOptions ,
339+ mut render_options : RenderOptions ,
332340 output_format : OutputFormat ,
333341) -> ( clean:: Crate , RenderOptions , Cache , FxHashMap < rustc_span:: BytePos , Vec < ExpandedCode > > ) {
334342 // Certain queries assume that some checks were run elsewhere
@@ -361,6 +369,13 @@ pub(crate) fn run_global_ctxt(
361369 let auto_traits =
362370 tcx. visible_traits ( ) . filter ( |& trait_def_id| tcx. trait_is_auto ( trait_def_id) ) . collect ( ) ;
363371
372+ // Remnence of processing crate attributes for passes to run.
373+ if clean:: hir_attr_lists ( tcx. get_all_attrs ( rustc_hir:: def_id:: CRATE_DEF_ID ) , sym:: doc)
374+ . has_word ( sym:: document_private_items)
375+ {
376+ render_options. document_private = true ;
377+ }
378+
364379 let mut ctxt = DocContext {
365380 tcx,
366381 param_env : ParamEnv :: empty ( ) ,
@@ -374,7 +389,6 @@ pub(crate) fn run_global_ctxt(
374389 cache : Cache :: new ( render_options. document_private , render_options. document_hidden ) ,
375390 inlined : FxHashSet :: default ( ) ,
376391 output_format,
377- render_options,
378392 show_coverage,
379393 } ;
380394
@@ -411,14 +425,6 @@ pub(crate) fn run_global_ctxt(
411425 ) ;
412426 }
413427
414- // Process all of the crate attributes, extracting plugin metadata along
415- // with the passes which we are supposed to run.
416- for attr in krate. module . attrs . lists ( sym:: doc) {
417- if attr. is_word ( ) && attr. has_name ( sym:: document_private_items) {
418- ctxt. render_options . document_private = true ;
419- }
420- }
421-
422428 info ! ( "Executing passes" ) ;
423429
424430 let mut visited = FxHashMap :: default ( ) ;
@@ -427,9 +433,9 @@ pub(crate) fn run_global_ctxt(
427433 for p in passes:: defaults ( show_coverage) {
428434 let run = match p. condition {
429435 Always => true ,
430- WhenDocumentPrivate => ctxt. render_options . document_private ,
431- WhenNotDocumentPrivate => !ctxt. render_options . document_private ,
432- WhenNotDocumentHidden => !ctxt. render_options . document_hidden ,
436+ WhenDocumentPrivate => ctxt. document_private ( ) ,
437+ WhenNotDocumentPrivate => !ctxt. document_private ( ) ,
438+ WhenNotDocumentHidden => !ctxt. document_hidden ( ) ,
433439 } ;
434440 if run {
435441 debug ! ( "running pass {}" , p. pass. name) ;
@@ -447,15 +453,16 @@ pub(crate) fn run_global_ctxt(
447453
448454 tcx. sess . time ( "check_lint_expectations" , || tcx. check_expectations ( Some ( sym:: rustdoc) ) ) ;
449455
450- krate = tcx. sess . time ( "create_format_cache" , || Cache :: populate ( & mut ctxt, krate) ) ;
456+ krate =
457+ tcx. sess . time ( "create_format_cache" , || Cache :: populate ( & mut ctxt, krate, & render_options) ) ;
451458
452459 let mut collector =
453460 LinkCollector { cx : & mut ctxt, visited_links : visited, ambiguous_links : ambiguous } ;
454461 collector. resolve_ambiguities ( ) ;
455462
456463 tcx. dcx ( ) . abort_if_errors ( ) ;
457464
458- ( krate, ctxt . render_options , ctxt. cache , expanded_macros)
465+ ( krate, render_options, ctxt. cache , expanded_macros)
459466}
460467
461468/// Due to <https://github.com/rust-lang/rust/pull/73566>,
0 commit comments