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