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