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