]> git.lizzy.rs Git - rust.git/blob - src/librustdoc/lib.rs
Auto merge of #50693 - dlrobertson:fix_50493, r=petrochenkov
[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::fmt::Display;
60 use std::io;
61 use std::io::Write;
62 use std::path::{Path, PathBuf};
63 use std::process;
64 use std::sync::mpsc::channel;
65
66 use syntax::edition::Edition;
67 use externalfiles::ExternalHtml;
68 use rustc::session::search_paths::SearchPaths;
69 use rustc::session::config::{ErrorOutputType, RustcOptGroup, Externs, CodegenOptions};
70 use rustc::session::config::{nightly_options, build_codegen_options};
71 use rustc_target::spec::TargetTriple;
72
73 #[macro_use]
74 pub mod externalfiles;
75
76 pub mod clean;
77 pub mod core;
78 pub mod doctree;
79 pub mod fold;
80 pub mod html {
81     pub mod highlight;
82     pub mod escape;
83     pub mod item_type;
84     pub mod format;
85     pub mod layout;
86     pub mod markdown;
87     pub mod render;
88     pub mod toc;
89 }
90 pub mod markdown;
91 pub mod passes;
92 pub mod plugins;
93 pub mod visit_ast;
94 pub mod visit_lib;
95 pub mod test;
96 pub mod theme;
97
98 use clean::AttributesExt;
99
100 struct Output {
101     krate: clean::Crate,
102     renderinfo: html::render::RenderInfo,
103     passes: Vec<String>,
104 }
105
106 pub fn main() {
107     const STACK_SIZE: usize = 32_000_000; // 32MB
108     rustc_driver::set_sigpipe_handler();
109     env_logger::init();
110     let res = std::thread::Builder::new().stack_size(STACK_SIZE).spawn(move || {
111         syntax::with_globals(move || {
112             get_args().map(|args| main_args(&args)).unwrap_or(1)
113         })
114     }).unwrap().join().unwrap_or(101);
115     process::exit(res as i32);
116 }
117
118 fn get_args() -> Option<Vec<String>> {
119     env::args_os().enumerate()
120         .map(|(i, arg)| arg.into_string().map_err(|arg| {
121              print_error(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     ]
303 }
304
305 pub fn usage(argv0: &str) {
306     let mut options = getopts::Options::new();
307     for option in opts() {
308         (option.apply)(&mut options);
309     }
310     println!("{}", options.usage(&format!("{} [options] <input>", argv0)));
311 }
312
313 pub fn main_args(args: &[String]) -> isize {
314     let mut options = getopts::Options::new();
315     for option in opts() {
316         (option.apply)(&mut options);
317     }
318     let matches = match options.parse(&args[1..]) {
319         Ok(m) => m,
320         Err(err) => {
321             print_error(err);
322             return 1;
323         }
324     };
325     // Check for unstable options.
326     nightly_options::check_nightly_options(&matches, &opts());
327
328     // check for deprecated options
329     check_deprecated_options(&matches);
330
331     if matches.opt_present("h") || matches.opt_present("help") {
332         usage("rustdoc");
333         return 0;
334     } else if matches.opt_present("version") {
335         rustc_driver::version("rustdoc", &matches);
336         return 0;
337     }
338
339     if matches.opt_strs("passes") == ["list"] {
340         println!("Available passes for running rustdoc:");
341         for &(name, _, description) in passes::PASSES {
342             println!("{:>20} - {}", name, description);
343         }
344         println!("\nDefault passes for rustdoc:");
345         for &name in passes::DEFAULT_PASSES {
346             println!("{:>20}", name);
347         }
348         return 0;
349     }
350
351     let to_check = matches.opt_strs("theme-checker");
352     if !to_check.is_empty() {
353         let paths = theme::load_css_paths(include_bytes!("html/static/themes/light.css"));
354         let mut errors = 0;
355
356         println!("rustdoc: [theme-checker] Starting tests!");
357         for theme_file in to_check.iter() {
358             print!(" - Checking \"{}\"...", theme_file);
359             let (success, differences) = theme::test_theme_against(theme_file, &paths);
360             if !differences.is_empty() || !success {
361                 println!(" FAILED");
362                 errors += 1;
363                 if !differences.is_empty() {
364                     println!("{}", differences.join("\n"));
365                 }
366             } else {
367                 println!(" OK");
368             }
369         }
370         if errors != 0 {
371             return 1;
372         }
373         return 0;
374     }
375
376     if matches.free.is_empty() {
377         print_error("missing file operand");
378         return 1;
379     }
380     if matches.free.len() > 1 {
381         print_error("too many file operands");
382         return 1;
383     }
384     let input = &matches.free[0];
385
386     let color = match matches.opt_str("color").as_ref().map(|s| &s[..]) {
387         Some("auto") => ColorConfig::Auto,
388         Some("always") => ColorConfig::Always,
389         Some("never") => ColorConfig::Never,
390         None => ColorConfig::Auto,
391         Some(arg) => {
392             print_error(&format!("argument for --color must be `auto`, `always` or `never` \
393                                   (instead was `{}`)", arg));
394             return 1;
395         }
396     };
397     let error_format = match matches.opt_str("error-format").as_ref().map(|s| &s[..]) {
398         Some("human") => ErrorOutputType::HumanReadable(color),
399         Some("json") => ErrorOutputType::Json(false),
400         Some("pretty-json") => ErrorOutputType::Json(true),
401         Some("short") => ErrorOutputType::Short(color),
402         None => ErrorOutputType::HumanReadable(color),
403         Some(arg) => {
404             print_error(&format!("argument for --error-format must be `human`, `json` or \
405                                   `short` (instead was `{}`)", arg));
406             return 1;
407         }
408     };
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             print_error(err);
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             writeln!(
439                 &mut io::stderr(),
440                 "rustdoc: option --extend-css argument must be a file."
441             ).unwrap();
442             return 1;
443         }
444     }
445
446     let mut themes = Vec::new();
447     if matches.opt_present("themes") {
448         let paths = theme::load_css_paths(include_bytes!("html/static/themes/light.css"));
449
450         for (theme_file, theme_s) in matches.opt_strs("themes")
451                                             .iter()
452                                             .map(|s| (PathBuf::from(&s), s.to_owned())) {
453             if !theme_file.is_file() {
454                 println!("rustdoc: option --themes arguments must all be files");
455                 return 1;
456             }
457             let (success, ret) = theme::test_theme_against(&theme_file, &paths);
458             if !success || !ret.is_empty() {
459                 println!("rustdoc: invalid theme: \"{}\"", theme_s);
460                 println!("         Check what's wrong with the \"theme-checker\" option");
461                 return 1;
462             }
463             themes.push(theme_file);
464         }
465     }
466
467     let external_html = match ExternalHtml::load(
468             &matches.opt_strs("html-in-header"),
469             &matches.opt_strs("html-before-content"),
470             &matches.opt_strs("html-after-content"),
471             &matches.opt_strs("markdown-before-content"),
472             &matches.opt_strs("markdown-after-content")) {
473         Some(eh) => eh,
474         None => return 3,
475     };
476     let crate_name = matches.opt_str("crate-name");
477     let playground_url = matches.opt_str("playground-url");
478     let maybe_sysroot = matches.opt_str("sysroot").map(PathBuf::from);
479     let display_warnings = matches.opt_present("display-warnings");
480     let linker = matches.opt_str("linker").map(PathBuf::from);
481     let sort_modules_alphabetically = !matches.opt_present("sort-modules-by-appearance");
482     let resource_suffix = matches.opt_str("resource-suffix");
483
484     let edition = matches.opt_str("edition").unwrap_or("2015".to_string());
485     let edition = match edition.parse() {
486         Ok(e) => e,
487         Err(_) => {
488             print_error("could not parse edition");
489             return 1;
490         }
491     };
492
493     let cg = build_codegen_options(&matches, ErrorOutputType::default());
494
495     match (should_test, markdown_input) {
496         (true, true) => {
497             return markdown::test(input, cfgs, libs, externs, test_args, maybe_sysroot,
498                                   display_warnings, linker, edition, cg)
499         }
500         (true, false) => {
501             return test::run(Path::new(input), cfgs, libs, externs, test_args, crate_name,
502                              maybe_sysroot, display_warnings, linker, edition, cg)
503         }
504         (false, true) => return markdown::render(Path::new(input),
505                                                  output.unwrap_or(PathBuf::from("doc")),
506                                                  &matches, &external_html,
507                                                  !matches.opt_present("markdown-no-toc")),
508         (false, false) => {}
509     }
510
511     let output_format = matches.opt_str("w");
512
513     let res = acquire_input(PathBuf::from(input), externs, edition, cg, &matches, error_format,
514                             move |out| {
515         let Output { krate, passes, renderinfo } = out;
516         info!("going to format");
517         match output_format.as_ref().map(|s| &**s) {
518             Some("html") | None => {
519                 html::render::run(krate, &external_html, playground_url,
520                                   output.unwrap_or(PathBuf::from("doc")),
521                                   resource_suffix.unwrap_or(String::new()),
522                                   passes.into_iter().collect(),
523                                   css_file_extension,
524                                   renderinfo,
525                                   sort_modules_alphabetically,
526                                   themes)
527                     .expect("failed to generate documentation");
528                 0
529             }
530             Some(s) => {
531                 print_error(format!("unknown output format: {}", s));
532                 1
533             }
534         }
535     });
536     res.unwrap_or_else(|s| {
537         print_error(format!("input error: {}", s));
538         1
539     })
540 }
541
542 /// Prints an uniformized error message on the standard error output
543 fn print_error<T>(error_message: T) where T: Display {
544     writeln!(
545         &mut io::stderr(),
546         "rustdoc: {}\nTry 'rustdoc --help' for more information.",
547         error_message
548     ).unwrap();
549 }
550
551 /// Looks inside the command line arguments to extract the relevant input format
552 /// and files and then generates the necessary rustdoc output for formatting.
553 fn acquire_input<R, F>(input: PathBuf,
554                        externs: Externs,
555                        edition: Edition,
556                        cg: CodegenOptions,
557                        matches: &getopts::Matches,
558                        error_format: ErrorOutputType,
559                        f: F)
560                        -> Result<R, String>
561 where R: 'static + Send, F: 'static + Send + FnOnce(Output) -> R {
562     match matches.opt_str("r").as_ref().map(|s| &**s) {
563         Some("rust") => Ok(rust_input(input, externs, edition, cg, matches, error_format, f)),
564         Some(s) => Err(format!("unknown input format: {}", s)),
565         None => Ok(rust_input(input, externs, edition, cg, matches, error_format, f))
566     }
567 }
568
569 /// Extracts `--extern CRATE=PATH` arguments from `matches` and
570 /// returns a map mapping crate names to their paths or else an
571 /// error message.
572 fn parse_externs(matches: &getopts::Matches) -> Result<Externs, String> {
573     let mut externs = BTreeMap::new();
574     for arg in &matches.opt_strs("extern") {
575         let mut parts = arg.splitn(2, '=');
576         let name = parts.next().ok_or("--extern value must not be empty".to_string())?;
577         let location = parts.next()
578                                  .ok_or("--extern value must be of the format `foo=bar`"
579                                     .to_string())?;
580         let name = name.to_string();
581         externs.entry(name).or_insert_with(BTreeSet::new).insert(location.to_string());
582     }
583     Ok(Externs::new(externs))
584 }
585
586 /// Interprets the input file as a rust source file, passing it through the
587 /// compiler all the way through the analysis passes. The rustdoc output is then
588 /// generated from the cleaned AST of the crate.
589 ///
590 /// This form of input will run all of the plug/cleaning passes
591 fn rust_input<R, F>(cratefile: PathBuf,
592                     externs: Externs,
593                     edition: Edition,
594                     cg: CodegenOptions,
595                     matches: &getopts::Matches,
596                     error_format: ErrorOutputType,
597                     f: F) -> R
598 where R: 'static + Send,
599       F: 'static + Send + FnOnce(Output) -> R
600 {
601     let mut default_passes = !matches.opt_present("no-defaults");
602     let mut passes = matches.opt_strs("passes");
603     let mut plugins = matches.opt_strs("plugins");
604
605     // We hardcode in the passes here, as this is a new flag and we
606     // are generally deprecating passes.
607     if matches.opt_present("document-private-items") {
608         default_passes = false;
609
610         passes = vec![
611             String::from("collapse-docs"),
612             String::from("unindent-comments"),
613         ];
614     }
615
616     // First, parse the crate and extract all relevant information.
617     let mut paths = SearchPaths::new();
618     for s in &matches.opt_strs("L") {
619         paths.add_path(s, ErrorOutputType::default());
620     }
621     let cfgs = matches.opt_strs("cfg");
622     let triple = matches.opt_str("target").map(|target| {
623         if target.ends_with(".json") {
624             TargetTriple::TargetPath(PathBuf::from(target))
625         } else {
626             TargetTriple::TargetTriple(target)
627         }
628     });
629     let maybe_sysroot = matches.opt_str("sysroot").map(PathBuf::from);
630     let crate_name = matches.opt_str("crate-name");
631     let crate_version = matches.opt_str("crate-version");
632     let plugin_path = matches.opt_str("plugin-path");
633
634     info!("starting to run rustc");
635     let display_warnings = matches.opt_present("display-warnings");
636
637     let force_unstable_if_unmarked = matches.opt_strs("Z").iter().any(|x| {
638         *x == "force-unstable-if-unmarked"
639     });
640
641     let (tx, rx) = channel();
642
643     rustc_driver::monitor(move || syntax::with_globals(move || {
644         use rustc::session::config::Input;
645
646         let (mut krate, renderinfo) =
647             core::run_core(paths, cfgs, externs, Input::File(cratefile), triple, maybe_sysroot,
648                            display_warnings, crate_name.clone(),
649                            force_unstable_if_unmarked, edition, cg, error_format);
650
651         info!("finished with rustc");
652
653         if let Some(name) = crate_name {
654             krate.name = name
655         }
656
657         krate.version = crate_version;
658
659         // Process all of the crate attributes, extracting plugin metadata along
660         // with the passes which we are supposed to run.
661         for attr in krate.module.as_ref().unwrap().attrs.lists("doc") {
662             let name = attr.name().map(|s| s.as_str());
663             let name = name.as_ref().map(|s| &s[..]);
664             if attr.is_word() {
665                 if name == Some("no_default_passes") {
666                     default_passes = false;
667                 }
668             } else if let Some(value) = attr.value_str() {
669                 let sink = match name {
670                     Some("passes") => &mut passes,
671                     Some("plugins") => &mut plugins,
672                     _ => continue,
673                 };
674                 for p in value.as_str().split_whitespace() {
675                     sink.push(p.to_string());
676                 }
677             }
678         }
679
680         if default_passes {
681             for name in passes::DEFAULT_PASSES.iter().rev() {
682                 passes.insert(0, name.to_string());
683             }
684         }
685
686         // Load all plugins/passes into a PluginManager
687         let path = plugin_path.unwrap_or("/tmp/rustdoc/plugins".to_string());
688         let mut pm = plugins::PluginManager::new(PathBuf::from(path));
689         for pass in &passes {
690             let plugin = match passes::PASSES.iter()
691                                              .position(|&(p, ..)| {
692                                                  p == *pass
693                                              }) {
694                 Some(i) => passes::PASSES[i].1,
695                 None => {
696                     error!("unknown pass {}, skipping", *pass);
697                     continue
698                 },
699             };
700             pm.add_plugin(plugin);
701         }
702         info!("loading plugins...");
703         for pname in plugins {
704             pm.load_plugin(pname);
705         }
706
707         // Run everything!
708         info!("Executing passes/plugins");
709         let krate = pm.run_plugins(krate);
710
711         tx.send(f(Output { krate: krate, renderinfo: renderinfo, passes: passes })).unwrap();
712     }));
713     rx.recv().unwrap()
714 }
715
716 /// Prints deprecation warnings for deprecated options
717 fn check_deprecated_options(matches: &getopts::Matches) {
718     let deprecated_flags = [
719        "input-format",
720        "output-format",
721        "plugin-path",
722        "plugins",
723        "no-defaults",
724        "passes",
725     ];
726
727     for flag in deprecated_flags.into_iter() {
728         if matches.opt_present(flag) {
729             eprintln!("WARNING: the '{}' flag is considered deprecated", flag);
730             eprintln!("WARNING: please see https://github.com/rust-lang/rust/issues/44136");
731         }
732     }
733
734     if matches.opt_present("no-defaults") {
735         eprintln!("WARNING: (you may want to use --document-private-items)");
736     }
737 }