@@ -9,6 +9,7 @@ use std::mem;
99use std:: ops:: Range ;
1010use syntax_pos:: { InnerSpan , Span , DUMMY_SP } ;
1111
12+ use self :: Condition :: * ;
1213use crate :: clean:: { self , GetDefId , Item } ;
1314use crate :: core:: DocContext ;
1415use crate :: fold:: { DocFolder , StripItem } ;
@@ -53,10 +54,29 @@ pub use self::calculate_doc_coverage::CALCULATE_DOC_COVERAGE;
5354#[ derive( Copy , Clone ) ]
5455pub struct Pass {
5556 pub name : & ' static str ,
56- pub pass : fn ( clean:: Crate , & DocContext < ' _ > ) -> clean:: Crate ,
57+ pub run : fn ( clean:: Crate , & DocContext < ' _ > ) -> clean:: Crate ,
5758 pub description : & ' static str ,
5859}
5960
61+ /// In a list of passes, a pass that may or may not need to be run depending on options.
62+ #[ derive( Copy , Clone ) ]
63+ pub struct ConditionalPass {
64+ pub pass : Pass ,
65+ pub condition : Condition ,
66+ }
67+
68+ /// How to decide whether to run a conditional pass.
69+ #[ derive( Copy , Clone ) ]
70+ pub enum Condition {
71+ Always ,
72+ /// When `--document-private-items` is passed.
73+ WhenDocumentPrivate ,
74+ /// When `--document-private-items` is not passed.
75+ WhenNotDocumentPrivate ,
76+ /// When `--document-hidden-items` is not passed.
77+ WhenNotDocumentHidden ,
78+ }
79+
6080/// The full list of passes.
6181pub const PASSES : & [ Pass ] = & [
6282 CHECK_PRIVATE_ITEMS_DOC_TESTS ,
@@ -73,63 +93,58 @@ pub const PASSES: &[Pass] = &[
7393] ;
7494
7595/// The list of passes run by default.
76- pub const DEFAULT_PASSES : & [ Pass ] = & [
77- COLLECT_TRAIT_IMPLS ,
78- COLLAPSE_DOCS ,
79- UNINDENT_COMMENTS ,
80- CHECK_PRIVATE_ITEMS_DOC_TESTS ,
81- STRIP_HIDDEN ,
82- STRIP_PRIVATE ,
83- COLLECT_INTRA_DOC_LINKS ,
84- CHECK_CODE_BLOCK_SYNTAX ,
85- PROPAGATE_DOC_CFG ,
96+ pub const DEFAULT_PASSES : & [ ConditionalPass ] = & [
97+ ConditionalPass :: always ( COLLECT_TRAIT_IMPLS ) ,
98+ ConditionalPass :: always ( COLLAPSE_DOCS ) ,
99+ ConditionalPass :: always ( UNINDENT_COMMENTS ) ,
100+ ConditionalPass :: always ( CHECK_PRIVATE_ITEMS_DOC_TESTS ) ,
101+ ConditionalPass :: new ( STRIP_HIDDEN , WhenNotDocumentHidden ) ,
102+ ConditionalPass :: new ( STRIP_PRIVATE , WhenNotDocumentPrivate ) ,
103+ ConditionalPass :: new ( STRIP_PRIV_IMPORTS , WhenDocumentPrivate ) ,
104+ ConditionalPass :: always ( COLLECT_INTRA_DOC_LINKS ) ,
105+ ConditionalPass :: always ( CHECK_CODE_BLOCK_SYNTAX ) ,
106+ ConditionalPass :: always ( PROPAGATE_DOC_CFG ) ,
86107] ;
87108
88- /// The list of default passes run with `--document-private-items` is passed to rustdoc.
89- pub const DEFAULT_PRIVATE_PASSES : & [ Pass ] = & [
90- COLLECT_TRAIT_IMPLS ,
91- COLLAPSE_DOCS ,
92- UNINDENT_COMMENTS ,
93- CHECK_PRIVATE_ITEMS_DOC_TESTS ,
94- STRIP_PRIV_IMPORTS ,
95- COLLECT_INTRA_DOC_LINKS ,
96- CHECK_CODE_BLOCK_SYNTAX ,
97- PROPAGATE_DOC_CFG ,
109+ /// The list of default passes run when `--doc-coverage` is passed to rustdoc.
110+ pub const COVERAGE_PASSES : & [ ConditionalPass ] = & [
111+ ConditionalPass :: always ( COLLECT_TRAIT_IMPLS ) ,
112+ ConditionalPass :: new ( STRIP_HIDDEN , WhenNotDocumentHidden ) ,
113+ ConditionalPass :: new ( STRIP_PRIVATE , WhenNotDocumentPrivate ) ,
114+ ConditionalPass :: always ( CALCULATE_DOC_COVERAGE ) ,
98115] ;
99116
100- /// The list of default passes run when `--doc-coverage` is passed to rustdoc.
101- pub const DEFAULT_COVERAGE_PASSES : & [ Pass ] =
102- & [ COLLECT_TRAIT_IMPLS , STRIP_HIDDEN , STRIP_PRIVATE , CALCULATE_DOC_COVERAGE ] ;
117+ impl ConditionalPass {
118+ pub const fn always ( pass : Pass ) -> Self {
119+ Self :: new ( pass, Always )
120+ }
103121
104- /// The list of default passes run when `--doc-coverage --document-private-items` is passed to
105- /// rustdoc.
106- pub const PRIVATE_COVERAGE_PASSES : & [ Pass ] = & [ COLLECT_TRAIT_IMPLS , CALCULATE_DOC_COVERAGE ] ;
122+ pub const fn new ( pass : Pass , condition : Condition ) -> Self {
123+ ConditionalPass { pass, condition }
124+ }
125+ }
107126
108127/// A shorthand way to refer to which set of passes to use, based on the presence of
109- /// `--no-defaults` or `--document-private-items `.
128+ /// `--no-defaults` and `--show-coverage `.
110129#[ derive( Copy , Clone , PartialEq , Eq , Debug ) ]
111130pub enum DefaultPassOption {
112131 Default ,
113- Private ,
114132 Coverage ,
115- PrivateCoverage ,
116133 None ,
117134}
118135
119136/// Returns the given default set of passes.
120- pub fn defaults ( default_set : DefaultPassOption ) -> & ' static [ Pass ] {
137+ pub fn defaults ( default_set : DefaultPassOption ) -> & ' static [ ConditionalPass ] {
121138 match default_set {
122139 DefaultPassOption :: Default => DEFAULT_PASSES ,
123- DefaultPassOption :: Private => DEFAULT_PRIVATE_PASSES ,
124- DefaultPassOption :: Coverage => DEFAULT_COVERAGE_PASSES ,
125- DefaultPassOption :: PrivateCoverage => PRIVATE_COVERAGE_PASSES ,
140+ DefaultPassOption :: Coverage => COVERAGE_PASSES ,
126141 DefaultPassOption :: None => & [ ] ,
127142 }
128143}
129144
130145/// If the given name matches a known pass, returns its information.
131- pub fn find_pass ( pass_name : & str ) -> Option < & ' static Pass > {
132- PASSES . iter ( ) . find ( |p| p. name == pass_name)
146+ pub fn find_pass ( pass_name : & str ) -> Option < Pass > {
147+ PASSES . iter ( ) . find ( |p| p. name == pass_name) . copied ( )
133148}
134149
135150struct Stripper < ' a > {
0 commit comments