Skip to content

Commit 4d6c276

Browse files
split off a separate RenderOptions struct
1 parent 157833c commit 4d6c276

File tree

3 files changed

+67
-49
lines changed

3 files changed

+67
-49
lines changed

src/librustdoc/config.rs

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,13 @@ use opts;
3232
use passes::{self, DefaultPassOption};
3333
use theme;
3434

35+
/// Configuration options for rustdoc.
3536
#[derive(Clone)]
3637
pub struct Options {
3738
// Basic options / Options passed directly to rustc
3839

3940
/// The crate root or Markdown file to load.
4041
pub input: PathBuf,
41-
/// Output directory to generate docs into. Defaults to `doc`.
42-
pub output: PathBuf,
4342
/// The name of the crate being documented.
4443
pub crate_name: Option<String>,
4544
/// How to format errors and warnings.
@@ -91,20 +90,29 @@ pub struct Options {
9190
/// Whether to display warnings during doc generation or while gathering doctests. By default,
9291
/// all non-rustdoc-specific lints are allowed when generating docs.
9392
pub display_warnings: bool,
94-
/// A pre-populated `IdMap` with the default headings and any headings added by Markdown files
95-
/// processed by `external_html`.
96-
pub id_map: IdMap,
9793

9894
// Options that alter generated documentation pages
9995

96+
/// Crate version to note on the sidebar of generated docs.
97+
pub crate_version: Option<String>,
98+
/// Collected options specific to outputting final pages.
99+
pub render_options: RenderOptions,
100+
}
101+
102+
/// Configuration options for the HTML page-creation process.
103+
#[derive(Clone)]
104+
pub struct RenderOptions {
105+
/// Output directory to generate docs into. Defaults to `doc`.
106+
pub output: PathBuf,
100107
/// External files to insert into generated pages.
101108
pub external_html: ExternalHtml,
109+
/// A pre-populated `IdMap` with the default headings and any headings added by Markdown files
110+
/// processed by `external_html`.
111+
pub id_map: IdMap,
102112
/// If present, playground URL to use in the "Run" button added to code samples.
103113
///
104114
/// Be aware: This option can come both from the CLI and from crate attributes!
105115
pub playground_url: Option<String>,
106-
/// Crate version to note on the sidebar of generated docs.
107-
pub crate_version: Option<String>,
108116
/// Whether to sort modules alphabetically on a module page instead of using declaration order.
109117
/// `true` by default.
110118
///
@@ -390,7 +398,6 @@ impl Options {
390398

391399
Ok(Options {
392400
input,
393-
output,
394401
crate_name,
395402
error_format,
396403
libs,
@@ -410,21 +417,24 @@ impl Options {
410417
default_passes,
411418
manual_passes,
412419
display_warnings,
413-
id_map,
414-
external_html,
415-
playground_url,
416420
crate_version,
417-
sort_modules_alphabetically,
418-
themes,
419-
extension_css,
420-
extern_html_root_urls,
421-
resource_suffix,
422-
enable_minification,
423-
enable_index_page,
424-
index_page,
425-
markdown_no_toc,
426-
markdown_css,
427-
markdown_playground_url,
421+
render_options: RenderOptions {
422+
output,
423+
external_html,
424+
id_map,
425+
playground_url,
426+
sort_modules_alphabetically,
427+
themes,
428+
extension_css,
429+
extern_html_root_urls,
430+
resource_suffix,
431+
enable_minification,
432+
enable_index_page,
433+
index_page,
434+
markdown_no_toc,
435+
markdown_css,
436+
markdown_playground_url,
437+
}
428438
})
429439
}
430440

src/librustdoc/html/render.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ pub fn run(mut krate: clean::Crate,
509509
id_map: IdMap,
510510
enable_index_page: bool,
511511
index_page: Option<PathBuf>,
512-
options: config::Options,
512+
options: config::RenderOptions,
513513
diag: &errors::Handler,
514514
) -> Result<(), Error> {
515515
let src_root = match krate.src {
@@ -760,7 +760,7 @@ fn write_shared(
760760
cache: &Cache,
761761
search_index: String,
762762
enable_minification: bool,
763-
options: &config::Options,
763+
options: &config::RenderOptions,
764764
diag: &errors::Handler,
765765
) -> Result<(), Error> {
766766
// Write out the shared files. Note that these are shared among all rustdoc

src/librustdoc/lib.rs

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ mod theme;
9090
struct Output {
9191
krate: clean::Crate,
9292
renderinfo: html::render::RenderInfo,
93+
renderopts: config::RenderOptions,
9394
passes: Vec<String>,
9495
}
9596

@@ -381,36 +382,38 @@ fn main_args(args: &[String]) -> isize {
381382
options.display_warnings, options.linker, options.edition,
382383
options.codegen_options)
383384
}
384-
(false, true) => return markdown::render(&options.input, options.output,
385-
&options.markdown_css,
386-
options.markdown_playground_url
387-
.or(options.playground_url),
388-
&options.external_html,
389-
!options.markdown_no_toc, &diag),
385+
(false, true) => return markdown::render(&options.input, options.render_options.output,
386+
&options.render_options.markdown_css,
387+
options.render_options.markdown_playground_url
388+
.or(options.render_options.playground_url),
389+
&options.render_options.external_html,
390+
!options.render_options.markdown_no_toc, &diag),
390391
(false, false) => {}
391392
}
392393

393-
//TODO: split render-time options into their own struct so i don't have to clone here
394-
rust_input(options.clone(), move |out| {
395-
let Output { krate, passes, renderinfo } = out;
394+
// need to move these items separately because we lose them by the time the closure is called,
395+
// but we can't crates the Handler ahead of time because it's not Send
396+
let diag_opts = (options.error_format,
397+
options.debugging_options.treat_err_as_bug,
398+
options.debugging_options.ui_testing);
399+
rust_input(options, move |out| {
400+
let Output { krate, passes, renderinfo, renderopts } = out;
396401
info!("going to format");
397-
let diag = core::new_handler(options.error_format,
398-
None,
399-
options.debugging_options.treat_err_as_bug,
400-
options.debugging_options.ui_testing);
401-
let html_opts = options.clone();
402-
html::render::run(krate, options.extern_html_root_urls, &options.external_html, options.playground_url,
403-
options.output,
404-
options.resource_suffix,
402+
let (error_format, treat_err_as_bug, ui_testing) = diag_opts;
403+
let diag = core::new_handler(error_format, None, treat_err_as_bug, ui_testing);
404+
let html_opts = renderopts.clone();
405+
html::render::run(krate, renderopts.extern_html_root_urls, &renderopts.external_html,
406+
renderopts.playground_url,
407+
renderopts.output,
408+
renderopts.resource_suffix,
405409
passes.into_iter().collect(),
406-
options.extension_css,
410+
renderopts.extension_css,
407411
renderinfo,
408-
options.sort_modules_alphabetically,
409-
options.themes,
410-
options.enable_minification, options.id_map,
411-
options.enable_index_page, options.index_page,
412-
html_opts,
413-
&diag)
412+
renderopts.sort_modules_alphabetically,
413+
renderopts.themes,
414+
renderopts.enable_minification, renderopts.id_map,
415+
renderopts.enable_index_page, renderopts.index_page,
416+
html_opts, &diag)
414417
.expect("failed to generate documentation");
415418
0
416419
})
@@ -482,7 +485,12 @@ where R: 'static + Send,
482485
krate = pass(krate);
483486
}
484487

485-
tx.send(f(Output { krate: krate, renderinfo: renderinfo, passes: passes })).unwrap();
488+
tx.send(f(Output {
489+
krate: krate,
490+
renderinfo: renderinfo,
491+
renderopts: options.render_options,
492+
passes: passes
493+
})).unwrap();
486494
}));
487495

488496
match result {

0 commit comments

Comments
 (0)