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