]> git.lizzy.rs Git - rust.git/blob - src/librustdoc/lib.rs
Rollup merge of #50246 - nnethercote:no-dump_allocs, r=Mark-Simulacrum
[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 #![feature(ascii_ctype)]
17 #![feature(rustc_private)]
18 #![feature(box_patterns)]
19 #![feature(box_syntax)]
20 #![feature(fs_read_write)]
21 #![feature(set_stdio)]
22 #![feature(slice_sort_by_cached_key)]
23 #![feature(test)]
24 #![feature(vec_remove_item)]
25 #![feature(entry_and_modify)]
26 #![feature(dyn_trait)]
27
28 extern crate arena;
29 extern crate getopts;
30 extern crate env_logger;
31 extern crate rustc;
32 extern crate rustc_data_structures;
33 extern crate rustc_const_math;
34 extern crate rustc_trans_utils;
35 extern crate rustc_driver;
36 extern crate rustc_resolve;
37 extern crate rustc_lint;
38 extern crate rustc_metadata;
39 extern crate rustc_target;
40 extern crate rustc_typeck;
41 extern crate serialize;
42 #[macro_use] extern crate syntax;
43 extern crate syntax_pos;
44 extern crate test as testing;
45 #[macro_use] extern crate log;
46 extern crate rustc_errors as errors;
47 extern crate pulldown_cmark;
48 extern crate tempdir;
49
50 extern crate serialize as rustc_serialize; // used by deriving
51
52 use errors::ColorConfig;
53
54 use std::collections::{BTreeMap, BTreeSet};
55 use std::default::Default;
56 use std::env;
57 use std::fmt::Display;
58 use std::io;
59 use std::io::Write;
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::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              print_error(format!("Argument {} is not valid Unicode: {:?}", i, arg));
120         }).ok())
121         .collect()
122 }
123
124 fn stable<F>(name: &'static str, f: F) -> RustcOptGroup
125     where F: Fn(&mut getopts::Options) -> &mut getopts::Options + 'static
126 {
127     RustcOptGroup::stable(name, f)
128 }
129
130 fn unstable<F>(name: &'static str, f: F) -> RustcOptGroup
131     where F: Fn(&mut getopts::Options) -> &mut getopts::Options + 'static
132 {
133     RustcOptGroup::unstable(name, f)
134 }
135
136 pub fn opts() -> Vec<RustcOptGroup> {
137     vec![
138         stable("h", |o| o.optflag("h", "help", "show this help message")),
139         stable("V", |o| o.optflag("V", "version", "print rustdoc's version")),
140         stable("v", |o| o.optflag("v", "verbose", "use verbose output")),
141         stable("r", |o| {
142             o.optopt("r", "input-format", "the input type of the specified file",
143                      "[rust]")
144         }),
145         stable("w", |o| {
146             o.optopt("w", "output-format", "the output type to write", "[html]")
147         }),
148         stable("o", |o| o.optopt("o", "output", "where to place the output", "PATH")),
149         stable("crate-name", |o| {
150             o.optopt("", "crate-name", "specify the name of this crate", "NAME")
151         }),
152         stable("L", |o| {
153             o.optmulti("L", "library-path", "directory to add to crate search path",
154                        "DIR")
155         }),
156         stable("cfg", |o| o.optmulti("", "cfg", "pass a --cfg to rustc", "")),
157         stable("extern", |o| {
158             o.optmulti("", "extern", "pass an --extern to rustc", "NAME=PATH")
159         }),
160         stable("plugin-path", |o| {
161             o.optmulti("", "plugin-path", "directory to load plugins from", "DIR")
162         }),
163         stable("C", |o| {
164             o.optmulti("C", "codegen", "pass a codegen option to rustc", "OPT[=VALUE]")
165         }),
166         stable("passes", |o| {
167             o.optmulti("", "passes",
168                        "list of passes to also run, you might want \
169                         to pass it multiple times; a value of `list` \
170                         will print available passes",
171                        "PASSES")
172         }),
173         stable("plugins", |o| {
174             o.optmulti("", "plugins", "space separated list of plugins to also load",
175                        "PLUGINS")
176         }),
177         stable("no-default", |o| {
178             o.optflag("", "no-defaults", "don't run the default passes")
179         }),
180         stable("document-private-items", |o| {
181             o.optflag("", "document-private-items", "document private items")
182         }),
183         stable("test", |o| o.optflag("", "test", "run code examples as tests")),
184         stable("test-args", |o| {
185             o.optmulti("", "test-args", "arguments to pass to the test runner",
186                        "ARGS")
187         }),
188         stable("target", |o| o.optopt("", "target", "target triple to document", "TRIPLE")),
189         stable("markdown-css", |o| {
190             o.optmulti("", "markdown-css",
191                        "CSS files to include via <link> in a rendered Markdown file",
192                        "FILES")
193         }),
194         stable("html-in-header", |o|  {
195             o.optmulti("", "html-in-header",
196                        "files to include inline in the <head> section of a rendered Markdown file \
197                         or generated documentation",
198                        "FILES")
199         }),
200         stable("html-before-content", |o| {
201             o.optmulti("", "html-before-content",
202                        "files to include inline between <body> and the content of a rendered \
203                         Markdown file or generated documentation",
204                        "FILES")
205         }),
206         stable("html-after-content", |o| {
207             o.optmulti("", "html-after-content",
208                        "files to include inline between the content and </body> of a rendered \
209                         Markdown file or generated documentation",
210                        "FILES")
211         }),
212         unstable("markdown-before-content", |o| {
213             o.optmulti("", "markdown-before-content",
214                        "files to include inline between <body> and the content of a rendered \
215                         Markdown file or generated documentation",
216                        "FILES")
217         }),
218         unstable("markdown-after-content", |o| {
219             o.optmulti("", "markdown-after-content",
220                        "files to include inline between the content and </body> of a rendered \
221                         Markdown file or generated documentation",
222                        "FILES")
223         }),
224         stable("markdown-playground-url", |o| {
225             o.optopt("", "markdown-playground-url",
226                      "URL to send code snippets to", "URL")
227         }),
228         stable("markdown-no-toc", |o| {
229             o.optflag("", "markdown-no-toc", "don't include table of contents")
230         }),
231         stable("e", |o| {
232             o.optopt("e", "extend-css",
233                      "To add some CSS rules with a given file to generate doc with your \
234                       own theme. However, your theme might break if the rustdoc's generated HTML \
235                       changes, so be careful!", "PATH")
236         }),
237         unstable("Z", |o| {
238             o.optmulti("Z", "",
239                        "internal and debugging options (only on nightly build)", "FLAG")
240         }),
241         stable("sysroot", |o| {
242             o.optopt("", "sysroot", "Override the system root", "PATH")
243         }),
244         unstable("playground-url", |o| {
245             o.optopt("", "playground-url",
246                      "URL to send code snippets to, may be reset by --markdown-playground-url \
247                       or `#![doc(html_playground_url=...)]`",
248                      "URL")
249         }),
250         unstable("display-warnings", |o| {
251             o.optflag("", "display-warnings", "to print code warnings when testing doc")
252         }),
253         unstable("crate-version", |o| {
254             o.optopt("", "crate-version", "crate version to print into documentation", "VERSION")
255         }),
256         unstable("linker", |o| {
257             o.optopt("", "linker", "linker used for building executable test code", "PATH")
258         }),
259         unstable("sort-modules-by-appearance", |o| {
260             o.optflag("", "sort-modules-by-appearance", "sort modules by where they appear in the \
261                                                          program, rather than alphabetically")
262         }),
263         unstable("themes", |o| {
264             o.optmulti("", "themes",
265                        "additional themes which will be added to the generated docs",
266                        "FILES")
267         }),
268         unstable("theme-checker", |o| {
269             o.optmulti("", "theme-checker",
270                        "check if given theme is valid",
271                        "FILES")
272         }),
273         unstable("resource-suffix", |o| {
274             o.optopt("",
275                      "resource-suffix",
276                      "suffix to add to CSS and JavaScript files, e.g. \"light.css\" will become \
277                       \"light-suffix.css\"",
278                      "PATH")
279         }),
280         unstable("edition", |o| {
281             o.optopt("", "edition",
282                      "edition to use when compiling rust code (default: 2015)",
283                      "EDITION")
284         }),
285         unstable("color", |o| {
286             o.optopt("",
287                      "color",
288                      "Configure coloring of output:
289                                           auto   = colorize, if output goes to a tty (default);
290                                           always = always colorize output;
291                                           never  = never colorize output",
292                      "auto|always|never")
293         }),
294         unstable("error-format", |o| {
295             o.optopt("",
296                      "error-format",
297                      "How errors and other messages are produced",
298                      "human|json|short")
299         }),
300     ]
301 }
302
303 pub fn usage(argv0: &str) {
304     let mut options = getopts::Options::new();
305     for option in opts() {
306         (option.apply)(&mut options);
307     }
308     println!("{}", options.usage(&format!("{} [options] <input>", argv0)));
309 }
310
311 pub fn main_args(args: &[String]) -> isize {
312     let mut options = getopts::Options::new();
313     for option in opts() {
314         (option.apply)(&mut options);
315     }
316     let matches = match options.parse(&args[1..]) {
317         Ok(m) => m,
318         Err(err) => {
319             print_error(err);
320             return 1;
321         }
322     };
323     // Check for unstable options.
324     nightly_options::check_nightly_options(&matches, &opts());
325
326     // check for deprecated options
327     check_deprecated_options(&matches);
328
329     if matches.opt_present("h") || matches.opt_present("help") {
330         usage("rustdoc");
331         return 0;
332     } else if matches.opt_present("version") {
333         rustc_driver::version("rustdoc", &matches);
334         return 0;
335     }
336
337     if matches.opt_strs("passes") == ["list"] {
338         println!("Available passes for running rustdoc:");
339         for &(name, _, description) in passes::PASSES {
340             println!("{:>20} - {}", name, description);
341         }
342         println!("\nDefault passes for rustdoc:");
343         for &name in passes::DEFAULT_PASSES {
344             println!("{:>20}", name);
345         }
346         return 0;
347     }
348
349     let to_check = matches.opt_strs("theme-checker");
350     if !to_check.is_empty() {
351         let paths = theme::load_css_paths(include_bytes!("html/static/themes/light.css"));
352         let mut errors = 0;
353
354         println!("rustdoc: [theme-checker] Starting tests!");
355         for theme_file in to_check.iter() {
356             print!(" - Checking \"{}\"...", theme_file);
357             let (success, differences) = theme::test_theme_against(theme_file, &paths);
358             if !differences.is_empty() || !success {
359                 println!(" FAILED");
360                 errors += 1;
361                 if !differences.is_empty() {
362                     println!("{}", differences.join("\n"));
363                 }
364             } else {
365                 println!(" OK");
366             }
367         }
368         if errors != 0 {
369             return 1;
370         }
371         return 0;
372     }
373
374     if matches.free.is_empty() {
375         print_error("missing file operand");
376         return 1;
377     }
378     if matches.free.len() > 1 {
379         print_error("too many file operands");
380         return 1;
381     }
382     let input = &matches.free[0];
383
384     let color = match matches.opt_str("color").as_ref().map(|s| &s[..]) {
385         Some("auto") => ColorConfig::Auto,
386         Some("always") => ColorConfig::Always,
387         Some("never") => ColorConfig::Never,
388         None => ColorConfig::Auto,
389         Some(arg) => {
390             print_error(&format!("argument for --color must be `auto`, `always` or `never` \
391                                   (instead was `{}`)", arg));
392             return 1;
393         }
394     };
395     let error_format = match matches.opt_str("error-format").as_ref().map(|s| &s[..]) {
396         Some("human") => ErrorOutputType::HumanReadable(color),
397         Some("json") => ErrorOutputType::Json(false),
398         Some("pretty-json") => ErrorOutputType::Json(true),
399         Some("short") => ErrorOutputType::Short(color),
400         None => ErrorOutputType::HumanReadable(color),
401         Some(arg) => {
402             print_error(&format!("argument for --error-format must be `human`, `json` or \
403                                   `short` (instead was `{}`)", arg));
404             return 1;
405         }
406     };
407
408     let mut libs = SearchPaths::new();
409     for s in &matches.opt_strs("L") {
410         libs.add_path(s, error_format);
411     }
412     let externs = match parse_externs(&matches) {
413         Ok(ex) => ex,
414         Err(err) => {
415             print_error(err);
416             return 1;
417         }
418     };
419
420     let test_args = matches.opt_strs("test-args");
421     let test_args: Vec<String> = test_args.iter()
422                                           .flat_map(|s| s.split_whitespace())
423                                           .map(|s| s.to_string())
424                                           .collect();
425
426     let should_test = matches.opt_present("test");
427     let markdown_input = Path::new(input).extension()
428         .map_or(false, |e| e == "md" || e == "markdown");
429
430     let output = matches.opt_str("o").map(|s| PathBuf::from(&s));
431     let css_file_extension = matches.opt_str("e").map(|s| PathBuf::from(&s));
432     let cfgs = matches.opt_strs("cfg");
433
434     if let Some(ref p) = css_file_extension {
435         if !p.is_file() {
436             writeln!(
437                 &mut io::stderr(),
438                 "rustdoc: option --extend-css argument must be a file."
439             ).unwrap();
440             return 1;
441         }
442     }
443
444     let mut themes = Vec::new();
445     if matches.opt_present("themes") {
446         let paths = theme::load_css_paths(include_bytes!("html/static/themes/light.css"));
447
448         for (theme_file, theme_s) in matches.opt_strs("themes")
449                                             .iter()
450                                             .map(|s| (PathBuf::from(&s), s.to_owned())) {
451             if !theme_file.is_file() {
452                 println!("rustdoc: option --themes arguments must all be files");
453                 return 1;
454             }
455             let (success, ret) = theme::test_theme_against(&theme_file, &paths);
456             if !success || !ret.is_empty() {
457                 println!("rustdoc: invalid theme: \"{}\"", theme_s);
458                 println!("         Check what's wrong with the \"theme-checker\" option");
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")) {
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             print_error("could not parse edition");
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)
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")),
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         info!("going to format");
515         match output_format.as_ref().map(|s| &**s) {
516             Some("html") | None => {
517                 html::render::run(krate, &external_html, playground_url,
518                                   output.unwrap_or(PathBuf::from("doc")),
519                                   resource_suffix.unwrap_or(String::new()),
520                                   passes.into_iter().collect(),
521                                   css_file_extension,
522                                   renderinfo,
523                                   sort_modules_alphabetically,
524                                   themes)
525                     .expect("failed to generate documentation");
526                 0
527             }
528             Some(s) => {
529                 print_error(format!("unknown output format: {}", s));
530                 1
531             }
532         }
533     });
534     res.unwrap_or_else(|s| {
535         print_error(format!("input error: {}", s));
536         1
537     })
538 }
539
540 /// Prints an uniformized error message on the standard error output
541 fn print_error<T>(error_message: T) where T: Display {
542     writeln!(
543         &mut io::stderr(),
544         "rustdoc: {}\nTry 'rustdoc --help' for more information.",
545         error_message
546     ).unwrap();
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) {
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             eprintln!("WARNING: the '{}' flag is considered deprecated", flag);
728             eprintln!("WARNING: please see https://github.com/rust-lang/rust/issues/44136");
729         }
730     }
731
732     if matches.opt_present("no-defaults") {
733         eprintln!("WARNING: (you may want to use --document-private-items)");
734     }
735 }