Skip to content

Commit ee2e115

Browse files
author
Jonathan Turner
authored
Rollup merge of #36729 - frewsxcv:rustdoc, r=alexcrichton
librustdoc refactoring and cleanup. See each commit for more information. Biggest changes here is the addition of a `passes` module and each pass now lives in its own submodule.
2 parents df52628 + 99e1b9c commit ee2e115

File tree

8 files changed

+552
-451
lines changed

8 files changed

+552
-451
lines changed

src/librustdoc/lib.rs

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -91,39 +91,14 @@ pub mod test;
9191

9292
use clean::Attributes;
9393

94-
type Pass = (&'static str, // name
95-
fn(clean::Crate) -> plugins::PluginResult, // fn
96-
&'static str); // description
97-
98-
const PASSES: &'static [Pass] = &[
99-
("strip-hidden", passes::strip_hidden,
100-
"strips all doc(hidden) items from the output"),
101-
("unindent-comments", passes::unindent_comments,
102-
"removes excess indentation on comments in order for markdown to like it"),
103-
("collapse-docs", passes::collapse_docs,
104-
"concatenates all document attributes into one document attribute"),
105-
("strip-private", passes::strip_private,
106-
"strips all private items from a crate which cannot be seen externally, \
107-
implies strip-priv-imports"),
108-
("strip-priv-imports", passes::strip_priv_imports,
109-
"strips all private import statements (`use`, `extern crate`) from a crate"),
110-
];
111-
112-
const DEFAULT_PASSES: &'static [&'static str] = &[
113-
"strip-hidden",
114-
"strip-private",
115-
"collapse-docs",
116-
"unindent-comments",
117-
];
118-
11994
struct Output {
12095
krate: clean::Crate,
12196
renderinfo: html::render::RenderInfo,
12297
passes: Vec<String>,
12398
}
12499

125100
pub fn main() {
126-
const STACK_SIZE: usize = 32000000; // 32MB
101+
const STACK_SIZE: usize = 32_000_000; // 32MB
127102
let res = std::thread::Builder::new().stack_size(STACK_SIZE).spawn(move || {
128103
let s = env::args().collect::<Vec<_>>();
129104
main_args(&s)
@@ -223,11 +198,11 @@ pub fn main_args(args: &[String]) -> isize {
223198

224199
if matches.opt_strs("passes") == ["list"] {
225200
println!("Available passes for running rustdoc:");
226-
for &(name, _, description) in PASSES {
201+
for &(name, _, description) in passes::PASSES {
227202
println!("{:>20} - {}", name, description);
228203
}
229204
println!("\nDefault passes for rustdoc:");
230-
for &name in DEFAULT_PASSES {
205+
for &name in passes::DEFAULT_PASSES {
231206
println!("{:>20}", name);
232207
}
233208
return 0;
@@ -236,7 +211,8 @@ pub fn main_args(args: &[String]) -> isize {
236211
if matches.free.is_empty() {
237212
println!("expected an input file to act on");
238213
return 1;
239-
} if matches.free.len() > 1 {
214+
}
215+
if matches.free.len() > 1 {
240216
println!("only one input file may be specified");
241217
return 1;
242218
}
@@ -412,7 +388,7 @@ fn rust_input(cratefile: &str, externs: Externs, matches: &getopts::Matches) ->
412388
}
413389

414390
if default_passes {
415-
for name in DEFAULT_PASSES.iter().rev() {
391+
for name in passes::DEFAULT_PASSES.iter().rev() {
416392
passes.insert(0, name.to_string());
417393
}
418394
}
@@ -422,11 +398,11 @@ fn rust_input(cratefile: &str, externs: Externs, matches: &getopts::Matches) ->
422398
.unwrap_or("/tmp/rustdoc/plugins".to_string());
423399
let mut pm = plugins::PluginManager::new(PathBuf::from(path));
424400
for pass in &passes {
425-
let plugin = match PASSES.iter()
426-
.position(|&(p, ..)| {
427-
p == *pass
428-
}) {
429-
Some(i) => PASSES[i].1,
401+
let plugin = match passes::PASSES.iter()
402+
.position(|&(p, ..)| {
403+
p == *pass
404+
}) {
405+
Some(i) => passes::PASSES[i].1,
430406
None => {
431407
error!("unknown pass {}, skipping", *pass);
432408
continue

0 commit comments

Comments
 (0)