@@ -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.
@@ -333,7 +341,7 @@ pub(crate) fn create_config(
333341pub ( crate ) fn run_global_ctxt (
334342 tcx : TyCtxt < ' _ > ,
335343 show_coverage : bool ,
336- render_options : RenderOptions ,
344+ mut render_options : RenderOptions ,
337345 output_format : OutputFormat ,
338346) -> ( clean:: Crate , RenderOptions , Cache , FxHashMap < rustc_span:: BytePos , Vec < ExpandedCode > > ) {
339347 // Certain queries assume that some checks were run elsewhere
@@ -366,6 +374,14 @@ pub(crate) fn run_global_ctxt(
366374 let auto_traits =
367375 tcx. visible_traits ( ) . filter ( |& trait_def_id| tcx. trait_is_auto ( trait_def_id) ) . collect ( ) ;
368376
377+ // Remnence of processing crate attributes for passes to run.
378+ // To be removed in https://github.com/rust-lang/rust/pull/146495.
379+ if clean:: hir_attr_lists ( tcx. get_all_attrs ( rustc_hir:: def_id:: CRATE_DEF_ID ) , sym:: doc)
380+ . has_word ( sym:: document_private_items)
381+ {
382+ render_options. document_private = true ;
383+ }
384+
369385 let mut ctxt = DocContext {
370386 tcx,
371387 param_env : ParamEnv :: empty ( ) ,
@@ -379,7 +395,6 @@ pub(crate) fn run_global_ctxt(
379395 cache : Cache :: new ( render_options. document_private , render_options. document_hidden ) ,
380396 inlined : FxHashSet :: default ( ) ,
381397 output_format,
382- render_options,
383398 show_coverage,
384399 } ;
385400
@@ -416,14 +431,6 @@ pub(crate) fn run_global_ctxt(
416431 ) ;
417432 }
418433
419- // Process all of the crate attributes, extracting plugin metadata along
420- // with the passes which we are supposed to run.
421- for attr in krate. module . attrs . lists ( sym:: doc) {
422- if attr. is_word ( ) && attr. has_name ( sym:: document_private_items) {
423- ctxt. render_options . document_private = true ;
424- }
425- }
426-
427434 info ! ( "Executing passes" ) ;
428435
429436 let mut visited = FxHashMap :: default ( ) ;
@@ -432,9 +439,9 @@ pub(crate) fn run_global_ctxt(
432439 for p in passes:: defaults ( show_coverage) {
433440 let run = match p. condition {
434441 Always => true ,
435- WhenDocumentPrivate => ctxt. render_options . document_private ,
436- WhenNotDocumentPrivate => !ctxt. render_options . document_private ,
437- WhenNotDocumentHidden => !ctxt. render_options . document_hidden ,
442+ WhenDocumentPrivate => ctxt. document_private ( ) ,
443+ WhenNotDocumentPrivate => !ctxt. document_private ( ) ,
444+ WhenNotDocumentHidden => !ctxt. document_hidden ( ) ,
438445 } ;
439446 if run {
440447 debug ! ( "running pass {}" , p. pass. name) ;
@@ -452,15 +459,16 @@ pub(crate) fn run_global_ctxt(
452459
453460 tcx. sess . time ( "check_lint_expectations" , || tcx. check_expectations ( Some ( sym:: rustdoc) ) ) ;
454461
455- krate = tcx. sess . time ( "create_format_cache" , || Cache :: populate ( & mut ctxt, krate) ) ;
462+ krate =
463+ tcx. sess . time ( "create_format_cache" , || Cache :: populate ( & mut ctxt, krate, & render_options) ) ;
456464
457465 let mut collector =
458466 LinkCollector { cx : & mut ctxt, visited_links : visited, ambiguous_links : ambiguous } ;
459467 collector. resolve_ambiguities ( ) ;
460468
461469 tcx. dcx ( ) . abort_if_errors ( ) ;
462470
463- ( krate, ctxt . render_options , ctxt. cache , expanded_macros)
471+ ( krate, render_options, ctxt. cache , expanded_macros)
464472}
465473
466474/// Due to <https://github.com/rust-lang/rust/pull/73566>,
0 commit comments