@@ -7,10 +7,12 @@ use errors;
7
7
use getopts;
8
8
use rustc:: lint:: Level ;
9
9
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 } ;
11
15
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} ;
14
16
use rustc:: session:: search_paths:: SearchPath ;
15
17
use rustc_driver;
16
18
use rustc_target:: spec:: TargetTriple ;
@@ -19,8 +21,8 @@ use syntax::edition::{Edition, DEFAULT_EDITION};
19
21
use crate :: core:: new_handler;
20
22
use crate :: externalfiles:: ExternalHtml ;
21
23
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 ;
24
26
use crate :: opts;
25
27
use crate :: passes:: { self , DefaultPassOption } ;
26
28
use crate :: theme;
@@ -29,7 +31,6 @@ use crate::theme;
29
31
#[ derive( Clone ) ]
30
32
pub struct Options {
31
33
// Basic options / Options passed directly to rustc
32
-
33
34
/// The crate root or Markdown file to load.
34
35
pub input : PathBuf ,
35
36
/// The name of the crate being documented.
@@ -72,7 +73,6 @@ pub struct Options {
72
73
pub lint_cap : Option < Level > ,
73
74
74
75
// Options specific to running doctests
75
-
76
76
/// Whether we should run doctests instead of generating docs.
77
77
pub should_test : bool ,
78
78
/// List of arguments to pass to the test harness, if running tests.
@@ -94,7 +94,6 @@ pub struct Options {
94
94
pub test_builder : Option < PathBuf > ,
95
95
96
96
// Options that affect the documentation process
97
-
98
97
/// The selected default set of passes to use.
99
98
///
100
99
/// Be aware: This option can come both from the CLI and from crate attributes!
@@ -111,7 +110,6 @@ pub struct Options {
111
110
pub show_coverage : bool ,
112
111
113
112
// Options that alter generated documentation pages
114
-
115
113
/// Crate version to note on the sidebar of generated docs.
116
114
pub crate_version : Option < String > ,
117
115
/// Collected options specific to outputting final pages.
@@ -124,9 +122,7 @@ impl fmt::Debug for Options {
124
122
125
123
impl < ' a > fmt:: Debug for FmtExterns < ' a > {
126
124
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 ( )
130
126
}
131
127
}
132
128
@@ -208,7 +204,6 @@ pub struct RenderOptions {
208
204
pub static_root_path : Option < String > ,
209
205
210
206
// Options specific to reading standalone Markdown files
211
-
212
207
/// Whether to generate a table of contents on the output file when reading a standalone
213
208
/// Markdown file.
214
209
pub markdown_no_toc : bool ,
@@ -274,10 +269,12 @@ impl Options {
274
269
let codegen_options = build_codegen_options ( matches, error_format) ;
275
270
let debugging_options = build_debugging_options ( matches, error_format) ;
276
271
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
+ ) ;
281
278
282
279
// check for deprecated options
283
280
check_deprecated_options ( & matches, & diag) ;
@@ -317,7 +314,9 @@ impl Options {
317
314
}
318
315
let input = PathBuf :: from ( & matches. free [ 0 ] ) ;
319
316
320
- let libs = matches. opt_strs ( "L" ) . iter ( )
317
+ let libs = matches
318
+ . opt_strs ( "L" )
319
+ . iter ( )
321
320
. map ( |s| SearchPath :: from_cli_opt ( s, error_format) )
322
321
. collect ( ) ;
323
322
let externs = parse_externs ( & matches, & debugging_options, error_format) ;
@@ -330,16 +329,13 @@ impl Options {
330
329
} ;
331
330
332
331
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 ( ) ;
337
334
338
335
let should_test = matches. opt_present ( "test" ) ;
339
336
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" ) ) ;
343
339
let cfgs = matches. opt_strs ( "cfg" ) ;
344
340
345
341
let extension_css = matches. opt_str ( "e" ) . map ( |s| PathBuf :: from ( & s) ) ;
@@ -355,31 +351,36 @@ impl Options {
355
351
if matches. opt_present ( "theme" ) {
356
352
let paths = theme:: load_css_paths ( static_files:: themes:: LIGHT . as_bytes ( ) ) ;
357
353
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
+ {
361
357
if !theme_file. is_file ( ) {
362
358
diag. struct_err ( & format ! ( "invalid argument: \" {}\" " , theme_s) )
363
359
. help ( "arguments to --theme must be files" )
364
360
. emit ( ) ;
365
361
return Err ( 1 ) ;
366
362
}
367
363
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 ( ) ;
370
365
return Err ( 1 ) ;
371
366
}
372
367
let ( success, ret) = theme:: test_theme_against ( & theme_file, & paths, & diag) ;
373
368
if !success {
374
369
diag. struct_err ( & format ! ( "error loading theme file: \" {}\" " , theme_s) ) . emit ( ) ;
375
370
return Err ( 1 ) ;
376
371
} 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 ( ) ;
383
384
}
384
385
themes. push ( theme_file) ;
385
386
}
@@ -400,12 +401,16 @@ impl Options {
400
401
let mut id_map = html:: markdown:: IdMap :: new ( ) ;
401
402
id_map. populate ( html:: render:: initial_ids ( ) ) ;
402
403
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
+ ) {
409
414
Some ( eh) => eh,
410
415
None => return Err ( 3 ) ,
411
416
} ;
@@ -434,15 +439,14 @@ impl Options {
434
439
}
435
440
}
436
441
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
+ } ) ;
446
450
447
451
let show_coverage = matches. opt_present ( "show-coverage" ) ;
448
452
let document_private = matches. opt_present ( "document-private-items" ) ;
@@ -462,7 +466,7 @@ impl Options {
462
466
463
467
let crate_types = match parse_crate_types_from_list ( matches. opt_strs ( "crate-type" ) ) {
464
468
Ok ( types) => types,
465
- Err ( e) =>{
469
+ Err ( e) => {
466
470
diag. struct_err ( & format ! ( "unknown crate type: {}" , e) ) . emit ( ) ;
467
471
return Err ( 1 ) ;
468
472
}
@@ -547,30 +551,24 @@ impl Options {
547
551
markdown_playground_url,
548
552
generate_search_filter,
549
553
generate_redirect_pages,
550
- }
554
+ } ,
551
555
} )
552
556
}
553
557
554
558
/// Returns `true` if the file given as `self.input` is a Markdown file.
555
559
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" )
558
561
}
559
562
}
560
563
561
564
/// Prints deprecation warnings for deprecated options
562
565
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" ] ;
569
567
570
568
for flag in deprecated_flags. iter ( ) {
571
569
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) ) ;
574
572
err. warn ( "please see https://github.com/rust-lang/rust/issues/44136" ) ;
575
573
576
574
if * flag == "no-defaults" {
@@ -581,10 +579,7 @@ fn check_deprecated_options(matches: &getopts::Matches, diag: &errors::Handler)
581
579
}
582
580
}
583
581
584
- let removed_flags = [
585
- "plugins" ,
586
- "plugin-path" ,
587
- ] ;
582
+ let removed_flags = [ "plugins" , "plugin-path" ] ;
588
583
589
584
for & flag in removed_flags. iter ( ) {
590
585
if matches. opt_present ( flag) {
0 commit comments