]> git.lizzy.rs Git - rust.git/blob - src/librustdoc/lib.rs
Auto merge of #85252 - kulikjak:fix-solaris-CI, r=Mark-Simulacrum
[rust.git] / src / librustdoc / lib.rs
1 #![doc(
2     html_root_url = "https://doc.rust-lang.org/nightly/",
3     html_playground_url = "https://play.rust-lang.org/"
4 )]
5 #![feature(rustc_private)]
6 #![feature(array_methods)]
7 #![feature(box_patterns)]
8 #![feature(box_syntax)]
9 #![feature(in_band_lifetimes)]
10 #![feature(nll)]
11 #![feature(test)]
12 #![feature(crate_visibility_modifier)]
13 #![feature(never_type)]
14 #![feature(once_cell)]
15 #![feature(type_ascription)]
16 #![feature(iter_intersperse)]
17 #![recursion_limit = "256"]
18 #![warn(rustc::internal)]
19
20 #[macro_use]
21 extern crate lazy_static;
22 #[macro_use]
23 extern crate tracing;
24
25 // N.B. these need `extern crate` even in 2018 edition
26 // because they're loaded implicitly from the sysroot.
27 // The reason they're loaded from the sysroot is because
28 // the rustdoc artifacts aren't stored in rustc's cargo target directory.
29 // So if `rustc` was specified in Cargo.toml, this would spuriously rebuild crates.
30 //
31 // Dependencies listed in Cargo.toml do not need `extern crate`.
32
33 extern crate rustc_ast;
34 extern crate rustc_ast_lowering;
35 extern crate rustc_ast_pretty;
36 extern crate rustc_attr;
37 extern crate rustc_data_structures;
38 extern crate rustc_driver;
39 extern crate rustc_errors;
40 extern crate rustc_expand;
41 extern crate rustc_feature;
42 extern crate rustc_hir;
43 extern crate rustc_hir_pretty;
44 extern crate rustc_index;
45 extern crate rustc_infer;
46 extern crate rustc_interface;
47 extern crate rustc_lexer;
48 extern crate rustc_lint;
49 extern crate rustc_lint_defs;
50 extern crate rustc_metadata;
51 extern crate rustc_middle;
52 extern crate rustc_mir;
53 extern crate rustc_parse;
54 extern crate rustc_passes;
55 extern crate rustc_resolve;
56 extern crate rustc_session;
57 extern crate rustc_span as rustc_span;
58 extern crate rustc_target;
59 extern crate rustc_trait_selection;
60 extern crate rustc_typeck;
61 extern crate test as testing;
62
63 #[cfg(feature = "jemalloc")]
64 extern crate tikv_jemalloc_sys;
65 #[cfg(feature = "jemalloc")]
66 use tikv_jemalloc_sys as jemalloc_sys;
67 #[cfg(feature = "jemalloc")]
68 extern crate tikv_jemallocator;
69 #[cfg(feature = "jemalloc")]
70 use tikv_jemallocator as jemallocator;
71
72 use std::default::Default;
73 use std::env;
74 use std::process;
75
76 use rustc_driver::{abort_on_err, describe_lints};
77 use rustc_errors::ErrorReported;
78 use rustc_interface::interface;
79 use rustc_middle::ty::TyCtxt;
80 use rustc_session::config::{make_crate_type_option, ErrorOutputType, RustcOptGroup};
81 use rustc_session::getopts;
82 use rustc_session::{early_error, early_warn};
83
84 /// A macro to create a FxHashMap.
85 ///
86 /// Example:
87 ///
88 /// ```
89 /// let letters = map!{"a" => "b", "c" => "d"};
90 /// ```
91 ///
92 /// Trailing commas are allowed.
93 /// Commas between elements are required (even if the expression is a block).
94 macro_rules! map {
95     ($( $key: expr => $val: expr ),* $(,)*) => {{
96         let mut map = ::rustc_data_structures::fx::FxHashMap::default();
97         $( map.insert($key, $val); )*
98         map
99     }}
100 }
101
102 #[macro_use]
103 mod externalfiles;
104
105 mod clean;
106 mod config;
107 mod core;
108 mod docfs;
109 mod doctree;
110 #[macro_use]
111 mod error;
112 mod doctest;
113 mod fold;
114 mod formats;
115 // used by the error-index generator, so it needs to be public
116 pub mod html;
117 mod json;
118 crate mod lint;
119 mod markdown;
120 mod passes;
121 mod theme;
122 mod visit_ast;
123 mod visit_lib;
124
125 // See docs in https://github.com/rust-lang/rust/blob/master/compiler/rustc/src/main.rs
126 // about jemallocator
127 #[cfg(feature = "jemalloc")]
128 #[global_allocator]
129 static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
130
131 pub fn main() {
132     // See docs in https://github.com/rust-lang/rust/blob/master/compiler/rustc/src/main.rs
133     // about jemalloc-sys
134     #[cfg(feature = "jemalloc")]
135     {
136         use std::os::raw::{c_int, c_void};
137
138         #[used]
139         static _F1: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::calloc;
140         #[used]
141         static _F2: unsafe extern "C" fn(*mut *mut c_void, usize, usize) -> c_int =
142             jemalloc_sys::posix_memalign;
143         #[used]
144         static _F3: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::aligned_alloc;
145         #[used]
146         static _F4: unsafe extern "C" fn(usize) -> *mut c_void = jemalloc_sys::malloc;
147         #[used]
148         static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = jemalloc_sys::realloc;
149         #[used]
150         static _F6: unsafe extern "C" fn(*mut c_void) = jemalloc_sys::free;
151
152         // On OSX, jemalloc doesn't directly override malloc/free, but instead
153         // registers itself with the allocator's zone APIs in a ctor. However,
154         // the linker doesn't seem to consider ctors as "used" when statically
155         // linking, so we need to explicitly depend on the function.
156         #[cfg(target_os = "macos")]
157         {
158             extern "C" {
159                 fn _rjem_je_zone_register();
160             }
161
162             #[used]
163             static _F7: unsafe extern "C" fn() = _rjem_je_zone_register;
164         }
165     }
166
167     rustc_driver::set_sigpipe_handler();
168     rustc_driver::install_ice_hook();
169
170     // When using CI artifacts (with `download_stage1 = true`), tracing is unconditionally built
171     // with `--features=static_max_level_info`, which disables almost all rustdoc logging. To avoid
172     // this, compile our own version of `tracing` that logs all levels.
173     // NOTE: this compiles both versions of tracing unconditionally, because
174     // - The compile time hit is not that bad, especially compared to rustdoc's incremental times, and
175     // - Otherwise, there's no warning that logging is being ignored when `download_stage1 = true`.
176     // NOTE: The reason this doesn't show double logging when `download_stage1 = false` and
177     // `debug_logging = true` is because all rustc logging goes to its version of tracing (the one
178     // in the sysroot), and all of rustdoc's logging goes to its version (the one in Cargo.toml).
179     init_logging();
180     rustc_driver::init_env_logger("RUSTDOC_LOG");
181
182     let exit_code = rustc_driver::catch_with_exit_code(|| match get_args() {
183         Some(args) => main_args(&args),
184         _ => Err(ErrorReported),
185     });
186     process::exit(exit_code);
187 }
188
189 fn init_logging() {
190     use std::io;
191
192     // FIXME remove these and use winapi 0.3 instead
193     // Duplicates: bootstrap/compile.rs, librustc_errors/emitter.rs, rustc_driver/lib.rs
194     #[cfg(unix)]
195     fn stdout_isatty() -> bool {
196         extern crate libc;
197         unsafe { libc::isatty(libc::STDOUT_FILENO) != 0 }
198     }
199
200     #[cfg(windows)]
201     fn stdout_isatty() -> bool {
202         extern crate winapi;
203         use winapi::um::consoleapi::GetConsoleMode;
204         use winapi::um::processenv::GetStdHandle;
205         use winapi::um::winbase::STD_OUTPUT_HANDLE;
206
207         unsafe {
208             let handle = GetStdHandle(STD_OUTPUT_HANDLE);
209             let mut out = 0;
210             GetConsoleMode(handle, &mut out) != 0
211         }
212     }
213
214     let color_logs = match std::env::var("RUSTDOC_LOG_COLOR") {
215         Ok(value) => match value.as_ref() {
216             "always" => true,
217             "never" => false,
218             "auto" => stdout_isatty(),
219             _ => early_error(
220                 ErrorOutputType::default(),
221                 &format!(
222                     "invalid log color value '{}': expected one of always, never, or auto",
223                     value
224                 ),
225             ),
226         },
227         Err(std::env::VarError::NotPresent) => stdout_isatty(),
228         Err(std::env::VarError::NotUnicode(_value)) => early_error(
229             ErrorOutputType::default(),
230             "non-Unicode log color value: expected one of always, never, or auto",
231         ),
232     };
233     let filter = tracing_subscriber::EnvFilter::from_env("RUSTDOC_LOG");
234     let layer = tracing_tree::HierarchicalLayer::default()
235         .with_writer(io::stderr)
236         .with_indent_lines(true)
237         .with_ansi(color_logs)
238         .with_targets(true)
239         .with_wraparound(10)
240         .with_verbose_exit(true)
241         .with_verbose_entry(true)
242         .with_indent_amount(2);
243     #[cfg(parallel_compiler)]
244     let layer = layer.with_thread_ids(true).with_thread_names(true);
245
246     use tracing_subscriber::layer::SubscriberExt;
247     let subscriber = tracing_subscriber::Registry::default().with(filter).with(layer);
248     tracing::subscriber::set_global_default(subscriber).unwrap();
249 }
250
251 fn get_args() -> Option<Vec<String>> {
252     env::args_os()
253         .enumerate()
254         .map(|(i, arg)| {
255             arg.into_string()
256                 .map_err(|arg| {
257                     early_warn(
258                         ErrorOutputType::default(),
259                         &format!("Argument {} is not valid Unicode: {:?}", i, arg),
260                     );
261                 })
262                 .ok()
263         })
264         .collect()
265 }
266
267 fn opts() -> Vec<RustcOptGroup> {
268     let stable: fn(_, fn(&mut getopts::Options) -> &mut _) -> _ = RustcOptGroup::stable;
269     let unstable: fn(_, fn(&mut getopts::Options) -> &mut _) -> _ = RustcOptGroup::unstable;
270     vec![
271         stable("h", |o| o.optflag("h", "help", "show this help message")),
272         stable("V", |o| o.optflag("V", "version", "print rustdoc's version")),
273         stable("v", |o| o.optflag("v", "verbose", "use verbose output")),
274         stable("r", |o| {
275             o.optopt("r", "input-format", "the input type of the specified file", "[rust]")
276         }),
277         stable("w", |o| o.optopt("w", "output-format", "the output type to write", "[html]")),
278         stable("o", |o| o.optopt("o", "output", "where to place the output", "PATH")),
279         stable("crate-name", |o| {
280             o.optopt("", "crate-name", "specify the name of this crate", "NAME")
281         }),
282         make_crate_type_option(),
283         stable("L", |o| {
284             o.optmulti("L", "library-path", "directory to add to crate search path", "DIR")
285         }),
286         stable("cfg", |o| o.optmulti("", "cfg", "pass a --cfg to rustc", "")),
287         stable("extern", |o| o.optmulti("", "extern", "pass an --extern to rustc", "NAME[=PATH]")),
288         unstable("extern-html-root-url", |o| {
289             o.optmulti(
290                 "",
291                 "extern-html-root-url",
292                 "base URL to use for dependencies; for example, \
293                  \"std=/doc\" links std::vec::Vec to /doc/std/vec/struct.Vec.html",
294                 "NAME=URL",
295             )
296         }),
297         stable("plugin-path", |o| o.optmulti("", "plugin-path", "removed", "DIR")),
298         stable("C", |o| {
299             o.optmulti("C", "codegen", "pass a codegen option to rustc", "OPT[=VALUE]")
300         }),
301         stable("passes", |o| {
302             o.optmulti(
303                 "",
304                 "passes",
305                 "list of passes to also run, you might want to pass it multiple times; a value of \
306                  `list` will print available passes",
307                 "PASSES",
308             )
309         }),
310         stable("plugins", |o| o.optmulti("", "plugins", "removed", "PLUGINS")),
311         stable("no-default", |o| o.optflag("", "no-defaults", "don't run the default passes")),
312         stable("document-private-items", |o| {
313             o.optflag("", "document-private-items", "document private items")
314         }),
315         unstable("document-hidden-items", |o| {
316             o.optflag("", "document-hidden-items", "document items that have doc(hidden)")
317         }),
318         stable("test", |o| o.optflag("", "test", "run code examples as tests")),
319         stable("test-args", |o| {
320             o.optmulti("", "test-args", "arguments to pass to the test runner", "ARGS")
321         }),
322         unstable("test-run-directory", |o| {
323             o.optopt(
324                 "",
325                 "test-run-directory",
326                 "The working directory in which to run tests",
327                 "PATH",
328             )
329         }),
330         stable("target", |o| o.optopt("", "target", "target triple to document", "TRIPLE")),
331         stable("markdown-css", |o| {
332             o.optmulti(
333                 "",
334                 "markdown-css",
335                 "CSS files to include via <link> in a rendered Markdown file",
336                 "FILES",
337             )
338         }),
339         stable("html-in-header", |o| {
340             o.optmulti(
341                 "",
342                 "html-in-header",
343                 "files to include inline in the <head> section of a rendered Markdown file \
344                  or generated documentation",
345                 "FILES",
346             )
347         }),
348         stable("html-before-content", |o| {
349             o.optmulti(
350                 "",
351                 "html-before-content",
352                 "files to include inline between <body> and the content of a rendered \
353                  Markdown file or generated documentation",
354                 "FILES",
355             )
356         }),
357         stable("html-after-content", |o| {
358             o.optmulti(
359                 "",
360                 "html-after-content",
361                 "files to include inline between the content and </body> of a rendered \
362                  Markdown file or generated documentation",
363                 "FILES",
364             )
365         }),
366         unstable("markdown-before-content", |o| {
367             o.optmulti(
368                 "",
369                 "markdown-before-content",
370                 "files to include inline between <body> and the content of a rendered \
371                  Markdown file or generated documentation",
372                 "FILES",
373             )
374         }),
375         unstable("markdown-after-content", |o| {
376             o.optmulti(
377                 "",
378                 "markdown-after-content",
379                 "files to include inline between the content and </body> of a rendered \
380                  Markdown file or generated documentation",
381                 "FILES",
382             )
383         }),
384         stable("markdown-playground-url", |o| {
385             o.optopt("", "markdown-playground-url", "URL to send code snippets to", "URL")
386         }),
387         stable("markdown-no-toc", |o| {
388             o.optflag("", "markdown-no-toc", "don't include table of contents")
389         }),
390         stable("e", |o| {
391             o.optopt(
392                 "e",
393                 "extend-css",
394                 "To add some CSS rules with a given file to generate doc with your \
395                  own theme. However, your theme might break if the rustdoc's generated HTML \
396                  changes, so be careful!",
397                 "PATH",
398             )
399         }),
400         unstable("Z", |o| {
401             o.optmulti("Z", "", "internal and debugging options (only on nightly build)", "FLAG")
402         }),
403         stable("sysroot", |o| o.optopt("", "sysroot", "Override the system root", "PATH")),
404         unstable("playground-url", |o| {
405             o.optopt(
406                 "",
407                 "playground-url",
408                 "URL to send code snippets to, may be reset by --markdown-playground-url \
409                  or `#![doc(html_playground_url=...)]`",
410                 "URL",
411             )
412         }),
413         unstable("display-warnings", |o| {
414             o.optflag("", "display-warnings", "to print code warnings when testing doc")
415         }),
416         stable("crate-version", |o| {
417             o.optopt("", "crate-version", "crate version to print into documentation", "VERSION")
418         }),
419         unstable("sort-modules-by-appearance", |o| {
420             o.optflag(
421                 "",
422                 "sort-modules-by-appearance",
423                 "sort modules by where they appear in the program, rather than alphabetically",
424             )
425         }),
426         stable("default-theme", |o| {
427             o.optopt(
428                 "",
429                 "default-theme",
430                 "Set the default theme. THEME should be the theme name, generally lowercase. \
431                  If an unknown default theme is specified, the builtin default is used. \
432                  The set of themes, and the rustdoc built-in default, are not stable.",
433                 "THEME",
434             )
435         }),
436         unstable("default-setting", |o| {
437             o.optmulti(
438                 "",
439                 "default-setting",
440                 "Default value for a rustdoc setting (used when \"rustdoc-SETTING\" is absent \
441                  from web browser Local Storage). If VALUE is not supplied, \"true\" is used. \
442                  Supported SETTINGs and VALUEs are not documented and not stable.",
443                 "SETTING[=VALUE]",
444             )
445         }),
446         stable("theme", |o| {
447             o.optmulti(
448                 "",
449                 "theme",
450                 "additional themes which will be added to the generated docs",
451                 "FILES",
452             )
453         }),
454         stable("check-theme", |o| {
455             o.optmulti("", "check-theme", "check if given theme is valid", "FILES")
456         }),
457         unstable("resource-suffix", |o| {
458             o.optopt(
459                 "",
460                 "resource-suffix",
461                 "suffix to add to CSS and JavaScript files, e.g., \"light.css\" will become \
462                  \"light-suffix.css\"",
463                 "PATH",
464             )
465         }),
466         stable("edition", |o| {
467             o.optopt(
468                 "",
469                 "edition",
470                 "edition to use when compiling rust code (default: 2015)",
471                 "EDITION",
472             )
473         }),
474         stable("color", |o| {
475             o.optopt(
476                 "",
477                 "color",
478                 "Configure coloring of output:
479                                           auto   = colorize, if output goes to a tty (default);
480                                           always = always colorize output;
481                                           never  = never colorize output",
482                 "auto|always|never",
483             )
484         }),
485         stable("error-format", |o| {
486             o.optopt(
487                 "",
488                 "error-format",
489                 "How errors and other messages are produced",
490                 "human|json|short",
491             )
492         }),
493         stable("json", |o| {
494             o.optopt("", "json", "Configure the structure of JSON diagnostics", "CONFIG")
495         }),
496         unstable("disable-minification", |o| {
497             o.optflag("", "disable-minification", "Disable minification applied on JS files")
498         }),
499         stable("warn", |o| o.optmulti("W", "warn", "Set lint warnings", "OPT")),
500         stable("allow", |o| o.optmulti("A", "allow", "Set lint allowed", "OPT")),
501         stable("deny", |o| o.optmulti("D", "deny", "Set lint denied", "OPT")),
502         stable("forbid", |o| o.optmulti("F", "forbid", "Set lint forbidden", "OPT")),
503         stable("cap-lints", |o| {
504             o.optmulti(
505                 "",
506                 "cap-lints",
507                 "Set the most restrictive lint level. \
508                  More restrictive lints are capped at this \
509                  level. By default, it is at `forbid` level.",
510                 "LEVEL",
511             )
512         }),
513         unstable("index-page", |o| {
514             o.optopt("", "index-page", "Markdown file to be used as index page", "PATH")
515         }),
516         unstable("enable-index-page", |o| {
517             o.optflag("", "enable-index-page", "To enable generation of the index page")
518         }),
519         unstable("static-root-path", |o| {
520             o.optopt(
521                 "",
522                 "static-root-path",
523                 "Path string to force loading static files from in output pages. \
524                  If not set, uses combinations of '../' to reach the documentation root.",
525                 "PATH",
526             )
527         }),
528         unstable("disable-per-crate-search", |o| {
529             o.optflag(
530                 "",
531                 "disable-per-crate-search",
532                 "disables generating the crate selector on the search box",
533             )
534         }),
535         unstable("persist-doctests", |o| {
536             o.optopt(
537                 "",
538                 "persist-doctests",
539                 "Directory to persist doctest executables into",
540                 "PATH",
541             )
542         }),
543         unstable("show-coverage", |o| {
544             o.optflag(
545                 "",
546                 "show-coverage",
547                 "calculate percentage of public items with documentation",
548             )
549         }),
550         unstable("enable-per-target-ignores", |o| {
551             o.optflag(
552                 "",
553                 "enable-per-target-ignores",
554                 "parse ignore-foo for ignoring doctests on a per-target basis",
555             )
556         }),
557         unstable("runtool", |o| {
558             o.optopt(
559                 "",
560                 "runtool",
561                 "",
562                 "The tool to run tests with when building for a different target than host",
563             )
564         }),
565         unstable("runtool-arg", |o| {
566             o.optmulti(
567                 "",
568                 "runtool-arg",
569                 "",
570                 "One (of possibly many) arguments to pass to the runtool",
571             )
572         }),
573         unstable("test-builder", |o| {
574             o.optopt("", "test-builder", "The rustc-like binary to use as the test builder", "PATH")
575         }),
576         unstable("check", |o| o.optflag("", "check", "Run rustdoc checks")),
577         unstable("generate-redirect-map", |o| {
578             o.optflag(
579                 "",
580                 "generate-redirect-map",
581                 "Generate JSON file at the top level instead of generating HTML redirection files",
582             )
583         }),
584         unstable("print", |o| {
585             o.optmulti("", "print", "Rustdoc information to print on stdout", "[unversioned-files]")
586         }),
587         unstable("emit", |o| {
588             o.optmulti(
589                 "",
590                 "emit",
591                 "Comma separated list of types of output for rustdoc to emit",
592                 "[unversioned-shared-resources,toolchain-shared-resources,invocation-specific]",
593             )
594         }),
595         unstable("no-run", |o| o.optflag("", "no-run", "Compile doctests without running them")),
596         unstable("show-type-layout", |o| {
597             o.optflag("", "show-type-layout", "Include the memory layout of types in the docs")
598         }),
599     ]
600 }
601
602 fn usage(argv0: &str) {
603     let mut options = getopts::Options::new();
604     for option in opts() {
605         (option.apply)(&mut options);
606     }
607     println!("{}", options.usage(&format!("{} [options] <input>", argv0)));
608     println!("    @path               Read newline separated options from `path`\n");
609     println!("More information available at https://doc.rust-lang.org/rustdoc/what-is-rustdoc.html")
610 }
611
612 /// A result type used by several functions under `main()`.
613 type MainResult = Result<(), ErrorReported>;
614
615 fn main_args(at_args: &[String]) -> MainResult {
616     let args = rustc_driver::args::arg_expand_all(at_args);
617
618     let mut options = getopts::Options::new();
619     for option in opts() {
620         (option.apply)(&mut options);
621     }
622     let matches = match options.parse(&args[1..]) {
623         Ok(m) => m,
624         Err(err) => {
625             early_error(ErrorOutputType::default(), &err.to_string());
626         }
627     };
628
629     // Note that we discard any distinction between different non-zero exit
630     // codes from `from_matches` here.
631     let options = match config::Options::from_matches(&matches) {
632         Ok(opts) => opts,
633         Err(code) => return if code == 0 { Ok(()) } else { Err(ErrorReported) },
634     };
635     rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals(
636         options.edition,
637         1, // this runs single-threaded, even in a parallel compiler
638         &None,
639         move || main_options(options),
640     )
641 }
642
643 fn wrap_return(diag: &rustc_errors::Handler, res: Result<(), String>) -> MainResult {
644     match res {
645         Ok(()) => Ok(()),
646         Err(err) => {
647             diag.struct_err(&err).emit();
648             Err(ErrorReported)
649         }
650     }
651 }
652
653 fn run_renderer<'tcx, T: formats::FormatRenderer<'tcx>>(
654     krate: clean::Crate,
655     renderopts: config::RenderOptions,
656     cache: formats::cache::Cache,
657     tcx: TyCtxt<'tcx>,
658 ) -> MainResult {
659     match formats::run_format::<T>(krate, renderopts, cache, tcx) {
660         Ok(_) => Ok(()),
661         Err(e) => {
662             let mut msg =
663                 tcx.sess.struct_err(&format!("couldn't generate documentation: {}", e.error));
664             let file = e.file.display().to_string();
665             if file.is_empty() {
666                 msg.emit()
667             } else {
668                 msg.note(&format!("failed to create or modify \"{}\"", file)).emit()
669             }
670             Err(ErrorReported)
671         }
672     }
673 }
674
675 fn main_options(options: config::Options) -> MainResult {
676     let diag = core::new_handler(options.error_format, None, &options.debugging_opts);
677
678     match (options.should_test, options.markdown_input()) {
679         (true, true) => return wrap_return(&diag, markdown::test(options)),
680         (true, false) => return doctest::run(options),
681         (false, true) => {
682             return wrap_return(
683                 &diag,
684                 markdown::render(&options.input, options.render_options, options.edition),
685             );
686         }
687         (false, false) => {}
688     }
689
690     // need to move these items separately because we lose them by the time the closure is called,
691     // but we can't create the Handler ahead of time because it's not Send
692     let show_coverage = options.show_coverage;
693     let run_check = options.run_check;
694
695     // First, parse the crate and extract all relevant information.
696     info!("starting to run rustc");
697
698     // Interpret the input file as a rust source file, passing it through the
699     // compiler all the way through the analysis passes. The rustdoc output is
700     // then generated from the cleaned AST of the crate. This runs all the
701     // plug/cleaning passes.
702     let crate_version = options.crate_version.clone();
703
704     let default_passes = options.default_passes;
705     let output_format = options.output_format;
706     // FIXME: fix this clone (especially render_options)
707     let manual_passes = options.manual_passes.clone();
708     let render_options = options.render_options.clone();
709     let config = core::create_config(options);
710
711     interface::create_compiler_and_run(config, |compiler| {
712         compiler.enter(|queries| {
713             let sess = compiler.session();
714
715             if sess.opts.describe_lints {
716                 let (_, lint_store) = &*queries.register_plugins()?.peek();
717                 describe_lints(sess, lint_store, true);
718                 return Ok(());
719             }
720
721             // We need to hold on to the complete resolver, so we cause everything to be
722             // cloned for the analysis passes to use. Suboptimal, but necessary in the
723             // current architecture.
724             let resolver = core::create_resolver(queries, &sess);
725
726             if sess.has_errors() {
727                 sess.fatal("Compilation failed, aborting rustdoc");
728             }
729
730             let mut global_ctxt = abort_on_err(queries.global_ctxt(), sess).peek_mut();
731
732             global_ctxt.enter(|tcx| {
733                 let (krate, render_opts, mut cache) = sess.time("run_global_ctxt", || {
734                     core::run_global_ctxt(
735                         tcx,
736                         resolver,
737                         default_passes,
738                         manual_passes,
739                         render_options,
740                         output_format,
741                     )
742                 });
743                 info!("finished with rustc");
744
745                 cache.crate_version = crate_version;
746
747                 if show_coverage {
748                     // if we ran coverage, bail early, we don't need to also generate docs at this point
749                     // (also we didn't load in any of the useful passes)
750                     return Ok(());
751                 } else if run_check {
752                     // Since we're in "check" mode, no need to generate anything beyond this point.
753                     return Ok(());
754                 }
755
756                 info!("going to format");
757                 match output_format {
758                     config::OutputFormat::Html => sess.time("render_html", || {
759                         run_renderer::<html::render::Context<'_>>(krate, render_opts, cache, tcx)
760                     }),
761                     config::OutputFormat::Json => sess.time("render_json", || {
762                         run_renderer::<json::JsonRenderer<'_>>(krate, render_opts, cache, tcx)
763                     }),
764                 }
765             })
766         })
767     })
768 }