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