]> git.lizzy.rs Git - rust.git/blob - src/librustdoc/lib.rs
Auto merge of #50541 - QuietMisdreavus:rustdoc-errors, r=GuillaumeGomez
[rust.git] / src / librustdoc / lib.rs
1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
12        html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
13        html_root_url = "https://doc.rust-lang.org/nightly/",
14        html_playground_url = "https://play.rust-lang.org/")]
15
16 #![cfg_attr(stage0, feature(dyn_trait))]
17
18 #![feature(ascii_ctype)]
19 #![feature(rustc_private)]
20 #![feature(box_patterns)]
21 #![feature(box_syntax)]
22 #![feature(fs_read_write)]
23 #![feature(set_stdio)]
24 #![feature(slice_sort_by_cached_key)]
25 #![feature(test)]
26 #![feature(vec_remove_item)]
27 #![feature(entry_and_modify)]
28
29 #![recursion_limit="256"]
30
31 extern crate arena;
32 extern crate getopts;
33 extern crate env_logger;
34 extern crate rustc;
35 extern crate rustc_data_structures;
36 extern crate rustc_trans_utils;
37 extern crate rustc_driver;
38 extern crate rustc_resolve;
39 extern crate rustc_lint;
40 extern crate rustc_metadata;
41 extern crate rustc_target;
42 extern crate rustc_typeck;
43 extern crate serialize;
44 #[macro_use] extern crate syntax;
45 extern crate syntax_pos;
46 extern crate test as testing;
47 #[macro_use] extern crate log;
48 extern crate rustc_errors as errors;
49 extern crate pulldown_cmark;
50 extern crate tempdir;
51 extern crate minifier;
52
53 extern crate serialize as rustc_serialize; // used by deriving
54
55 use errors::ColorConfig;
56
57 use std::collections::{BTreeMap, BTreeSet};
58 use std::default::Default;
59 use std::env;
60 use std::path::{Path, PathBuf};
61 use std::process;
62 use std::sync::mpsc::channel;
63
64 use syntax::edition::Edition;
65 use externalfiles::ExternalHtml;
66 use rustc::session::{early_warn, early_error};
67 use rustc::session::search_paths::SearchPaths;
68 use rustc::session::config::{ErrorOutputType, RustcOptGroup, Externs, CodegenOptions};
69 use rustc::session::config::{nightly_options, build_codegen_options};
70 use rustc_target::spec::TargetTriple;
71
72 #[macro_use]
73 pub mod externalfiles;
74
75 pub mod clean;
76 pub mod core;
77 pub mod doctree;
78 pub mod fold;
79 pub mod html {
80     pub mod highlight;
81     pub mod escape;
82     pub mod item_type;
83     pub mod format;
84     pub mod layout;
85     pub mod markdown;
86     pub mod render;
87     pub mod toc;
88 }
89 pub mod markdown;
90 pub mod passes;
91 pub mod plugins;
92 pub mod visit_ast;
93 pub mod visit_lib;
94 pub mod test;
95 pub mod theme;
96
97 use clean::AttributesExt;
98
99 struct Output {
100     krate: clean::Crate,
101     renderinfo: html::render::RenderInfo,
102     passes: Vec<String>,
103 }
104
105 pub fn main() {
106     const STACK_SIZE: usize = 32_000_000; // 32MB
107     rustc_driver::set_sigpipe_handler();
108     env_logger::init();
109     let res = std::thread::Builder::new().stack_size(STACK_SIZE).spawn(move || {
110         syntax::with_globals(move || {
111             get_args().map(|args| main_args(&args)).unwrap_or(1)
112         })
113     }).unwrap().join().unwrap_or(101);
114     process::exit(res as i32);
115 }
116
117 fn get_args() -> Option<Vec<String>> {
118     env::args_os().enumerate()
119         .map(|(i, arg)| arg.into_string().map_err(|arg| {
120              early_warn(ErrorOutputType::default(),
121                         &format!("Argument {} is not valid Unicode: {:?}", i, arg));
122         }).ok())
123         .collect()
124 }
125
126 fn stable<F>(name: &'static str, f: F) -> RustcOptGroup
127     where F: Fn(&mut getopts::Options) -> &mut getopts::Options + 'static
128 {
129     RustcOptGroup::stable(name, f)
130 }
131
132 fn unstable<F>(name: &'static str, f: F) -> RustcOptGroup
133     where F: Fn(&mut getopts::Options) -> &mut getopts::Options + 'static
134 {
135     RustcOptGroup::unstable(name, f)
136 }
137
138 pub fn opts() -> Vec<RustcOptGroup> {
139     vec![
140         stable("h", |o| o.optflag("h", "help", "show this help message")),
141         stable("V", |o| o.optflag("V", "version", "print rustdoc's version")),
142         stable("v", |o| o.optflag("v", "verbose", "use verbose output")),
143         stable("r", |o| {
144             o.optopt("r", "input-format", "the input type of the specified file",
145                      "[rust]")
146         }),
147         stable("w", |o| {
148             o.optopt("w", "output-format", "the output type to write", "[html]")
149         }),
150         stable("o", |o| o.optopt("o", "output", "where to place the output", "PATH")),
151         stable("crate-name", |o| {
152             o.optopt("", "crate-name", "specify the name of this crate", "NAME")
153         }),
154         stable("L", |o| {
155             o.optmulti("L", "library-path", "directory to add to crate search path",
156                        "DIR")
157         }),
158         stable("cfg", |o| o.optmulti("", "cfg", "pass a --cfg to rustc", "")),
159         stable("extern", |o| {
160             o.optmulti("", "extern", "pass an --extern to rustc", "NAME=PATH")
161         }),
162         stable("plugin-path", |o| {
163             o.optmulti("", "plugin-path", "directory to load plugins from", "DIR")
164         }),
165         stable("C", |o| {
166             o.optmulti("C", "codegen", "pass a codegen option to rustc", "OPT[=VALUE]")
167         }),
168         stable("passes", |o| {
169             o.optmulti("", "passes",
170                        "list of passes to also run, you might want \
171                         to pass it multiple times; a value of `list` \
172                         will print available passes",
173                        "PASSES")
174         }),
175         stable("plugins", |o| {
176             o.optmulti("", "plugins", "space separated list of plugins to also load",
177                        "PLUGINS")
178         }),
179         stable("no-default", |o| {
180             o.optflag("", "no-defaults", "don't run the default passes")
181         }),
182         stable("document-private-items", |o| {
183             o.optflag("", "document-private-items", "document private items")
184         }),
185         stable("test", |o| o.optflag("", "test", "run code examples as tests")),
186         stable("test-args", |o| {
187             o.optmulti("", "test-args", "arguments to pass to the test runner",
188                        "ARGS")
189         }),
190         stable("target", |o| o.optopt("", "target", "target triple to document", "TRIPLE")),
191         stable("markdown-css", |o| {
192             o.optmulti("", "markdown-css",
193                        "CSS files to include via <link> in a rendered Markdown file",
194                        "FILES")
195         }),
196         stable("html-in-header", |o|  {
197             o.optmulti("", "html-in-header",
198                        "files to include inline in the <head> section of a rendered Markdown file \
199                         or generated documentation",
200                        "FILES")
201         }),
202         stable("html-before-content", |o| {
203             o.optmulti("", "html-before-content",
204                        "files to include inline between <body> and the content of a rendered \
205                         Markdown file or generated documentation",
206                        "FILES")
207         }),
208         stable("html-after-content", |o| {
209             o.optmulti("", "html-after-content",
210                        "files to include inline between the content and </body> of a rendered \
211                         Markdown file or generated documentation",
212                        "FILES")
213         }),
214         unstable("markdown-before-content", |o| {
215             o.optmulti("", "markdown-before-content",
216                        "files to include inline between <body> and the content of a rendered \
217                         Markdown file or generated documentation",
218                        "FILES")
219         }),
220         unstable("markdown-after-content", |o| {
221             o.optmulti("", "markdown-after-content",
222                        "files to include inline between the content and </body> of a rendered \
223                         Markdown file or generated documentation",
224                        "FILES")
225         }),
226         stable("markdown-playground-url", |o| {
227             o.optopt("", "markdown-playground-url",
228                      "URL to send code snippets to", "URL")
229         }),
230         stable("markdown-no-toc", |o| {
231             o.optflag("", "markdown-no-toc", "don't include table of contents")
232         }),
233         stable("e", |o| {
234             o.optopt("e", "extend-css",
235                      "To add some CSS rules with a given file to generate doc with your \
236                       own theme. However, your theme might break if the rustdoc's generated HTML \
237                       changes, so be careful!", "PATH")
238         }),
239         unstable("Z", |o| {
240             o.optmulti("Z", "",
241                        "internal and debugging options (only on nightly build)", "FLAG")
242         }),
243         stable("sysroot", |o| {
244             o.optopt("", "sysroot", "Override the system root", "PATH")
245         }),
246         unstable("playground-url", |o| {
247             o.optopt("", "playground-url",
248                      "URL to send code snippets to, may be reset by --markdown-playground-url \
249                       or `#![doc(html_playground_url=...)]`",
250                      "URL")
251         }),
252         unstable("display-warnings", |o| {
253             o.optflag("", "display-warnings", "to print code warnings when testing doc")
254         }),
255         unstable("crate-version", |o| {
256             o.optopt("", "crate-version", "crate version to print into documentation", "VERSION")
257         }),
258         unstable("linker", |o| {
259             o.optopt("", "linker", "linker used for building executable test code", "PATH")
260         }),
261         unstable("sort-modules-by-appearance", |o| {
262             o.optflag("", "sort-modules-by-appearance", "sort modules by where they appear in the \
263                                                          program, rather than alphabetically")
264         }),
265         unstable("themes", |o| {
266             o.optmulti("", "themes",
267                        "additional themes which will be added to the generated docs",
268                        "FILES")
269         }),
270         unstable("theme-checker", |o| {
271             o.optmulti("", "theme-checker",
272                        "check if given theme is valid",
273                        "FILES")
274         }),
275         unstable("resource-suffix", |o| {
276             o.optopt("",
277                      "resource-suffix",
278                      "suffix to add to CSS and JavaScript files, e.g. \"light.css\" will become \
279                       \"light-suffix.css\"",
280                      "PATH")
281         }),
282         unstable("edition", |o| {
283             o.optopt("", "edition",
284                      "edition to use when compiling rust code (default: 2015)",
285                      "EDITION")
286         }),
287         unstable("color", |o| {
288             o.optopt("",
289                      "color",
290                      "Configure coloring of output:
291                                           auto   = colorize, if output goes to a tty (default);
292                                           always = always colorize output;
293                                           never  = never colorize output",
294                      "auto|always|never")
295         }),
296         unstable("error-format", |o| {
297             o.optopt("",
298                      "error-format",
299                      "How errors and other messages are produced",
300                      "human|json|short")
301         }),
302         unstable("disable-minification", |o| {
303              o.optflag("",
304                        "disable-minification",
305                        "Disable minification applied on JS files")
306         }),
307     ]
308 }
309
310 pub fn usage(argv0: &str) {
311     let mut options = getopts::Options::new();
312     for option in opts() {
313         (option.apply)(&mut options);
314     }
315     println!("{}", options.usage(&format!("{} [options] <input>", argv0)));
316 }
317
318 pub fn main_args(args: &[String]) -> isize {
319     let mut options = getopts::Options::new();
320     for option in opts() {
321         (option.apply)(&mut options);
322     }
323     let matches = match options.parse(&args[1..]) {
324         Ok(m) => m,
325         Err(err) => {
326             early_error(ErrorOutputType::default(), &err.to_string());
327         }
328     };
329     // Check for unstable options.
330     nightly_options::check_nightly_options(&matches, &opts());
331
332     if matches.opt_present("h") || matches.opt_present("help") {
333         usage("rustdoc");
334         return 0;
335     } else if matches.opt_present("version") {
336         rustc_driver::version("rustdoc", &matches);
337         return 0;
338     }
339
340     if matches.opt_strs("passes") == ["list"] {
341         println!("Available passes for running rustdoc:");
342         for &(name, _, description) in passes::PASSES {
343             println!("{:>20} - {}", name, description);
344         }
345         println!("\nDefault passes for rustdoc:");
346         for &name in passes::DEFAULT_PASSES {
347             println!("{:>20}", name);
348         }
349         return 0;
350     }
351
352     let color = match matches.opt_str("color").as_ref().map(|s| &s[..]) {
353         Some("auto") => ColorConfig::Auto,
354         Some("always") => ColorConfig::Always,
355         Some("never") => ColorConfig::Never,
356         None => ColorConfig::Auto,
357         Some(arg) => {
358             early_error(ErrorOutputType::default(),
359                         &format!("argument for --color must be `auto`, `always` or `never` \
360                                   (instead was `{}`)", arg));
361         }
362     };
363     let error_format = match matches.opt_str("error-format").as_ref().map(|s| &s[..]) {
364         Some("human") => ErrorOutputType::HumanReadable(color),
365         Some("json") => ErrorOutputType::Json(false),
366         Some("pretty-json") => ErrorOutputType::Json(true),
367         Some("short") => ErrorOutputType::Short(color),
368         None => ErrorOutputType::HumanReadable(color),
369         Some(arg) => {
370             early_error(ErrorOutputType::default(),
371                         &format!("argument for --error-format must be `human`, `json` or \
372                                   `short` (instead was `{}`)", arg));
373         }
374     };
375
376     let diag = core::new_handler(error_format, None);
377
378     // check for deprecated options
379     check_deprecated_options(&matches, &diag);
380
381     let to_check = matches.opt_strs("theme-checker");
382     if !to_check.is_empty() {
383         let paths = theme::load_css_paths(include_bytes!("html/static/themes/light.css"));
384         let mut errors = 0;
385
386         println!("rustdoc: [theme-checker] Starting tests!");
387         for theme_file in to_check.iter() {
388             print!(" - Checking \"{}\"...", theme_file);
389             let (success, differences) = theme::test_theme_against(theme_file, &paths, &diag);
390             if !differences.is_empty() || !success {
391                 println!(" FAILED");
392                 errors += 1;
393                 if !differences.is_empty() {
394                     println!("{}", differences.join("\n"));
395                 }
396             } else {
397                 println!(" OK");
398             }
399         }
400         if errors != 0 {
401             return 1;
402         }
403         return 0;
404     }
405
406     if matches.free.is_empty() {
407         diag.struct_err("missing file operand").emit();
408         return 1;
409     }
410     if matches.free.len() > 1 {
411         diag.struct_err("too many file operands").emit();
412         return 1;
413     }
414     let input = &matches.free[0];
415
416     let mut libs = SearchPaths::new();
417     for s in &matches.opt_strs("L") {
418         libs.add_path(s, error_format);
419     }
420     let externs = match parse_externs(&matches) {
421         Ok(ex) => ex,
422         Err(err) => {
423             diag.struct_err(&err.to_string()).emit();
424             return 1;
425         }
426     };
427
428     let test_args = matches.opt_strs("test-args");
429     let test_args: Vec<String> = test_args.iter()
430                                           .flat_map(|s| s.split_whitespace())
431                                           .map(|s| s.to_string())
432                                           .collect();
433
434     let should_test = matches.opt_present("test");
435     let markdown_input = Path::new(input).extension()
436         .map_or(false, |e| e == "md" || e == "markdown");
437
438     let output = matches.opt_str("o").map(|s| PathBuf::from(&s));
439     let css_file_extension = matches.opt_str("e").map(|s| PathBuf::from(&s));
440     let cfgs = matches.opt_strs("cfg");
441
442     if let Some(ref p) = css_file_extension {
443         if !p.is_file() {
444             diag.struct_err("option --extend-css argument must be a file").emit();
445             return 1;
446         }
447     }
448
449     let mut themes = Vec::new();
450     if matches.opt_present("themes") {
451         let paths = theme::load_css_paths(include_bytes!("html/static/themes/light.css"));
452
453         for (theme_file, theme_s) in matches.opt_strs("themes")
454                                             .iter()
455                                             .map(|s| (PathBuf::from(&s), s.to_owned())) {
456             if !theme_file.is_file() {
457                 diag.struct_err("option --themes arguments must all be files").emit();
458                 return 1;
459             }
460             let (success, ret) = theme::test_theme_against(&theme_file, &paths, &diag);
461             if !success || !ret.is_empty() {
462                 diag.struct_err(&format!("invalid theme: \"{}\"", theme_s))
463                     .help("check what's wrong with the --theme-checker option")
464                     .emit();
465                 return 1;
466             }
467             themes.push(theme_file);
468         }
469     }
470
471     let external_html = match ExternalHtml::load(
472             &matches.opt_strs("html-in-header"),
473             &matches.opt_strs("html-before-content"),
474             &matches.opt_strs("html-after-content"),
475             &matches.opt_strs("markdown-before-content"),
476             &matches.opt_strs("markdown-after-content"), &diag) {
477         Some(eh) => eh,
478         None => return 3,
479     };
480     let crate_name = matches.opt_str("crate-name");
481     let playground_url = matches.opt_str("playground-url");
482     let maybe_sysroot = matches.opt_str("sysroot").map(PathBuf::from);
483     let display_warnings = matches.opt_present("display-warnings");
484     let linker = matches.opt_str("linker").map(PathBuf::from);
485     let sort_modules_alphabetically = !matches.opt_present("sort-modules-by-appearance");
486     let resource_suffix = matches.opt_str("resource-suffix");
487     let enable_minification = !matches.opt_present("disable-minification");
488
489     let edition = matches.opt_str("edition").unwrap_or("2015".to_string());
490     let edition = match edition.parse() {
491         Ok(e) => e,
492         Err(_) => {
493             diag.struct_err("could not parse edition").emit();
494             return 1;
495         }
496     };
497
498     let cg = build_codegen_options(&matches, ErrorOutputType::default());
499
500     match (should_test, markdown_input) {
501         (true, true) => {
502             return markdown::test(input, cfgs, libs, externs, test_args, maybe_sysroot,
503                                   display_warnings, linker, edition, cg, &diag)
504         }
505         (true, false) => {
506             return test::run(Path::new(input), cfgs, libs, externs, test_args, crate_name,
507                              maybe_sysroot, display_warnings, linker, edition, cg)
508         }
509         (false, true) => return markdown::render(Path::new(input),
510                                                  output.unwrap_or(PathBuf::from("doc")),
511                                                  &matches, &external_html,
512                                                  !matches.opt_present("markdown-no-toc"), &diag),
513         (false, false) => {}
514     }
515
516     let output_format = matches.opt_str("w");
517
518     let res = acquire_input(PathBuf::from(input), externs, edition, cg, &matches, error_format,
519                             move |out| {
520         let Output { krate, passes, renderinfo } = out;
521         let diag = core::new_handler(error_format, None);
522         info!("going to format");
523         match output_format.as_ref().map(|s| &**s) {
524             Some("html") | None => {
525                 html::render::run(krate, &external_html, playground_url,
526                                   output.unwrap_or(PathBuf::from("doc")),
527                                   resource_suffix.unwrap_or(String::new()),
528                                   passes.into_iter().collect(),
529                                   css_file_extension,
530                                   renderinfo,
531                                   sort_modules_alphabetically,
532                                   themes,
533                                   enable_minification)
534                     .expect("failed to generate documentation");
535                 0
536             }
537             Some(s) => {
538                 diag.struct_err(&format!("unknown output format: {}", s)).emit();
539                 1
540             }
541         }
542     });
543     res.unwrap_or_else(|s| {
544         diag.struct_err(&format!("input error: {}", s)).emit();
545         1
546     })
547 }
548
549 /// Looks inside the command line arguments to extract the relevant input format
550 /// and files and then generates the necessary rustdoc output for formatting.
551 fn acquire_input<R, F>(input: PathBuf,
552                        externs: Externs,
553                        edition: Edition,
554                        cg: CodegenOptions,
555                        matches: &getopts::Matches,
556                        error_format: ErrorOutputType,
557                        f: F)
558                        -> Result<R, String>
559 where R: 'static + Send, F: 'static + Send + FnOnce(Output) -> R {
560     match matches.opt_str("r").as_ref().map(|s| &**s) {
561         Some("rust") => Ok(rust_input(input, externs, edition, cg, matches, error_format, f)),
562         Some(s) => Err(format!("unknown input format: {}", s)),
563         None => Ok(rust_input(input, externs, edition, cg, matches, error_format, f))
564     }
565 }
566
567 /// Extracts `--extern CRATE=PATH` arguments from `matches` and
568 /// returns a map mapping crate names to their paths or else an
569 /// error message.
570 fn parse_externs(matches: &getopts::Matches) -> Result<Externs, String> {
571     let mut externs = BTreeMap::new();
572     for arg in &matches.opt_strs("extern") {
573         let mut parts = arg.splitn(2, '=');
574         let name = parts.next().ok_or("--extern value must not be empty".to_string())?;
575         let location = parts.next()
576                                  .ok_or("--extern value must be of the format `foo=bar`"
577                                     .to_string())?;
578         let name = name.to_string();
579         externs.entry(name).or_insert_with(BTreeSet::new).insert(location.to_string());
580     }
581     Ok(Externs::new(externs))
582 }
583
584 /// Interprets the input file as a rust source file, passing it through the
585 /// compiler all the way through the analysis passes. The rustdoc output is then
586 /// generated from the cleaned AST of the crate.
587 ///
588 /// This form of input will run all of the plug/cleaning passes
589 fn rust_input<R, F>(cratefile: PathBuf,
590                     externs: Externs,
591                     edition: Edition,
592                     cg: CodegenOptions,
593                     matches: &getopts::Matches,
594                     error_format: ErrorOutputType,
595                     f: F) -> R
596 where R: 'static + Send,
597       F: 'static + Send + FnOnce(Output) -> R
598 {
599     let mut default_passes = !matches.opt_present("no-defaults");
600     let mut passes = matches.opt_strs("passes");
601     let mut plugins = matches.opt_strs("plugins");
602
603     // We hardcode in the passes here, as this is a new flag and we
604     // are generally deprecating passes.
605     if matches.opt_present("document-private-items") {
606         default_passes = false;
607
608         passes = vec![
609             String::from("collapse-docs"),
610             String::from("unindent-comments"),
611         ];
612     }
613
614     // First, parse the crate and extract all relevant information.
615     let mut paths = SearchPaths::new();
616     for s in &matches.opt_strs("L") {
617         paths.add_path(s, ErrorOutputType::default());
618     }
619     let cfgs = matches.opt_strs("cfg");
620     let triple = matches.opt_str("target").map(|target| {
621         if target.ends_with(".json") {
622             TargetTriple::TargetPath(PathBuf::from(target))
623         } else {
624             TargetTriple::TargetTriple(target)
625         }
626     });
627     let maybe_sysroot = matches.opt_str("sysroot").map(PathBuf::from);
628     let crate_name = matches.opt_str("crate-name");
629     let crate_version = matches.opt_str("crate-version");
630     let plugin_path = matches.opt_str("plugin-path");
631
632     info!("starting to run rustc");
633     let display_warnings = matches.opt_present("display-warnings");
634
635     let force_unstable_if_unmarked = matches.opt_strs("Z").iter().any(|x| {
636         *x == "force-unstable-if-unmarked"
637     });
638
639     let (tx, rx) = channel();
640
641     rustc_driver::monitor(move || syntax::with_globals(move || {
642         use rustc::session::config::Input;
643
644         let (mut krate, renderinfo) =
645             core::run_core(paths, cfgs, externs, Input::File(cratefile), triple, maybe_sysroot,
646                            display_warnings, crate_name.clone(),
647                            force_unstable_if_unmarked, edition, cg, error_format);
648
649         info!("finished with rustc");
650
651         if let Some(name) = crate_name {
652             krate.name = name
653         }
654
655         krate.version = crate_version;
656
657         // Process all of the crate attributes, extracting plugin metadata along
658         // with the passes which we are supposed to run.
659         for attr in krate.module.as_ref().unwrap().attrs.lists("doc") {
660             let name = attr.name().map(|s| s.as_str());
661             let name = name.as_ref().map(|s| &s[..]);
662             if attr.is_word() {
663                 if name == Some("no_default_passes") {
664                     default_passes = false;
665                 }
666             } else if let Some(value) = attr.value_str() {
667                 let sink = match name {
668                     Some("passes") => &mut passes,
669                     Some("plugins") => &mut plugins,
670                     _ => continue,
671                 };
672                 for p in value.as_str().split_whitespace() {
673                     sink.push(p.to_string());
674                 }
675             }
676         }
677
678         if default_passes {
679             for name in passes::DEFAULT_PASSES.iter().rev() {
680                 passes.insert(0, name.to_string());
681             }
682         }
683
684         // Load all plugins/passes into a PluginManager
685         let path = plugin_path.unwrap_or("/tmp/rustdoc/plugins".to_string());
686         let mut pm = plugins::PluginManager::new(PathBuf::from(path));
687         for pass in &passes {
688             let plugin = match passes::PASSES.iter()
689                                              .position(|&(p, ..)| {
690                                                  p == *pass
691                                              }) {
692                 Some(i) => passes::PASSES[i].1,
693                 None => {
694                     error!("unknown pass {}, skipping", *pass);
695                     continue
696                 },
697             };
698             pm.add_plugin(plugin);
699         }
700         info!("loading plugins...");
701         for pname in plugins {
702             pm.load_plugin(pname);
703         }
704
705         // Run everything!
706         info!("Executing passes/plugins");
707         let krate = pm.run_plugins(krate);
708
709         tx.send(f(Output { krate: krate, renderinfo: renderinfo, passes: passes })).unwrap();
710     }));
711     rx.recv().unwrap()
712 }
713
714 /// Prints deprecation warnings for deprecated options
715 fn check_deprecated_options(matches: &getopts::Matches, diag: &errors::Handler) {
716     let deprecated_flags = [
717        "input-format",
718        "output-format",
719        "plugin-path",
720        "plugins",
721        "no-defaults",
722        "passes",
723     ];
724
725     for flag in deprecated_flags.into_iter() {
726         if matches.opt_present(flag) {
727             let mut err = diag.struct_warn(&format!("the '{}' flag is considered deprecated",
728                                                     flag));
729             err.warn("please see https://github.com/rust-lang/rust/issues/44136");
730
731             if *flag == "no-defaults" {
732                 err.help("you may want to use --document-private-items");
733             }
734
735             err.emit();
736         }
737     }
738 }