Skip to content

Commit 1536852

Browse files
committed
merge early and late passes into single struct
1 parent 906ec8a commit 1536852

14 files changed

+68
-138
lines changed

src/librustdoc/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ impl Options {
214214
if matches.opt_strs("passes") == ["list"] {
215215
println!("Available passes for running rustdoc:");
216216
for pass in passes::PASSES {
217-
println!("{:>20} - {}", pass.name(), pass.description());
217+
println!("{:>20} - {}", pass.name, pass.description);
218218
}
219219
println!("\nDefault passes for rustdoc:");
220220
for &name in passes::DEFAULT_PASSES {

src/librustdoc/core.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -606,10 +606,12 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
606606
passes::defaults(default_passes).iter().map(|p| p.to_string()).collect();
607607
passes.extend(manual_passes);
608608

609+
info!("Executing passes");
610+
609611
for pass in &passes {
610-
// the "unknown pass" error will be reported when late passes are run
611-
if let Some(pass) = passes::find_pass(pass).and_then(|p| p.early_fn()) {
612-
krate = pass(krate, &ctxt);
612+
match passes::find_pass(pass).map(|p| p.pass) {
613+
Some(pass) => krate = pass(krate, &ctxt),
614+
None => error!("unknown pass {}, skipping", *pass),
613615
}
614616
}
615617

src/librustdoc/lib.rs

-22
Original file line numberDiff line numberDiff line change
@@ -441,28 +441,6 @@ where R: 'static + Send,
441441

442442
krate.version = crate_version;
443443

444-
info!("Executing passes");
445-
446-
for pass in &passes {
447-
// determine if we know about this pass
448-
let pass = match passes::find_pass(pass) {
449-
Some(pass) => if let Some(pass) = pass.late_fn() {
450-
pass
451-
} else {
452-
// not a late pass, but still valid so don't report the error
453-
continue
454-
}
455-
None => {
456-
error!("unknown pass {}, skipping", *pass);
457-
458-
continue
459-
},
460-
};
461-
462-
// run it
463-
krate = pass(krate);
464-
}
465-
466444
tx.send(f(Output {
467445
krate: krate,
468446
renderinfo: renderinfo,

src/librustdoc/passes/check_code_block_syntax.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ use crate::fold::DocFolder;
1010
use crate::html::markdown::{self, RustCodeBlock};
1111
use crate::passes::Pass;
1212

13-
pub const CHECK_CODE_BLOCK_SYNTAX: Pass =
14-
Pass::early("check-code-block-syntax", check_code_block_syntax,
15-
"validates syntax inside Rust code blocks");
13+
pub const CHECK_CODE_BLOCK_SYNTAX: Pass = Pass {
14+
name: "check-code-block-syntax",
15+
pass: check_code_block_syntax,
16+
description: "validates syntax inside Rust code blocks",
17+
};
1618

1719
pub fn check_code_block_syntax(krate: clean::Crate, cx: &DocContext<'_, '_, '_>) -> clean::Crate {
1820
SyntaxChecker { cx }.fold_crate(krate)

src/librustdoc/passes/collapse_docs.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ use crate::passes::Pass;
66

77
use std::mem::replace;
88

9-
pub const COLLAPSE_DOCS: Pass =
10-
Pass::early("collapse-docs", collapse_docs,
11-
"concatenates all document attributes into one document attribute");
9+
pub const COLLAPSE_DOCS: Pass = Pass {
10+
name: "collapse-docs",
11+
pass: collapse_docs,
12+
description: "concatenates all document attributes into one document attribute",
13+
};
1214

1315
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
1416
enum DocFragmentKind {

src/librustdoc/passes/collect_intra_doc_links.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ use crate::passes::{look_for_tests, Pass};
1818

1919
use super::span_of_attrs;
2020

21-
pub const COLLECT_INTRA_DOC_LINKS: Pass =
22-
Pass::early("collect-intra-doc-links", collect_intra_doc_links,
23-
"reads a crate's documentation to resolve intra-doc-links");
21+
pub const COLLECT_INTRA_DOC_LINKS: Pass = Pass {
22+
name: "collect-intra-doc-links",
23+
pass: collect_intra_doc_links,
24+
description: "reads a crate's documentation to resolve intra-doc-links",
25+
};
2426

2527
pub fn collect_intra_doc_links(krate: Crate, cx: &DocContext<'_, '_, '_>) -> Crate {
2628
if !UnstableFeatures::from_environment().is_nightly_build() {

src/librustdoc/passes/collect_trait_impls.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ use super::Pass;
66
use rustc::util::nodemap::FxHashSet;
77
use rustc::hir::def_id::DefId;
88

9-
pub const COLLECT_TRAIT_IMPLS: Pass =
10-
Pass::early("collect-trait-impls", collect_trait_impls,
11-
"retrieves trait impls for items in the crate");
9+
pub const COLLECT_TRAIT_IMPLS: Pass = Pass {
10+
name: "collect-trait-impls",
11+
pass: collect_trait_impls,
12+
description: "retrieves trait impls for items in the crate",
13+
};
1214

1315
pub fn collect_trait_impls(krate: Crate, cx: &DocContext<'_, '_, '_>) -> Crate {
1416
let mut synth = SyntheticImplCollector::new(cx);

src/librustdoc/passes/mod.rs

+9-80
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use rustc::lint as lint;
66
use rustc::middle::privacy::AccessLevels;
77
use rustc::util::nodemap::DefIdSet;
88
use std::mem;
9-
use std::fmt;
109
use syntax::ast::NodeId;
1110
use syntax_pos::{DUMMY_SP, Span};
1211
use std::ops::Range;
@@ -46,84 +45,14 @@ pub use self::collect_trait_impls::COLLECT_TRAIT_IMPLS;
4645
mod check_code_block_syntax;
4746
pub use self::check_code_block_syntax::CHECK_CODE_BLOCK_SYNTAX;
4847

49-
/// Represents a single pass.
48+
/// A single pass over the cleaned documentation.
49+
///
50+
/// Runs in the compiler context, so it has access to types and traits and the like.
5051
#[derive(Copy, Clone)]
51-
pub enum Pass {
52-
/// An "early pass" is run in the compiler context, and can gather information about types and
53-
/// traits and the like.
54-
EarlyPass {
55-
name: &'static str,
56-
pass: fn(clean::Crate, &DocContext<'_, '_, '_>) -> clean::Crate,
57-
description: &'static str,
58-
},
59-
/// A "late pass" is run between crate cleaning and page generation.
60-
LatePass {
61-
name: &'static str,
62-
pass: fn(clean::Crate) -> clean::Crate,
63-
description: &'static str,
64-
},
65-
}
66-
67-
impl fmt::Debug for Pass {
68-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
69-
let mut dbg = match *self {
70-
Pass::EarlyPass { .. } => f.debug_struct("EarlyPass"),
71-
Pass::LatePass { .. } => f.debug_struct("LatePass"),
72-
};
73-
74-
dbg.field("name", &self.name())
75-
.field("pass", &"...")
76-
.field("description", &self.description())
77-
.finish()
78-
}
79-
}
80-
81-
impl Pass {
82-
/// Constructs a new early pass.
83-
pub const fn early(name: &'static str,
84-
pass: fn(clean::Crate, &DocContext<'_, '_, '_>) -> clean::Crate,
85-
description: &'static str) -> Pass {
86-
Pass::EarlyPass { name, pass, description }
87-
}
88-
89-
/// Constructs a new late pass.
90-
pub const fn late(name: &'static str,
91-
pass: fn(clean::Crate) -> clean::Crate,
92-
description: &'static str) -> Pass {
93-
Pass::LatePass { name, pass, description }
94-
}
95-
96-
/// Returns the name of this pass.
97-
pub fn name(self) -> &'static str {
98-
match self {
99-
Pass::EarlyPass { name, .. } |
100-
Pass::LatePass { name, .. } => name,
101-
}
102-
}
103-
104-
/// Returns the description of this pass.
105-
pub fn description(self) -> &'static str {
106-
match self {
107-
Pass::EarlyPass { description, .. } |
108-
Pass::LatePass { description, .. } => description,
109-
}
110-
}
111-
112-
/// If this pass is an early pass, returns the pointer to its function.
113-
pub fn early_fn(self) -> Option<fn(clean::Crate, &DocContext<'_, '_, '_>) -> clean::Crate> {
114-
match self {
115-
Pass::EarlyPass { pass, .. } => Some(pass),
116-
_ => None,
117-
}
118-
}
119-
120-
/// If this pass is a late pass, returns the pointer to its function.
121-
pub fn late_fn(self) -> Option<fn(clean::Crate) -> clean::Crate> {
122-
match self {
123-
Pass::LatePass { pass, .. } => Some(pass),
124-
_ => None,
125-
}
126-
}
52+
pub struct Pass {
53+
pub name: &'static str,
54+
pub pass: fn(clean::Crate, &DocContext<'_, '_, '_>) -> clean::Crate,
55+
pub description: &'static str,
12756
}
12857

12958
/// The full list of passes.
@@ -184,8 +113,8 @@ pub fn defaults(default_set: DefaultPassOption) -> &'static [&'static str] {
184113
}
185114

186115
/// If the given name matches a known pass, returns its information.
187-
pub fn find_pass(pass_name: &str) -> Option<Pass> {
188-
PASSES.iter().find(|p| p.name() == pass_name).cloned()
116+
pub fn find_pass(pass_name: &str) -> Option<&'static Pass> {
117+
PASSES.iter().find(|p| p.name == pass_name)
189118
}
190119

191120
struct Stripper<'a> {

src/librustdoc/passes/private_items_doc_tests.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ use crate::core::DocContext;
33
use crate::fold::DocFolder;
44
use crate::passes::{look_for_tests, Pass};
55

6-
7-
pub const CHECK_PRIVATE_ITEMS_DOC_TESTS: Pass =
8-
Pass::early("check-private-items-doc-tests", check_private_items_doc_tests,
9-
"check private items doc tests");
6+
pub const CHECK_PRIVATE_ITEMS_DOC_TESTS: Pass = Pass {
7+
name: "check-private-items-doc-tests",
8+
pass: check_private_items_doc_tests,
9+
description: "check private items doc tests",
10+
};
1011

1112
struct PrivateItemDocTestLinter<'a, 'tcx: 'a, 'rcx: 'a> {
1213
cx: &'a DocContext<'a, 'tcx, 'rcx>,

src/librustdoc/passes/propagate_doc_cfg.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@ use std::sync::Arc;
22

33
use crate::clean::{Crate, Item};
44
use crate::clean::cfg::Cfg;
5+
use crate::core::DocContext;
56
use crate::fold::DocFolder;
67
use crate::passes::Pass;
78

8-
pub const PROPAGATE_DOC_CFG: Pass =
9-
Pass::late("propagate-doc-cfg", propagate_doc_cfg,
10-
"propagates `#[doc(cfg(...))]` to child items");
9+
pub const PROPAGATE_DOC_CFG: Pass = Pass {
10+
name: "propagate-doc-cfg",
11+
pass: propagate_doc_cfg,
12+
description: "propagates `#[doc(cfg(...))]` to child items",
13+
};
1114

12-
pub fn propagate_doc_cfg(cr: Crate) -> Crate {
15+
pub fn propagate_doc_cfg(cr: Crate, _: &DocContext<'_, '_, '_>) -> Crate {
1316
CfgPropagator { parent_cfg: None }.fold_crate(cr)
1417
}
1518

src/librustdoc/passes/strip_hidden.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ use crate::core::DocContext;
77
use crate::fold::{DocFolder, StripItem};
88
use crate::passes::{ImplStripper, Pass};
99

10-
pub const STRIP_HIDDEN: Pass =
11-
Pass::early("strip-hidden", strip_hidden,
12-
"strips all doc(hidden) items from the output");
10+
pub const STRIP_HIDDEN: Pass = Pass {
11+
name: "strip-hidden",
12+
pass: strip_hidden,
13+
description: "strips all doc(hidden) items from the output",
14+
};
1315

1416
/// Strip items marked `#[doc(hidden)]`
1517
pub fn strip_hidden(krate: clean::Crate, _: &DocContext<'_, '_, '_>) -> clean::Crate {

src/librustdoc/passes/strip_priv_imports.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ use crate::fold::{DocFolder};
33
use crate::core::DocContext;
44
use crate::passes::{ImportStripper, Pass};
55

6-
pub const STRIP_PRIV_IMPORTS: Pass = Pass::early("strip-priv-imports", strip_priv_imports,
7-
"strips all private import statements (`use`, `extern crate`) from a crate");
6+
pub const STRIP_PRIV_IMPORTS: Pass = Pass {
7+
name: "strip-priv-imports",
8+
pass: strip_priv_imports,
9+
description: "strips all private import statements (`use`, `extern crate`) from a crate",
10+
};
811

912
pub fn strip_priv_imports(krate: clean::Crate, _: &DocContext<'_, '_, '_>) -> clean::Crate {
1013
ImportStripper.fold_crate(krate)

src/librustdoc/passes/strip_private.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ use crate::fold::{DocFolder};
55
use crate::core::DocContext;
66
use crate::passes::{ImplStripper, ImportStripper, Stripper, Pass};
77

8-
pub const STRIP_PRIVATE: Pass =
9-
Pass::early("strip-private", strip_private,
10-
"strips all private items from a crate which cannot be seen externally, \
11-
implies strip-priv-imports");
8+
pub const STRIP_PRIVATE: Pass = Pass {
9+
name: "strip-private",
10+
pass: strip_private,
11+
description: "strips all private items from a crate which cannot be seen externally, \
12+
implies strip-priv-imports",
13+
};
1214

1315
/// Strip private items from the point of view of a crate or externally from a
1416
/// crate, specified by the `xcrate` flag.

src/librustdoc/passes/unindent_comments.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ use crate::core::DocContext;
77
use crate::fold::{self, DocFolder};
88
use crate::passes::Pass;
99

10-
pub const UNINDENT_COMMENTS: Pass =
11-
Pass::early("unindent-comments", unindent_comments,
12-
"removes excess indentation on comments in order for markdown to like it");
10+
pub const UNINDENT_COMMENTS: Pass = Pass {
11+
name: "unindent-comments",
12+
pass: unindent_comments,
13+
description: "removes excess indentation on comments in order for markdown to like it",
14+
};
1315

1416
pub fn unindent_comments(krate: clean::Crate, _: &DocContext<'_, '_, '_>) -> clean::Crate {
1517
CommentCleaner.fold_crate(krate)

0 commit comments

Comments
 (0)