@@ -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.
@@ -374,7 +382,6 @@ pub(crate) fn run_global_ctxt(
374382 cache : Cache :: new ( render_options. document_private , render_options. document_hidden ) ,
375383 inlined : FxHashSet :: default ( ) ,
376384 output_format,
377- render_options,
378385 show_coverage,
379386 } ;
380387
@@ -411,14 +418,6 @@ pub(crate) fn run_global_ctxt(
411418 ) ;
412419 }
413420
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-
422421 info ! ( "Executing passes" ) ;
423422
424423 let mut visited = FxHashMap :: default ( ) ;
@@ -427,9 +426,9 @@ pub(crate) fn run_global_ctxt(
427426 for p in passes:: defaults ( show_coverage) {
428427 let run = match p. condition {
429428 Always => true ,
430- WhenDocumentPrivate => ctxt. render_options . document_private ,
431- WhenNotDocumentPrivate => !ctxt. render_options . document_private ,
432- WhenNotDocumentHidden => !ctxt. render_options . document_hidden ,
429+ WhenDocumentPrivate => ctxt. document_private ( ) ,
430+ WhenNotDocumentPrivate => !ctxt. document_private ( ) ,
431+ WhenNotDocumentHidden => !ctxt. document_hidden ( ) ,
433432 } ;
434433 if run {
435434 debug ! ( "running pass {}" , p. pass. name) ;
@@ -447,15 +446,16 @@ pub(crate) fn run_global_ctxt(
447446
448447 tcx. sess . time ( "check_lint_expectations" , || tcx. check_expectations ( Some ( sym:: rustdoc) ) ) ;
449448
450- krate = tcx. sess . time ( "create_format_cache" , || Cache :: populate ( & mut ctxt, krate) ) ;
449+ krate =
450+ tcx. sess . time ( "create_format_cache" , || Cache :: populate ( & mut ctxt, krate, & render_options) ) ;
451451
452452 let mut collector =
453453 LinkCollector { cx : & mut ctxt, visited_links : visited, ambiguous_links : ambiguous } ;
454454 collector. resolve_ambiguities ( ) ;
455455
456456 tcx. dcx ( ) . abort_if_errors ( ) ;
457457
458- ( krate, ctxt . render_options , ctxt. cache , expanded_macros)
458+ ( krate, render_options, ctxt. cache , expanded_macros)
459459}
460460
461461/// Due to <https://github.com/rust-lang/rust/pull/73566>,
0 commit comments