Skip to content

Commit 0031951

Browse files
Store typed Passes
1 parent 6be2857 commit 0031951

File tree

7 files changed

+65
-68
lines changed

7 files changed

+65
-68
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ pub struct Crate {
133133
// Only here so that they can be filtered through the rustdoc passes.
134134
pub external_traits: Rc<RefCell<FxHashMap<DefId, Trait>>>,
135135
pub masked_crates: FxHashSet<CrateNum>,
136+
pub collapsed: bool,
136137
}
137138

138139
impl Clean<Crate> for hir::Crate {
@@ -221,6 +222,7 @@ impl Clean<Crate> for hir::Crate {
221222
primitives,
222223
external_traits: cx.external_traits.clone(),
223224
masked_crates,
225+
collapsed: false,
224226
}
225227
}
226228
}

src/librustdoc/config.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,22 +220,22 @@ impl Options {
220220
println!("{:>20} - {}", pass.name, pass.description);
221221
}
222222
println!("\nDefault passes for rustdoc:");
223-
for &name in passes::DEFAULT_PASSES {
224-
println!("{:>20}", name);
223+
for pass in passes::DEFAULT_PASSES {
224+
println!("{:>20}", pass.name);
225225
}
226226
println!("\nPasses run with `--document-private-items`:");
227-
for &name in passes::DEFAULT_PRIVATE_PASSES {
228-
println!("{:>20}", name);
227+
for pass in passes::DEFAULT_PRIVATE_PASSES {
228+
println!("{:>20}", pass.name);
229229
}
230230

231231
if nightly_options::is_nightly_build() {
232232
println!("\nPasses run with `--show-coverage`:");
233-
for &name in passes::DEFAULT_COVERAGE_PASSES {
234-
println!("{:>20}", name);
233+
for pass in passes::DEFAULT_COVERAGE_PASSES {
234+
println!("{:>20}", pass.name);
235235
}
236236
println!("\nPasses run with `--show-coverage --document-private-items`:");
237-
for &name in passes::PRIVATE_COVERAGE_PASSES {
238-
println!("{:>20}", name);
237+
for pass in passes::PRIVATE_COVERAGE_PASSES {
238+
println!("{:>20}", pass.name);
239239
}
240240
}
241241

src/librustdoc/core.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ pub fn new_handler(error_format: ErrorOutputType,
223223
)
224224
}
225225

226-
pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOptions, Vec<String>) {
226+
pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOptions) {
227227
// Parse, resolve, and typecheck the given crate.
228228

229229
let RustdocOptions {
@@ -427,8 +427,8 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
427427
},
428428
_ => continue,
429429
};
430-
for p in value.as_str().split_whitespace() {
431-
sink.push(p.to_string());
430+
for name in value.as_str().split_whitespace() {
431+
sink.push(name.to_string());
432432
}
433433
}
434434

@@ -439,25 +439,26 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
439439
}
440440
}
441441

442-
let mut passes: Vec<String> =
443-
passes::defaults(default_passes).iter().map(|p| p.to_string()).collect();
444-
passes.extend(manual_passes);
442+
let passes = passes::defaults(default_passes).iter().chain(manual_passes.into_iter()
443+
.flat_map(|name| {
444+
if let Some(pass) = passes::find_pass(&name) {
445+
Some(pass)
446+
} else {
447+
error!("unknown pass {}, skipping", name);
448+
None
449+
}
450+
}));
445451

446452
info!("Executing passes");
447453

448-
for pass_name in &passes {
449-
match passes::find_pass(pass_name).map(|p| p.pass) {
450-
Some(pass) => {
451-
debug!("running pass {}", pass_name);
452-
krate = pass(krate, &ctxt);
453-
}
454-
None => error!("unknown pass {}, skipping", *pass_name),
455-
}
454+
for pass in passes {
455+
debug!("running pass {}", pass.name);
456+
krate = (pass.pass)(krate, &ctxt);
456457
}
457458

458459
ctxt.sess().abort_if_errors();
459460

460-
(krate, ctxt.renderinfo.into_inner(), render_options, passes)
461+
(krate, ctxt.renderinfo.into_inner(), render_options)
461462
})
462463
})
463464
}

src/librustdoc/html/render.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ struct SharedContext {
185185
pub include_sources: bool,
186186
/// The local file sources we've emitted and their respective url-paths.
187187
pub local_sources: FxHashMap<PathBuf, String>,
188-
/// All the passes that were run on this crate.
189-
pub passes: FxHashSet<String>,
188+
/// Whether the collapsed pass ran
189+
pub collapsed: bool,
190190
/// The base-URL of the issue tracker for when an item has been tagged with
191191
/// an issue number.
192192
pub issue_tracker_base_url: Option<String>,
@@ -229,15 +229,10 @@ impl SharedContext {
229229
}
230230

231231
impl SharedContext {
232-
/// Returns `true` if the `collapse-docs` pass was run on this crate.
233-
pub fn was_collapsed(&self) -> bool {
234-
self.passes.contains("collapse-docs")
235-
}
236-
237232
/// Based on whether the `collapse-docs` pass was run, return either the `doc_value` or the
238233
/// `collapsed_doc_value` of the given item.
239234
pub fn maybe_collapsed_doc_value<'a>(&self, item: &'a clean::Item) -> Option<Cow<'a, str>> {
240-
if self.was_collapsed() {
235+
if self.collapsed {
241236
item.collapsed_doc_value().map(|s| s.into())
242237
} else {
243238
item.doc_value().map(|s| s.into())
@@ -526,7 +521,6 @@ pub fn initial_ids() -> Vec<String> {
526521
/// Generates the documentation for `crate` into the directory `dst`
527522
pub fn run(mut krate: clean::Crate,
528523
options: RenderOptions,
529-
passes: FxHashSet<String>,
530524
renderinfo: RenderInfo,
531525
diag: &errors::Handler,
532526
edition: Edition) -> Result<(), Error> {
@@ -557,8 +551,8 @@ pub fn run(mut krate: clean::Crate,
557551
};
558552
let mut errors = Arc::new(ErrorStorage::new());
559553
let mut scx = SharedContext {
554+
collapsed: krate.collapsed,
560555
src_root,
561-
passes,
562556
include_sources: true,
563557
local_sources: Default::default(),
564558
issue_tracker_base_url: None,

src/librustdoc/lib.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ struct Output {
8080
krate: clean::Crate,
8181
renderinfo: html::render::RenderInfo,
8282
renderopts: config::RenderOptions,
83-
passes: Vec<String>,
8483
}
8584

8685
pub fn main() {
@@ -419,14 +418,13 @@ fn main_options(options: config::Options) -> i32 {
419418
return rustc_driver::EXIT_SUCCESS;
420419
}
421420

422-
let Output { krate, passes, renderinfo, renderopts } = out;
421+
let Output { krate, renderinfo, renderopts } = out;
423422
info!("going to format");
424423
let (error_format, treat_err_as_bug, ui_testing, edition) = diag_opts;
425424
let diag = core::new_handler(error_format, None, treat_err_as_bug, ui_testing);
426425
match html::render::run(
427426
krate,
428427
renderopts,
429-
passes.into_iter().collect(),
430428
renderinfo,
431429
&diag,
432430
edition,
@@ -459,7 +457,7 @@ where R: 'static + Send,
459457
let result = rustc_driver::report_ices_to_stderr_if_any(move || {
460458
let crate_name = options.crate_name.clone();
461459
let crate_version = options.crate_version.clone();
462-
let (mut krate, renderinfo, renderopts, passes) = core::run_core(options);
460+
let (mut krate, renderinfo, renderopts) = core::run_core(options);
463461

464462
info!("finished with rustc");
465463

@@ -473,7 +471,6 @@ where R: 'static + Send,
473471
krate: krate,
474472
renderinfo: renderinfo,
475473
renderopts,
476-
passes: passes
477474
})).unwrap();
478475
});
479476

src/librustdoc/passes/collapse_docs.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ impl DocFragment {
3030
}
3131

3232
pub fn collapse_docs(krate: clean::Crate, _: &DocContext<'_>) -> clean::Crate {
33-
Collapser.fold_crate(krate)
33+
let mut krate = Collapser.fold_crate(krate);
34+
krate.collapsed = true;
35+
krate
3436
}
3537

3638
struct Collapser;

src/librustdoc/passes/mod.rs

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ pub struct Pass {
5757
pub description: &'static str,
5858
}
5959

60+
6061
/// The full list of passes.
61-
pub const PASSES: &'static [Pass] = &[
62+
pub const PASSES: &[Pass] = &[
6263
CHECK_PRIVATE_ITEMS_DOC_TESTS,
6364
STRIP_HIDDEN,
6465
UNINDENT_COMMENTS,
@@ -73,43 +74,43 @@ pub const PASSES: &'static [Pass] = &[
7374
];
7475

7576
/// The list of passes run by default.
76-
pub const DEFAULT_PASSES: &[&str] = &[
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",
77+
pub const DEFAULT_PASSES: &[Pass] = &[
78+
COLLECT_TRAIT_IMPLS,
79+
COLLAPSE_DOCS,
80+
UNINDENT_COMMENTS,
81+
CHECK_PRIVATE_ITEMS_DOC_TESTS,
82+
STRIP_HIDDEN,
83+
STRIP_PRIVATE,
84+
COLLECT_INTRA_DOC_LINKS,
85+
CHECK_CODE_BLOCK_SYNTAX,
86+
PROPAGATE_DOC_CFG,
8687
];
8788

8889
/// The list of default passes run with `--document-private-items` is passed to rustdoc.
89-
pub const DEFAULT_PRIVATE_PASSES: &[&str] = &[
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",
90+
pub const DEFAULT_PRIVATE_PASSES: &[Pass] = &[
91+
COLLECT_TRAIT_IMPLS,
92+
COLLAPSE_DOCS,
93+
UNINDENT_COMMENTS,
94+
CHECK_PRIVATE_ITEMS_DOC_TESTS,
95+
STRIP_PRIV_IMPORTS,
96+
COLLECT_INTRA_DOC_LINKS,
97+
CHECK_CODE_BLOCK_SYNTAX,
98+
PROPAGATE_DOC_CFG,
9899
];
99100

100101
/// The list of default passes run when `--doc-coverage` is passed to rustdoc.
101-
pub const DEFAULT_COVERAGE_PASSES: &'static [&'static str] = &[
102-
"collect-trait-impls",
103-
"strip-hidden",
104-
"strip-private",
105-
"calculate-doc-coverage",
102+
pub const DEFAULT_COVERAGE_PASSES: &[Pass] = &[
103+
COLLECT_TRAIT_IMPLS,
104+
STRIP_HIDDEN,
105+
STRIP_PRIVATE,
106+
CALCULATE_DOC_COVERAGE,
106107
];
107108

108109
/// The list of default passes run when `--doc-coverage --document-private-items` is passed to
109110
/// rustdoc.
110-
pub const PRIVATE_COVERAGE_PASSES: &'static [&'static str] = &[
111-
"collect-trait-impls",
112-
"calculate-doc-coverage",
111+
pub const PRIVATE_COVERAGE_PASSES: &[Pass] = &[
112+
COLLECT_TRAIT_IMPLS,
113+
CALCULATE_DOC_COVERAGE,
113114
];
114115

115116
/// A shorthand way to refer to which set of passes to use, based on the presence of
@@ -124,7 +125,7 @@ pub enum DefaultPassOption {
124125
}
125126

126127
/// Returns the given default set of passes.
127-
pub fn defaults(default_set: DefaultPassOption) -> &'static [&'static str] {
128+
pub fn defaults(default_set: DefaultPassOption) -> &'static [Pass] {
128129
match default_set {
129130
DefaultPassOption::Default => DEFAULT_PASSES,
130131
DefaultPassOption::Private => DEFAULT_PRIVATE_PASSES,

0 commit comments

Comments
 (0)