@@ -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,14 @@ 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+ // To be removed in https://github.com/rust-lang/rust/pull/146495.
374+ if clean:: hir_attr_lists ( tcx. get_all_attrs ( rustc_hir:: def_id:: CRATE_DEF_ID ) , sym:: doc)
375+ . has_word ( sym:: document_private_items)
376+ {
377+ render_options. document_private = true ;
378+ }
379+
364380 let mut ctxt = DocContext {
365381 tcx,
366382 param_env : ParamEnv :: empty ( ) ,
@@ -374,7 +390,6 @@ pub(crate) fn run_global_ctxt(
374390 cache : Cache :: new ( render_options. document_private , render_options. document_hidden ) ,
375391 inlined : FxHashSet :: default ( ) ,
376392 output_format,
377- render_options,
378393 show_coverage,
379394 } ;
380395
@@ -411,14 +426,6 @@ pub(crate) fn run_global_ctxt(
411426 ) ;
412427 }
413428
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-
422429 info ! ( "Executing passes" ) ;
423430
424431 let mut visited = FxHashMap :: default ( ) ;
@@ -427,9 +434,9 @@ pub(crate) fn run_global_ctxt(
427434 for p in passes:: defaults ( show_coverage) {
428435 let run = match p. condition {
429436 Always => true ,
430- WhenDocumentPrivate => ctxt. render_options . document_private ,
431- WhenNotDocumentPrivate => !ctxt. render_options . document_private ,
432- WhenNotDocumentHidden => !ctxt. render_options . document_hidden ,
437+ WhenDocumentPrivate => ctxt. document_private ( ) ,
438+ WhenNotDocumentPrivate => !ctxt. document_private ( ) ,
439+ WhenNotDocumentHidden => !ctxt. document_hidden ( ) ,
433440 } ;
434441 if run {
435442 debug ! ( "running pass {}" , p. pass. name) ;
@@ -447,15 +454,16 @@ pub(crate) fn run_global_ctxt(
447454
448455 tcx. sess . time ( "check_lint_expectations" , || tcx. check_expectations ( Some ( sym:: rustdoc) ) ) ;
449456
450- krate = tcx. sess . time ( "create_format_cache" , || Cache :: populate ( & mut ctxt, krate) ) ;
457+ krate =
458+ tcx. sess . time ( "create_format_cache" , || Cache :: populate ( & mut ctxt, krate, & render_options) ) ;
451459
452460 let mut collector =
453461 LinkCollector { cx : & mut ctxt, visited_links : visited, ambiguous_links : ambiguous } ;
454462 collector. resolve_ambiguities ( ) ;
455463
456464 tcx. dcx ( ) . abort_if_errors ( ) ;
457465
458- ( krate, ctxt . render_options , ctxt. cache , expanded_macros)
466+ ( krate, render_options, ctxt. cache , expanded_macros)
459467}
460468
461469/// Due to <https://github.com/rust-lang/rust/pull/73566>,
0 commit comments