Skip to content

Commit 5386cbd

Browse files
format librustdoc
1 parent 6a835ea commit 5386cbd

15 files changed

+839
-775
lines changed

src/librustdoc/config.rs

Lines changed: 62 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ use errors;
77
use getopts;
88
use rustc::lint::Level;
99
use rustc::session;
10-
use rustc::session::config::{CrateType, parse_crate_types_from_list, parse_externs};
10+
use rustc::session::config::{
11+
build_codegen_options, build_debugging_options, get_cmd_lint_options, host_triple,
12+
nightly_options,
13+
};
14+
use rustc::session::config::{parse_crate_types_from_list, parse_externs, CrateType};
1115
use rustc::session::config::{CodegenOptions, DebuggingOptions, ErrorOutputType, Externs};
12-
use rustc::session::config::{nightly_options, build_codegen_options, build_debugging_options,
13-
get_cmd_lint_options, host_triple};
1416
use rustc::session::search_paths::SearchPath;
1517
use rustc_driver;
1618
use rustc_target::spec::TargetTriple;
@@ -19,8 +21,8 @@ use syntax::edition::{Edition, DEFAULT_EDITION};
1921
use crate::core::new_handler;
2022
use crate::externalfiles::ExternalHtml;
2123
use crate::html;
22-
use crate::html::{static_files};
23-
use crate::html::markdown::{IdMap};
24+
use crate::html::markdown::IdMap;
25+
use crate::html::static_files;
2426
use crate::opts;
2527
use crate::passes::{self, DefaultPassOption};
2628
use crate::theme;
@@ -29,7 +31,6 @@ use crate::theme;
2931
#[derive(Clone)]
3032
pub struct Options {
3133
// Basic options / Options passed directly to rustc
32-
3334
/// The crate root or Markdown file to load.
3435
pub input: PathBuf,
3536
/// The name of the crate being documented.
@@ -72,7 +73,6 @@ pub struct Options {
7273
pub lint_cap: Option<Level>,
7374

7475
// Options specific to running doctests
75-
7676
/// Whether we should run doctests instead of generating docs.
7777
pub should_test: bool,
7878
/// List of arguments to pass to the test harness, if running tests.
@@ -94,7 +94,6 @@ pub struct Options {
9494
pub test_builder: Option<PathBuf>,
9595

9696
// Options that affect the documentation process
97-
9897
/// The selected default set of passes to use.
9998
///
10099
/// Be aware: This option can come both from the CLI and from crate attributes!
@@ -111,7 +110,6 @@ pub struct Options {
111110
pub show_coverage: bool,
112111

113112
// Options that alter generated documentation pages
114-
115113
/// Crate version to note on the sidebar of generated docs.
116114
pub crate_version: Option<String>,
117115
/// Collected options specific to outputting final pages.
@@ -124,9 +122,7 @@ impl fmt::Debug for Options {
124122

125123
impl<'a> fmt::Debug for FmtExterns<'a> {
126124
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
127-
f.debug_map()
128-
.entries(self.0.iter())
129-
.finish()
125+
f.debug_map().entries(self.0.iter()).finish()
130126
}
131127
}
132128

@@ -208,7 +204,6 @@ pub struct RenderOptions {
208204
pub static_root_path: Option<String>,
209205

210206
// Options specific to reading standalone Markdown files
211-
212207
/// Whether to generate a table of contents on the output file when reading a standalone
213208
/// Markdown file.
214209
pub markdown_no_toc: bool,
@@ -274,10 +269,12 @@ impl Options {
274269
let codegen_options = build_codegen_options(matches, error_format);
275270
let debugging_options = build_debugging_options(matches, error_format);
276271

277-
let diag = new_handler(error_format,
278-
None,
279-
debugging_options.treat_err_as_bug,
280-
debugging_options.ui_testing);
272+
let diag = new_handler(
273+
error_format,
274+
None,
275+
debugging_options.treat_err_as_bug,
276+
debugging_options.ui_testing,
277+
);
281278

282279
// check for deprecated options
283280
check_deprecated_options(&matches, &diag);
@@ -317,7 +314,9 @@ impl Options {
317314
}
318315
let input = PathBuf::from(&matches.free[0]);
319316

320-
let libs = matches.opt_strs("L").iter()
317+
let libs = matches
318+
.opt_strs("L")
319+
.iter()
321320
.map(|s| SearchPath::from_cli_opt(s, error_format))
322321
.collect();
323322
let externs = parse_externs(&matches, &debugging_options, error_format);
@@ -330,16 +329,13 @@ impl Options {
330329
};
331330

332331
let test_args = matches.opt_strs("test-args");
333-
let test_args: Vec<String> = test_args.iter()
334-
.flat_map(|s| s.split_whitespace())
335-
.map(|s| s.to_string())
336-
.collect();
332+
let test_args: Vec<String> =
333+
test_args.iter().flat_map(|s| s.split_whitespace()).map(|s| s.to_string()).collect();
337334

338335
let should_test = matches.opt_present("test");
339336

340-
let output = matches.opt_str("o")
341-
.map(|s| PathBuf::from(&s))
342-
.unwrap_or_else(|| PathBuf::from("doc"));
337+
let output =
338+
matches.opt_str("o").map(|s| PathBuf::from(&s)).unwrap_or_else(|| PathBuf::from("doc"));
343339
let cfgs = matches.opt_strs("cfg");
344340

345341
let extension_css = matches.opt_str("e").map(|s| PathBuf::from(&s));
@@ -355,31 +351,36 @@ impl Options {
355351
if matches.opt_present("theme") {
356352
let paths = theme::load_css_paths(static_files::themes::LIGHT.as_bytes());
357353

358-
for (theme_file, theme_s) in matches.opt_strs("theme")
359-
.iter()
360-
.map(|s| (PathBuf::from(&s), s.to_owned())) {
354+
for (theme_file, theme_s) in
355+
matches.opt_strs("theme").iter().map(|s| (PathBuf::from(&s), s.to_owned()))
356+
{
361357
if !theme_file.is_file() {
362358
diag.struct_err(&format!("invalid argument: \"{}\"", theme_s))
363359
.help("arguments to --theme must be files")
364360
.emit();
365361
return Err(1);
366362
}
367363
if theme_file.extension() != Some(OsStr::new("css")) {
368-
diag.struct_err(&format!("invalid argument: \"{}\"", theme_s))
369-
.emit();
364+
diag.struct_err(&format!("invalid argument: \"{}\"", theme_s)).emit();
370365
return Err(1);
371366
}
372367
let (success, ret) = theme::test_theme_against(&theme_file, &paths, &diag);
373368
if !success {
374369
diag.struct_err(&format!("error loading theme file: \"{}\"", theme_s)).emit();
375370
return Err(1);
376371
} else if !ret.is_empty() {
377-
diag.struct_warn(&format!("theme file \"{}\" is missing CSS rules from the \
378-
default theme", theme_s))
379-
.warn("the theme may appear incorrect when loaded")
380-
.help(&format!("to see what rules are missing, call `rustdoc \
381-
--check-theme \"{}\"`", theme_s))
382-
.emit();
372+
diag.struct_warn(&format!(
373+
"theme file \"{}\" is missing CSS rules from the \
374+
default theme",
375+
theme_s
376+
))
377+
.warn("the theme may appear incorrect when loaded")
378+
.help(&format!(
379+
"to see what rules are missing, call `rustdoc \
380+
--check-theme \"{}\"`",
381+
theme_s
382+
))
383+
.emit();
383384
}
384385
themes.push(theme_file);
385386
}
@@ -400,12 +401,16 @@ impl Options {
400401
let mut id_map = html::markdown::IdMap::new();
401402
id_map.populate(html::render::initial_ids());
402403
let external_html = match ExternalHtml::load(
403-
&matches.opt_strs("html-in-header"),
404-
&matches.opt_strs("html-before-content"),
405-
&matches.opt_strs("html-after-content"),
406-
&matches.opt_strs("markdown-before-content"),
407-
&matches.opt_strs("markdown-after-content"),
408-
&diag, &mut id_map, edition, &None) {
404+
&matches.opt_strs("html-in-header"),
405+
&matches.opt_strs("html-before-content"),
406+
&matches.opt_strs("html-after-content"),
407+
&matches.opt_strs("markdown-before-content"),
408+
&matches.opt_strs("markdown-after-content"),
409+
&diag,
410+
&mut id_map,
411+
edition,
412+
&None,
413+
) {
409414
Some(eh) => eh,
410415
None => return Err(3),
411416
};
@@ -434,15 +439,14 @@ impl Options {
434439
}
435440
}
436441

437-
let target = matches.opt_str("target").map_or(
438-
TargetTriple::from_triple(host_triple()),
439-
|target| {
440-
if target.ends_with(".json") {
441-
TargetTriple::TargetPath(PathBuf::from(target))
442-
} else {
443-
TargetTriple::TargetTriple(target)
444-
}
445-
});
442+
let target =
443+
matches.opt_str("target").map_or(TargetTriple::from_triple(host_triple()), |target| {
444+
if target.ends_with(".json") {
445+
TargetTriple::TargetPath(PathBuf::from(target))
446+
} else {
447+
TargetTriple::TargetTriple(target)
448+
}
449+
});
446450

447451
let show_coverage = matches.opt_present("show-coverage");
448452
let document_private = matches.opt_present("document-private-items");
@@ -462,7 +466,7 @@ impl Options {
462466

463467
let crate_types = match parse_crate_types_from_list(matches.opt_strs("crate-type")) {
464468
Ok(types) => types,
465-
Err(e) =>{
469+
Err(e) => {
466470
diag.struct_err(&format!("unknown crate type: {}", e)).emit();
467471
return Err(1);
468472
}
@@ -547,30 +551,24 @@ impl Options {
547551
markdown_playground_url,
548552
generate_search_filter,
549553
generate_redirect_pages,
550-
}
554+
},
551555
})
552556
}
553557

554558
/// Returns `true` if the file given as `self.input` is a Markdown file.
555559
pub fn markdown_input(&self) -> bool {
556-
self.input.extension()
557-
.map_or(false, |e| e == "md" || e == "markdown")
560+
self.input.extension().map_or(false, |e| e == "md" || e == "markdown")
558561
}
559562
}
560563

561564
/// Prints deprecation warnings for deprecated options
562565
fn check_deprecated_options(matches: &getopts::Matches, diag: &errors::Handler) {
563-
let deprecated_flags = [
564-
"input-format",
565-
"output-format",
566-
"no-defaults",
567-
"passes",
568-
];
566+
let deprecated_flags = ["input-format", "output-format", "no-defaults", "passes"];
569567

570568
for flag in deprecated_flags.iter() {
571569
if matches.opt_present(flag) {
572-
let mut err = diag.struct_warn(&format!("the '{}' flag is considered deprecated",
573-
flag));
570+
let mut err =
571+
diag.struct_warn(&format!("the '{}' flag is considered deprecated", flag));
574572
err.warn("please see https://github.com/rust-lang/rust/issues/44136");
575573

576574
if *flag == "no-defaults" {
@@ -581,10 +579,7 @@ fn check_deprecated_options(matches: &getopts::Matches, diag: &errors::Handler)
581579
}
582580
}
583581

584-
let removed_flags = [
585-
"plugins",
586-
"plugin-path",
587-
];
582+
let removed_flags = ["plugins", "plugin-path"];
588583

589584
for &flag in removed_flags.iter() {
590585
if matches.opt_present(flag) {

0 commit comments

Comments
 (0)