2019-02-05 13:37:15 +00:00
|
|
|
#![doc(
|
|
|
|
html_root_url = "https://doc.rust-lang.org/nightly/",
|
2015-12-11 21:07:11 +00:00
|
|
|
html_playground_url = "https://play.rust-lang.org/"
|
|
|
|
)]
|
2017-07-23 02:01:58 +00:00
|
|
|
#![feature(rustc_private)]
|
2020-10-09 05:24:34 +00:00
|
|
|
#![feature(array_methods)]
|
2021-09-02 16:54:32 +00:00
|
|
|
#![feature(assert_matches)]
|
2015-02-10 21:52:44 +00:00
|
|
|
#![feature(box_patterns)]
|
2022-02-15 02:14:38 +00:00
|
|
|
#![feature(drain_filter)]
|
2022-08-20 18:40:08 +00:00
|
|
|
#![feature(let_chains)]
|
2015-01-23 02:22:03 +00:00
|
|
|
#![feature(test)]
|
2019-12-11 14:55:29 +00:00
|
|
|
#![feature(never_type)]
|
2022-12-12 05:42:45 +00:00
|
|
|
#![feature(lazy_cell)]
|
2020-11-30 20:24:48 +00:00
|
|
|
#![feature(type_ascription)]
|
2021-10-07 17:39:36 +00:00
|
|
|
#![feature(iter_intersperse)]
|
2022-01-15 19:51:35 +00:00
|
|
|
#![feature(type_alias_impl_trait)]
|
2023-04-12 13:32:15 +00:00
|
|
|
#![cfg_attr(not(bootstrap), feature(impl_trait_in_assoc_type))]
|
2018-04-25 22:49:52 +00:00
|
|
|
#![recursion_limit = "256"]
|
2021-04-27 17:00:36 +00:00
|
|
|
#![warn(rustc::internal)]
|
2022-01-13 22:26:31 +00:00
|
|
|
#![allow(clippy::collapsible_if, clippy::collapsible_else_if)]
|
2022-02-23 13:06:22 +00:00
|
|
|
#![allow(rustc::potential_query_instability)]
|
2013-10-03 01:10:16 +00:00
|
|
|
|
2022-11-23 00:55:16 +00:00
|
|
|
extern crate thin_vec;
|
2020-09-15 02:03:54 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate tracing;
|
|
|
|
|
|
|
|
// N.B. these need `extern crate` even in 2018 edition
|
|
|
|
// because they're loaded implicitly from the sysroot.
|
2020-09-15 12:40:10 +00:00
|
|
|
// The reason they're loaded from the sysroot is because
|
|
|
|
// the rustdoc artifacts aren't stored in rustc's cargo target directory.
|
|
|
|
// So if `rustc` was specified in Cargo.toml, this would spuriously rebuild crates.
|
|
|
|
//
|
|
|
|
// Dependencies listed in Cargo.toml do not need `extern crate`.
|
2021-04-04 21:07:56 +00:00
|
|
|
|
2022-02-01 12:30:32 +00:00
|
|
|
extern crate pulldown_cmark;
|
2020-02-29 17:37:32 +00:00
|
|
|
extern crate rustc_ast;
|
2020-01-11 16:02:46 +00:00
|
|
|
extern crate rustc_ast_pretty;
|
2020-01-11 12:15:20 +00:00
|
|
|
extern crate rustc_attr;
|
2021-01-05 19:08:11 +00:00
|
|
|
extern crate rustc_const_eval;
|
2016-08-12 22:22:02 +00:00
|
|
|
extern crate rustc_data_structures;
|
2014-11-27 14:57:47 +00:00
|
|
|
extern crate rustc_driver;
|
2020-01-09 10:18:47 +00:00
|
|
|
extern crate rustc_errors;
|
2019-12-29 14:23:55 +00:00
|
|
|
extern crate rustc_expand;
|
2019-11-29 23:23:38 +00:00
|
|
|
extern crate rustc_feature;
|
2020-01-05 01:37:57 +00:00
|
|
|
extern crate rustc_hir;
|
2022-09-26 11:00:29 +00:00
|
|
|
extern crate rustc_hir_analysis;
|
2020-03-24 01:44:41 +00:00
|
|
|
extern crate rustc_hir_pretty;
|
2019-11-15 18:41:50 +00:00
|
|
|
extern crate rustc_index;
|
2020-01-06 22:31:06 +00:00
|
|
|
extern crate rustc_infer;
|
2018-12-08 19:30:23 +00:00
|
|
|
extern crate rustc_interface;
|
2019-07-21 11:50:39 +00:00
|
|
|
extern crate rustc_lexer;
|
2015-02-25 11:44:44 +00:00
|
|
|
extern crate rustc_lint;
|
2020-12-30 04:16:16 +00:00
|
|
|
extern crate rustc_lint_defs;
|
2021-09-17 01:12:45 +00:00
|
|
|
extern crate rustc_macros;
|
2015-11-24 23:23:22 +00:00
|
|
|
extern crate rustc_metadata;
|
2020-03-29 14:41:09 +00:00
|
|
|
extern crate rustc_middle;
|
2019-10-15 20:48:13 +00:00
|
|
|
extern crate rustc_parse;
|
2021-02-27 21:02:41 +00:00
|
|
|
extern crate rustc_passes;
|
2015-01-11 02:03:34 +00:00
|
|
|
extern crate rustc_resolve;
|
2021-09-17 01:12:45 +00:00
|
|
|
extern crate rustc_serialize;
|
2020-01-09 05:42:42 +00:00
|
|
|
extern crate rustc_session;
|
2021-07-14 01:41:05 +00:00
|
|
|
extern crate rustc_span;
|
2018-04-25 16:30:39 +00:00
|
|
|
extern crate rustc_target;
|
2020-02-11 20:19:40 +00:00
|
|
|
extern crate rustc_trait_selection;
|
2021-07-14 01:40:09 +00:00
|
|
|
extern crate test;
|
2014-05-25 04:15:16 +00:00
|
|
|
|
2021-12-23 04:47:32 +00:00
|
|
|
// See docs in https://github.com/rust-lang/rust/blob/master/compiler/rustc/src/main.rs
|
|
|
|
// about jemalloc.
|
2021-04-04 21:07:56 +00:00
|
|
|
#[cfg(feature = "jemalloc")]
|
2022-05-06 21:20:04 +00:00
|
|
|
extern crate jemalloc_sys;
|
2021-04-04 21:07:56 +00:00
|
|
|
|
2016-01-05 01:35:22 +00:00
|
|
|
use std::default::Default;
|
2022-01-12 17:46:18 +00:00
|
|
|
use std::env::{self, VarError};
|
2022-10-16 13:56:03 +00:00
|
|
|
use std::io::{self, IsTerminal};
|
2015-06-11 02:33:04 +00:00
|
|
|
use std::process;
|
2015-02-27 05:00:43 +00:00
|
|
|
|
2022-07-02 05:54:05 +00:00
|
|
|
use rustc_driver::abort_on_err;
|
2022-01-23 18:34:26 +00:00
|
|
|
use rustc_errors::ErrorGuaranteed;
|
2020-12-16 19:34:08 +00:00
|
|
|
use rustc_interface::interface;
|
2021-01-01 04:25:30 +00:00
|
|
|
use rustc_middle::ty::TyCtxt;
|
2020-03-11 11:49:08 +00:00
|
|
|
use rustc_session::config::{make_crate_type_option, ErrorOutputType, RustcOptGroup};
|
2020-04-10 20:42:19 +00:00
|
|
|
use rustc_session::getopts;
|
2020-03-11 11:49:08 +00:00
|
|
|
use rustc_session::{early_error, early_warn};
|
2013-09-22 06:25:48 +00:00
|
|
|
|
2021-05-05 03:36:33 +00:00
|
|
|
use crate::clean::utils::DOC_RUST_LANG_ORG_CHANNEL;
|
|
|
|
|
2021-03-05 15:35:22 +00:00
|
|
|
/// A macro to create a FxHashMap.
|
|
|
|
///
|
|
|
|
/// Example:
|
|
|
|
///
|
2022-05-03 15:53:46 +00:00
|
|
|
/// ```ignore(cannot-test-this-because-non-exported-macro)
|
2021-03-05 15:35:22 +00:00
|
|
|
/// let letters = map!{"a" => "b", "c" => "d"};
|
|
|
|
/// ```
|
|
|
|
///
|
|
|
|
/// Trailing commas are allowed.
|
|
|
|
/// Commas between elements are required (even if the expression is a block).
|
|
|
|
macro_rules! map {
|
|
|
|
($( $key: expr => $val: expr ),* $(,)*) => {{
|
|
|
|
let mut map = ::rustc_data_structures::fx::FxHashMap::default();
|
|
|
|
$( map.insert($key, $val); )*
|
|
|
|
map
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
|
2018-07-22 21:01:09 +00:00
|
|
|
mod clean;
|
2018-10-30 13:47:54 +00:00
|
|
|
mod config;
|
2018-07-22 21:01:09 +00:00
|
|
|
mod core;
|
2019-05-20 02:04:04 +00:00
|
|
|
mod docfs;
|
2021-10-30 02:07:37 +00:00
|
|
|
mod doctest;
|
2020-06-15 18:42:29 +00:00
|
|
|
mod error;
|
2021-10-30 02:07:37 +00:00
|
|
|
mod externalfiles;
|
2018-07-22 21:01:09 +00:00
|
|
|
mod fold;
|
2021-01-28 23:51:54 +00:00
|
|
|
mod formats;
|
|
|
|
// used by the error-index generator, so it needs to be public
|
2020-06-29 23:22:58 +00:00
|
|
|
pub mod html;
|
2020-07-30 18:54:26 +00:00
|
|
|
mod json;
|
2022-05-21 01:06:44 +00:00
|
|
|
pub(crate) mod lint;
|
2018-07-22 21:01:09 +00:00
|
|
|
mod markdown;
|
|
|
|
mod passes;
|
2021-05-09 23:22:22 +00:00
|
|
|
mod scrape_examples;
|
2018-07-22 21:01:09 +00:00
|
|
|
mod theme;
|
rustdoc: Add `DocVisitor`
`DocFolder` allows transforming the docs, accomplished by making its
methods take and return types by-value. However, several of the rustdoc
`DocFolder` impls only *visit* the docs; they don't change anything.
Passing around types by-value is thus unnecessary, confusing, and
potentially inefficient for those impls.
`DocVisitor` is very similar to `DocFolder`, except that its methods
take shared references and return nothing (i.e., the unit type). This
should both be more efficient and make the code clearer.
There is an additional reason to add `DocVisitor`, too. As part of my
cleanup of `external_traits`, I'm planning to add a `fn cache(&mut self)
-> &mut Cache` method to `DocFolder` so that `external_traits` can be
retrieved explicitly from the `Cache`, rather than implicitly via
`Crate.external_traits` (which is an `Rc<RefCell<...>>`). However, some
of the `DocFolder` impls that could be turned into `DocVisitor` impls
only have a shared reference to the `Cache`, because they are used
during rendering. (They have to access the `Cache` via
`html::render::Context.shared.cache`, which involves an `Rc`.)
Since `DocVisitor` does not mutate any of the types it's visiting, its
equivalent `cache()` method will only need a shared reference to the
`Cache`, avoiding the problem described above.
2021-11-01 03:18:52 +00:00
|
|
|
mod visit;
|
2018-07-22 21:01:09 +00:00
|
|
|
mod visit_ast;
|
|
|
|
mod visit_lib;
|
2013-09-22 06:25:48 +00:00
|
|
|
|
2013-03-01 18:44:43 +00:00
|
|
|
pub fn main() {
|
2021-04-04 21:07:56 +00:00
|
|
|
// See docs in https://github.com/rust-lang/rust/blob/master/compiler/rustc/src/main.rs
|
2021-12-23 04:47:32 +00:00
|
|
|
// about jemalloc.
|
2021-04-04 21:07:56 +00:00
|
|
|
#[cfg(feature = "jemalloc")]
|
|
|
|
{
|
|
|
|
use std::os::raw::{c_int, c_void};
|
|
|
|
|
|
|
|
#[used]
|
|
|
|
static _F1: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::calloc;
|
|
|
|
#[used]
|
|
|
|
static _F2: unsafe extern "C" fn(*mut *mut c_void, usize, usize) -> c_int =
|
|
|
|
jemalloc_sys::posix_memalign;
|
|
|
|
#[used]
|
|
|
|
static _F3: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::aligned_alloc;
|
|
|
|
#[used]
|
|
|
|
static _F4: unsafe extern "C" fn(usize) -> *mut c_void = jemalloc_sys::malloc;
|
|
|
|
#[used]
|
|
|
|
static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = jemalloc_sys::realloc;
|
|
|
|
#[used]
|
|
|
|
static _F6: unsafe extern "C" fn(*mut c_void) = jemalloc_sys::free;
|
|
|
|
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
{
|
|
|
|
extern "C" {
|
|
|
|
fn _rjem_je_zone_register();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[used]
|
|
|
|
static _F7: unsafe extern "C" fn() = _rjem_je_zone_register;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-03 22:41:23 +00:00
|
|
|
rustc_driver::install_ice_hook();
|
2020-12-28 18:28:29 +00:00
|
|
|
|
|
|
|
// When using CI artifacts (with `download_stage1 = true`), tracing is unconditionally built
|
|
|
|
// with `--features=static_max_level_info`, which disables almost all rustdoc logging. To avoid
|
|
|
|
// this, compile our own version of `tracing` that logs all levels.
|
|
|
|
// NOTE: this compiles both versions of tracing unconditionally, because
|
|
|
|
// - The compile time hit is not that bad, especially compared to rustdoc's incremental times, and
|
|
|
|
// - Otherwise, there's no warning that logging is being ignored when `download_stage1 = true`.
|
|
|
|
// NOTE: The reason this doesn't show double logging when `download_stage1 = false` and
|
|
|
|
// `debug_logging = true` is because all rustc logging goes to its version of tracing (the one
|
|
|
|
// in the sysroot), and all of rustdoc's logging goes to its version (the one in Cargo.toml).
|
|
|
|
init_logging();
|
2020-07-25 13:50:51 +00:00
|
|
|
rustc_driver::init_env_logger("RUSTDOC_LOG");
|
2020-12-28 18:28:29 +00:00
|
|
|
|
Avoid an unnecessary thread creation at rustdoc startup.
rustdoc's `main()` immediately spawns a thread, M, with a large stack
(16MiB or 32MiB) on which it runs `main_args()`. `main_args()` does a
small amount of options processing and then calls
`setup_callbacks_and_run_in_default_thread_pool_with_globals()`, which
spawns it own thread, and M is not used further.
So, thread M seems unnecessary. However, it does serve a purpose: if the
options processing in `main_args()` panics, that panic is caught when M
is joined. So M can't simply be removed.
However, `main_options()`, which is called by `main_args()`, has a
`catch_fatal_errors()` call within it. We can move that call to `main()`
and change it to the very similar `catch_with_exit_code()`. With that in
place, M can be removed, and panics from options processing will still
be caught appropriately.
Even better, this makes rustdoc's `main()` match rustc's `main()`, which
also uses `catch_with_exit_code()`.
(Also note that the use of a 16MiB/32MiB stack was eliminated from rustc
in #55617.)
2020-08-03 09:37:22 +00:00
|
|
|
let exit_code = rustc_driver::catch_with_exit_code(|| match get_args() {
|
|
|
|
Some(args) => main_args(&args),
|
2022-01-23 00:49:12 +00:00
|
|
|
_ => Err(ErrorGuaranteed::unchecked_claim_error_was_emitted()),
|
Avoid an unnecessary thread creation at rustdoc startup.
rustdoc's `main()` immediately spawns a thread, M, with a large stack
(16MiB or 32MiB) on which it runs `main_args()`. `main_args()` does a
small amount of options processing and then calls
`setup_callbacks_and_run_in_default_thread_pool_with_globals()`, which
spawns it own thread, and M is not used further.
So, thread M seems unnecessary. However, it does serve a purpose: if the
options processing in `main_args()` panics, that panic is caught when M
is joined. So M can't simply be removed.
However, `main_options()`, which is called by `main_args()`, has a
`catch_fatal_errors()` call within it. We can move that call to `main()`
and change it to the very similar `catch_with_exit_code()`. With that in
place, M can be removed, and panics from options processing will still
be caught appropriately.
Even better, this makes rustdoc's `main()` match rustc's `main()`, which
also uses `catch_with_exit_code()`.
(Also note that the use of a 16MiB/32MiB stack was eliminated from rustc
in #55617.)
2020-08-03 09:37:22 +00:00
|
|
|
});
|
|
|
|
process::exit(exit_code);
|
2013-09-22 06:25:48 +00:00
|
|
|
}
|
|
|
|
|
2020-12-28 18:28:29 +00:00
|
|
|
fn init_logging() {
|
2022-01-12 17:46:18 +00:00
|
|
|
let color_logs = match std::env::var("RUSTDOC_LOG_COLOR").as_deref() {
|
|
|
|
Ok("always") => true,
|
|
|
|
Ok("never") => false,
|
2022-10-16 13:56:03 +00:00
|
|
|
Ok("auto") | Err(VarError::NotPresent) => io::stdout().is_terminal(),
|
2022-01-12 17:46:18 +00:00
|
|
|
Ok(value) => early_error(
|
|
|
|
ErrorOutputType::default(),
|
|
|
|
&format!("invalid log color value '{}': expected one of always, never, or auto", value),
|
|
|
|
),
|
|
|
|
Err(VarError::NotUnicode(value)) => early_error(
|
2020-12-28 18:28:29 +00:00
|
|
|
ErrorOutputType::default(),
|
2022-01-12 17:46:18 +00:00
|
|
|
&format!(
|
|
|
|
"invalid log color value '{}': expected one of always, never, or auto",
|
|
|
|
value.to_string_lossy()
|
|
|
|
),
|
2020-12-28 18:28:29 +00:00
|
|
|
),
|
|
|
|
};
|
|
|
|
let filter = tracing_subscriber::EnvFilter::from_env("RUSTDOC_LOG");
|
|
|
|
let layer = tracing_tree::HierarchicalLayer::default()
|
|
|
|
.with_writer(io::stderr)
|
|
|
|
.with_indent_lines(true)
|
|
|
|
.with_ansi(color_logs)
|
|
|
|
.with_targets(true)
|
|
|
|
.with_wraparound(10)
|
|
|
|
.with_verbose_exit(true)
|
|
|
|
.with_verbose_entry(true)
|
|
|
|
.with_indent_amount(2);
|
2023-04-04 07:31:37 +00:00
|
|
|
#[cfg(all(parallel_compiler, debug_assertions))]
|
2020-12-28 18:28:29 +00:00
|
|
|
let layer = layer.with_thread_ids(true).with_thread_names(true);
|
|
|
|
|
|
|
|
use tracing_subscriber::layer::SubscriberExt;
|
|
|
|
let subscriber = tracing_subscriber::Registry::default().with(filter).with(layer);
|
|
|
|
tracing::subscriber::set_global_default(subscriber).unwrap();
|
|
|
|
}
|
|
|
|
|
2017-05-18 23:11:22 +00:00
|
|
|
fn get_args() -> Option<Vec<String>> {
|
|
|
|
env::args_os()
|
|
|
|
.enumerate()
|
|
|
|
.map(|(i, arg)| {
|
|
|
|
arg.into_string()
|
|
|
|
.map_err(|arg| {
|
2018-05-08 18:42:53 +00:00
|
|
|
early_warn(
|
|
|
|
ErrorOutputType::default(),
|
|
|
|
&format!("Argument {} is not valid Unicode: {:?}", i, arg),
|
|
|
|
);
|
2017-05-18 23:11:22 +00:00
|
|
|
})
|
|
|
|
.ok()
|
2019-12-22 22:42:04 +00:00
|
|
|
})
|
2017-05-18 23:11:22 +00:00
|
|
|
.collect()
|
|
|
|
}
|
|
|
|
|
2018-07-22 21:01:09 +00:00
|
|
|
fn opts() -> Vec<RustcOptGroup> {
|
2020-12-13 20:13:41 +00:00
|
|
|
let stable: fn(_, fn(&mut getopts::Options) -> &mut _) -> _ = RustcOptGroup::stable;
|
|
|
|
let unstable: fn(_, fn(&mut getopts::Options) -> &mut _) -> _ = RustcOptGroup::unstable;
|
2016-10-29 21:54:04 +00:00
|
|
|
vec![
|
2020-07-01 18:25:54 +00:00
|
|
|
stable("h", |o| o.optflagmulti("h", "help", "show this help message")),
|
|
|
|
stable("V", |o| o.optflagmulti("V", "version", "print rustdoc's version")),
|
|
|
|
stable("v", |o| o.optflagmulti("v", "verbose", "use verbose output")),
|
2017-06-08 21:20:55 +00:00
|
|
|
stable("w", |o| o.optopt("w", "output-format", "the output type to write", "[html]")),
|
2021-11-28 07:12:56 +00:00
|
|
|
stable("output", |o| {
|
|
|
|
o.optopt(
|
|
|
|
"",
|
|
|
|
"output",
|
|
|
|
"Which directory to place the output. \
|
|
|
|
This option is deprecated, use --out-dir instead.",
|
|
|
|
"PATH",
|
|
|
|
)
|
|
|
|
}),
|
|
|
|
stable("o", |o| o.optopt("o", "out-dir", "which directory to place the output", "PATH")),
|
2017-06-08 21:20:55 +00:00
|
|
|
stable("crate-name", |o| {
|
|
|
|
o.optopt("", "crate-name", "specify the name of this crate", "NAME")
|
|
|
|
}),
|
2019-07-20 20:34:41 +00:00
|
|
|
make_crate_type_option(),
|
2017-06-08 21:20:55 +00:00
|
|
|
stable("L", |o| {
|
|
|
|
o.optmulti("L", "library-path", "directory to add to crate search path", "DIR")
|
|
|
|
}),
|
|
|
|
stable("cfg", |o| o.optmulti("", "cfg", "pass a --cfg to rustc", "")),
|
2022-02-19 13:31:20 +00:00
|
|
|
unstable("check-cfg", |o| o.optmulti("", "check-cfg", "pass a --check-cfg to rustc", "")),
|
2019-09-30 01:17:48 +00:00
|
|
|
stable("extern", |o| o.optmulti("", "extern", "pass an --extern to rustc", "NAME[=PATH]")),
|
2018-06-06 01:17:06 +00:00
|
|
|
unstable("extern-html-root-url", |o| {
|
2021-03-17 18:41:01 +00:00
|
|
|
o.optmulti(
|
|
|
|
"",
|
|
|
|
"extern-html-root-url",
|
|
|
|
"base URL to use for dependencies; for example, \
|
|
|
|
\"std=/doc\" links std::vec::Vec to /doc/std/vec/struct.Vec.html",
|
|
|
|
"NAME=URL",
|
|
|
|
)
|
2017-06-08 21:20:55 +00:00
|
|
|
}),
|
Give precedence to `html_root_url` over `--extern-html-root-url` by default, but add a way to opt-in to the previous behavior
## What is an HTML root url?
It tells rustdoc where it should link when documentation for a crate is
not available locally; for example, when a crate is a dependency of a
crate documented with `cargo doc --no-deps`.
## What is the difference between `html_root_url` and `--extern-html-root-url`?
Both of these tell rustdoc what the HTML root should be set to.
`doc(html_root_url)` is set by the crate author, while
`--extern-html-root-url` is set by the person documenting the crate.
These are often different. For example, docs.rs uses
`--extern-html-root-url https://docs.rs/crate-name/version` to ensure
all crates have documentation, even if `html_root_url` is not set.
Conversely, crates such as Rocket set `doc(html_root_url =
"https://api.rocket.rs")`, because they prefer users to view the
documentation on their own site.
Crates also set `html_root_url` to ensure they have
documentation when building locally when offline. This is unfortunate to
require, because it's more work from the library author. It also makes
it impossible to distinguish between crates that want to be viewed on a
different site (e.g. Rocket) and crates that just want documentation to
be visible offline at all (e.g. Tokio). I have authored a separate
change to the API guidelines to no longer recommend doing this:
https://github.com/rust-lang/api-guidelines/pull/230.
## Why change the default?
In the past, docs.rs has been the main user of `--extern-html-root-url`.
However, it's useful for other projects as well. In particular, Cargo
wants to pass it by default when running `--no-deps`
(https://github.com/rust-lang/cargo/issues/8296).
Unfortunately, for these other use cases, the priority order is
inverted. They want to give *precedence* to the URL the crate picks, and
only fall back to the `--extern-html-root` if no `html_root_url` is
present. That allows passing `--extern-html-root` unconditionally,
without having to parse the source code to see what attributes are
present.
For docs.rs, however, we still want to keep the old behavior, so that
all links on docs.rs stay on the site.
2021-03-04 20:03:22 +00:00
|
|
|
unstable("extern-html-root-takes-precedence", |o| {
|
|
|
|
o.optflagmulti(
|
|
|
|
"",
|
|
|
|
"extern-html-root-takes-precedence",
|
|
|
|
"give precedence to `--extern-html-root-url`, not `html_root_url`",
|
|
|
|
)
|
|
|
|
}),
|
2018-04-12 18:12:53 +00:00
|
|
|
stable("C", |o| {
|
|
|
|
o.optmulti("C", "codegen", "pass a codegen option to rustc", "OPT[=VALUE]")
|
|
|
|
}),
|
2017-09-21 18:10:07 +00:00
|
|
|
stable("document-private-items", |o| {
|
2020-07-01 18:25:54 +00:00
|
|
|
o.optflagmulti("", "document-private-items", "document private items")
|
2017-09-21 18:10:07 +00:00
|
|
|
}),
|
2020-01-04 18:58:32 +00:00
|
|
|
unstable("document-hidden-items", |o| {
|
2020-07-01 18:25:54 +00:00
|
|
|
o.optflagmulti("", "document-hidden-items", "document items that have doc(hidden)")
|
2020-01-04 18:58:32 +00:00
|
|
|
}),
|
2020-07-01 18:25:54 +00:00
|
|
|
stable("test", |o| o.optflagmulti("", "test", "run code examples as tests")),
|
2017-06-08 21:20:55 +00:00
|
|
|
stable("test-args", |o| {
|
|
|
|
o.optmulti("", "test-args", "arguments to pass to the test runner", "ARGS")
|
|
|
|
}),
|
2021-01-22 09:54:53 +00:00
|
|
|
unstable("test-run-directory", |o| {
|
|
|
|
o.optopt(
|
|
|
|
"",
|
|
|
|
"test-run-directory",
|
|
|
|
"The working directory in which to run tests",
|
|
|
|
"PATH",
|
|
|
|
)
|
|
|
|
}),
|
2017-06-08 21:20:55 +00:00
|
|
|
stable("target", |o| o.optopt("", "target", "target triple to document", "TRIPLE")),
|
|
|
|
stable("markdown-css", |o| {
|
|
|
|
o.optmulti(
|
|
|
|
"",
|
|
|
|
"markdown-css",
|
|
|
|
"CSS files to include via <link> in a rendered Markdown file",
|
|
|
|
"FILES",
|
|
|
|
)
|
|
|
|
}),
|
|
|
|
stable("html-in-header", |o| {
|
|
|
|
o.optmulti(
|
|
|
|
"",
|
|
|
|
"html-in-header",
|
|
|
|
"files to include inline in the <head> section of a rendered Markdown file \
|
2020-08-31 11:16:50 +00:00
|
|
|
or generated documentation",
|
2017-06-08 21:20:55 +00:00
|
|
|
"FILES",
|
|
|
|
)
|
|
|
|
}),
|
|
|
|
stable("html-before-content", |o| {
|
|
|
|
o.optmulti(
|
|
|
|
"",
|
|
|
|
"html-before-content",
|
|
|
|
"files to include inline between <body> and the content of a rendered \
|
2020-08-31 11:16:50 +00:00
|
|
|
Markdown file or generated documentation",
|
2017-06-08 21:20:55 +00:00
|
|
|
"FILES",
|
|
|
|
)
|
|
|
|
}),
|
|
|
|
stable("html-after-content", |o| {
|
|
|
|
o.optmulti(
|
|
|
|
"",
|
|
|
|
"html-after-content",
|
|
|
|
"files to include inline between the content and </body> of a rendered \
|
2020-08-31 11:16:50 +00:00
|
|
|
Markdown file or generated documentation",
|
2017-06-08 21:20:55 +00:00
|
|
|
"FILES",
|
|
|
|
)
|
|
|
|
}),
|
|
|
|
unstable("markdown-before-content", |o| {
|
|
|
|
o.optmulti(
|
|
|
|
"",
|
|
|
|
"markdown-before-content",
|
|
|
|
"files to include inline between <body> and the content of a rendered \
|
2020-08-31 11:16:50 +00:00
|
|
|
Markdown file or generated documentation",
|
2017-06-08 21:20:55 +00:00
|
|
|
"FILES",
|
|
|
|
)
|
|
|
|
}),
|
|
|
|
unstable("markdown-after-content", |o| {
|
|
|
|
o.optmulti(
|
|
|
|
"",
|
|
|
|
"markdown-after-content",
|
|
|
|
"files to include inline between the content and </body> of a rendered \
|
2020-08-31 11:16:50 +00:00
|
|
|
Markdown file or generated documentation",
|
2017-06-08 21:20:55 +00:00
|
|
|
"FILES",
|
|
|
|
)
|
|
|
|
}),
|
|
|
|
stable("markdown-playground-url", |o| {
|
|
|
|
o.optopt("", "markdown-playground-url", "URL to send code snippets to", "URL")
|
|
|
|
}),
|
|
|
|
stable("markdown-no-toc", |o| {
|
2020-07-01 18:25:54 +00:00
|
|
|
o.optflagmulti("", "markdown-no-toc", "don't include table of contents")
|
2017-06-08 21:20:55 +00:00
|
|
|
}),
|
|
|
|
stable("e", |o| {
|
|
|
|
o.optopt(
|
|
|
|
"e",
|
|
|
|
"extend-css",
|
|
|
|
"To add some CSS rules with a given file to generate doc with your \
|
2020-08-31 11:16:50 +00:00
|
|
|
own theme. However, your theme might break if the rustdoc's generated HTML \
|
|
|
|
changes, so be careful!",
|
2017-06-08 21:20:55 +00:00
|
|
|
"PATH",
|
|
|
|
)
|
|
|
|
}),
|
|
|
|
unstable("Z", |o| {
|
2022-07-06 12:44:47 +00:00
|
|
|
o.optmulti("Z", "", "unstable / perma-unstable options (only on nightly build)", "FLAG")
|
2017-06-08 21:20:55 +00:00
|
|
|
}),
|
|
|
|
stable("sysroot", |o| o.optopt("", "sysroot", "Override the system root", "PATH")),
|
|
|
|
unstable("playground-url", |o| {
|
|
|
|
o.optopt(
|
|
|
|
"",
|
|
|
|
"playground-url",
|
|
|
|
"URL to send code snippets to, may be reset by --markdown-playground-url \
|
2020-08-31 11:16:50 +00:00
|
|
|
or `#![doc(html_playground_url=...)]`",
|
2017-06-08 21:20:55 +00:00
|
|
|
"URL",
|
|
|
|
)
|
|
|
|
}),
|
2021-09-09 14:52:19 +00:00
|
|
|
unstable("display-doctest-warnings", |o| {
|
|
|
|
o.optflagmulti(
|
|
|
|
"",
|
|
|
|
"display-doctest-warnings",
|
|
|
|
"show warnings that originate in doctests",
|
|
|
|
)
|
2017-06-08 21:20:55 +00:00
|
|
|
}),
|
2020-02-26 21:08:59 +00:00
|
|
|
stable("crate-version", |o| {
|
2017-10-02 23:29:03 +00:00
|
|
|
o.optopt("", "crate-version", "crate version to print into documentation", "VERSION")
|
|
|
|
}),
|
2017-12-17 15:22:50 +00:00
|
|
|
unstable("sort-modules-by-appearance", |o| {
|
2020-07-01 18:25:54 +00:00
|
|
|
o.optflagmulti(
|
2017-12-18 19:52:45 +00:00
|
|
|
"",
|
|
|
|
"sort-modules-by-appearance",
|
2020-06-13 13:05:37 +00:00
|
|
|
"sort modules by where they appear in the program, rather than alphabetically",
|
2017-12-18 19:52:45 +00:00
|
|
|
)
|
2017-12-17 15:22:50 +00:00
|
|
|
}),
|
2020-12-02 18:32:38 +00:00
|
|
|
stable("default-theme", |o| {
|
2020-10-28 17:53:12 +00:00
|
|
|
o.optopt(
|
|
|
|
"",
|
|
|
|
"default-theme",
|
2020-10-28 20:12:15 +00:00
|
|
|
"Set the default theme. THEME should be the theme name, generally lowercase. \
|
2020-10-28 17:53:12 +00:00
|
|
|
If an unknown default theme is specified, the builtin default is used. \
|
2020-12-02 18:31:55 +00:00
|
|
|
The set of themes, and the rustdoc built-in default, are not stable.",
|
2020-10-28 17:53:12 +00:00
|
|
|
"THEME",
|
|
|
|
)
|
|
|
|
}),
|
2020-10-13 17:52:43 +00:00
|
|
|
unstable("default-setting", |o| {
|
|
|
|
o.optmulti(
|
|
|
|
"",
|
|
|
|
"default-setting",
|
|
|
|
"Default value for a rustdoc setting (used when \"rustdoc-SETTING\" is absent \
|
2020-10-28 20:12:15 +00:00
|
|
|
from web browser Local Storage). If VALUE is not supplied, \"true\" is used. \
|
2020-10-13 17:52:43 +00:00
|
|
|
Supported SETTINGs and VALUEs are not documented and not stable.",
|
|
|
|
"SETTING[=VALUE]",
|
|
|
|
)
|
|
|
|
}),
|
2019-09-22 20:35:25 +00:00
|
|
|
stable("theme", |o| {
|
|
|
|
o.optmulti(
|
|
|
|
"",
|
|
|
|
"theme",
|
2018-01-20 21:16:46 +00:00
|
|
|
"additional themes which will be added to the generated docs",
|
|
|
|
"FILES",
|
|
|
|
)
|
|
|
|
}),
|
2019-09-22 20:35:25 +00:00
|
|
|
stable("check-theme", |o| {
|
2018-01-23 23:38:41 +00:00
|
|
|
o.optmulti("", "check-theme", "check if given theme is valid", "FILES")
|
|
|
|
}),
|
2018-02-24 18:14:36 +00:00
|
|
|
unstable("resource-suffix", |o| {
|
|
|
|
o.optopt(
|
|
|
|
"",
|
|
|
|
"resource-suffix",
|
2018-11-27 02:59:49 +00:00
|
|
|
"suffix to add to CSS and JavaScript files, e.g., \"light.css\" will become \
|
2020-08-31 11:16:50 +00:00
|
|
|
\"light-suffix.css\"",
|
2018-02-24 18:14:36 +00:00
|
|
|
"PATH",
|
|
|
|
)
|
|
|
|
}),
|
2018-09-06 16:20:01 +00:00
|
|
|
stable("edition", |o| {
|
2018-03-27 14:31:19 +00:00
|
|
|
o.optopt(
|
|
|
|
"",
|
|
|
|
"edition",
|
|
|
|
"edition to use when compiling rust code (default: 2015)",
|
|
|
|
"EDITION",
|
|
|
|
)
|
|
|
|
}),
|
2018-08-02 20:54:09 +00:00
|
|
|
stable("color", |o| {
|
2018-03-31 22:09:00 +00:00
|
|
|
o.optopt(
|
|
|
|
"",
|
|
|
|
"color",
|
|
|
|
"Configure coloring of output:
|
|
|
|
auto = colorize, if output goes to a tty (default);
|
|
|
|
always = always colorize output;
|
|
|
|
never = never colorize output",
|
|
|
|
"auto|always|never",
|
|
|
|
)
|
|
|
|
}),
|
2018-08-02 20:54:09 +00:00
|
|
|
stable("error-format", |o| {
|
2018-03-31 22:09:00 +00:00
|
|
|
o.optopt(
|
|
|
|
"",
|
|
|
|
"error-format",
|
|
|
|
"How errors and other messages are produced",
|
|
|
|
"human|json|short",
|
|
|
|
)
|
|
|
|
}),
|
2022-09-24 01:04:15 +00:00
|
|
|
stable("diagnostic-width", |o| {
|
2022-02-14 06:01:38 +00:00
|
|
|
o.optopt(
|
|
|
|
"",
|
2022-07-06 10:57:41 +00:00
|
|
|
"diagnostic-width",
|
2022-06-16 15:39:11 +00:00
|
|
|
"Provide width of the output for truncated error messages",
|
2022-02-14 06:01:38 +00:00
|
|
|
"WIDTH",
|
|
|
|
)
|
|
|
|
}),
|
2019-07-17 19:52:56 +00:00
|
|
|
stable("json", |o| {
|
|
|
|
o.optopt("", "json", "Configure the structure of JSON diagnostics", "CONFIG")
|
|
|
|
}),
|
2021-07-24 06:59:17 +00:00
|
|
|
stable("allow", |o| o.optmulti("A", "allow", "Set lint allowed", "LINT")),
|
|
|
|
stable("warn", |o| o.optmulti("W", "warn", "Set lint warnings", "LINT")),
|
2021-07-24 07:05:24 +00:00
|
|
|
stable("force-warn", |o| o.optmulti("", "force-warn", "Set lint force-warn", "LINT")),
|
2021-07-24 06:59:17 +00:00
|
|
|
stable("deny", |o| o.optmulti("D", "deny", "Set lint denied", "LINT")),
|
|
|
|
stable("forbid", |o| o.optmulti("F", "forbid", "Set lint forbidden", "LINT")),
|
2018-07-13 20:45:21 +00:00
|
|
|
stable("cap-lints", |o| {
|
2018-06-23 13:09:21 +00:00
|
|
|
o.optmulti(
|
|
|
|
"",
|
|
|
|
"cap-lints",
|
|
|
|
"Set the most restrictive lint level. \
|
|
|
|
More restrictive lints are capped at this \
|
|
|
|
level. By default, it is at `forbid` level.",
|
|
|
|
"LEVEL",
|
|
|
|
)
|
|
|
|
}),
|
2018-09-24 23:08:33 +00:00
|
|
|
unstable("index-page", |o| {
|
|
|
|
o.optopt("", "index-page", "Markdown file to be used as index page", "PATH")
|
|
|
|
}),
|
|
|
|
unstable("enable-index-page", |o| {
|
2020-07-01 18:25:54 +00:00
|
|
|
o.optflagmulti("", "enable-index-page", "To enable generation of the index page")
|
2018-09-24 23:08:33 +00:00
|
|
|
}),
|
2018-12-20 16:18:45 +00:00
|
|
|
unstable("static-root-path", |o| {
|
|
|
|
o.optopt(
|
|
|
|
"",
|
|
|
|
"static-root-path",
|
|
|
|
"Path string to force loading static files from in output pages. \
|
2020-08-31 11:16:50 +00:00
|
|
|
If not set, uses combinations of '../' to reach the documentation root.",
|
2018-12-20 16:18:45 +00:00
|
|
|
"PATH",
|
|
|
|
)
|
|
|
|
}),
|
2018-12-20 12:28:55 +00:00
|
|
|
unstable("disable-per-crate-search", |o| {
|
2020-07-01 18:25:54 +00:00
|
|
|
o.optflagmulti(
|
2018-12-20 12:28:55 +00:00
|
|
|
"",
|
|
|
|
"disable-per-crate-search",
|
|
|
|
"disables generating the crate selector on the search box",
|
|
|
|
)
|
2018-12-31 23:05:57 +00:00
|
|
|
}),
|
2018-12-08 19:17:50 +00:00
|
|
|
unstable("persist-doctests", |o| {
|
|
|
|
o.optopt(
|
|
|
|
"",
|
|
|
|
"persist-doctests",
|
2018-12-16 22:31:36 +00:00
|
|
|
"Directory to persist doctest executables into",
|
2018-12-08 19:17:50 +00:00
|
|
|
"PATH",
|
|
|
|
)
|
2018-12-20 12:28:55 +00:00
|
|
|
}),
|
2019-01-30 20:04:56 +00:00
|
|
|
unstable("show-coverage", |o| {
|
2020-07-01 18:25:54 +00:00
|
|
|
o.optflagmulti(
|
2019-01-30 20:04:56 +00:00
|
|
|
"",
|
|
|
|
"show-coverage",
|
|
|
|
"calculate percentage of public items with documentation",
|
|
|
|
)
|
|
|
|
}),
|
2019-06-06 23:01:53 +00:00
|
|
|
unstable("enable-per-target-ignores", |o| {
|
2020-07-01 18:25:54 +00:00
|
|
|
o.optflagmulti(
|
2019-06-06 23:01:53 +00:00
|
|
|
"",
|
|
|
|
"enable-per-target-ignores",
|
|
|
|
"parse ignore-foo for ignoring doctests on a per-target basis",
|
|
|
|
)
|
|
|
|
}),
|
2019-04-26 20:52:56 +00:00
|
|
|
unstable("runtool", |o| {
|
|
|
|
o.optopt(
|
|
|
|
"",
|
|
|
|
"runtool",
|
|
|
|
"",
|
|
|
|
"The tool to run tests with when building for a different target than host",
|
|
|
|
)
|
|
|
|
}),
|
|
|
|
unstable("runtool-arg", |o| {
|
|
|
|
o.optmulti(
|
|
|
|
"",
|
|
|
|
"runtool-arg",
|
|
|
|
"",
|
|
|
|
"One (of possibly many) arguments to pass to the runtool",
|
|
|
|
)
|
|
|
|
}),
|
2019-09-10 01:11:27 +00:00
|
|
|
unstable("test-builder", |o| {
|
2021-01-12 16:29:47 +00:00
|
|
|
o.optopt("", "test-builder", "The rustc-like binary to use as the test builder", "PATH")
|
2019-09-10 01:11:27 +00:00
|
|
|
}),
|
2021-07-10 21:32:14 +00:00
|
|
|
unstable("check", |o| o.optflagmulti("", "check", "Run rustdoc checks")),
|
2021-01-20 19:56:47 +00:00
|
|
|
unstable("generate-redirect-map", |o| {
|
2021-07-10 21:32:14 +00:00
|
|
|
o.optflagmulti(
|
2021-01-20 19:56:47 +00:00
|
|
|
"",
|
|
|
|
"generate-redirect-map",
|
|
|
|
"Generate JSON file at the top level instead of generating HTML redirection files",
|
|
|
|
)
|
|
|
|
}),
|
2021-03-25 16:46:35 +00:00
|
|
|
unstable("emit", |o| {
|
|
|
|
o.optmulti(
|
|
|
|
"",
|
|
|
|
"emit",
|
|
|
|
"Comma separated list of types of output for rustdoc to emit",
|
2021-03-31 15:35:57 +00:00
|
|
|
"[unversioned-shared-resources,toolchain-shared-resources,invocation-specific]",
|
2021-03-25 16:46:35 +00:00
|
|
|
)
|
|
|
|
}),
|
2021-07-10 21:32:14 +00:00
|
|
|
unstable("no-run", |o| {
|
|
|
|
o.optflagmulti("", "no-run", "Compile doctests without running them")
|
|
|
|
}),
|
2021-04-13 02:42:26 +00:00
|
|
|
unstable("show-type-layout", |o| {
|
2021-07-10 21:32:14 +00:00
|
|
|
o.optflagmulti("", "show-type-layout", "Include the memory layout of types in the docs")
|
2021-04-13 02:42:26 +00:00
|
|
|
}),
|
2021-06-11 14:53:32 +00:00
|
|
|
unstable("nocapture", |o| {
|
|
|
|
o.optflag("", "nocapture", "Don't capture stdout and stderr of tests")
|
|
|
|
}),
|
2021-04-13 13:52:41 +00:00
|
|
|
unstable("generate-link-to-definition", |o| {
|
|
|
|
o.optflag(
|
|
|
|
"",
|
|
|
|
"generate-link-to-definition",
|
|
|
|
"Make the identifiers in the HTML source code pages navigable",
|
|
|
|
)
|
|
|
|
}),
|
2021-09-20 21:08:33 +00:00
|
|
|
unstable("scrape-examples-output-path", |o| {
|
2021-09-17 01:12:45 +00:00
|
|
|
o.optopt(
|
|
|
|
"",
|
2021-09-20 21:08:33 +00:00
|
|
|
"scrape-examples-output-path",
|
2021-09-17 01:12:45 +00:00
|
|
|
"",
|
2021-09-20 21:08:33 +00:00
|
|
|
"collect function call information and output at the given path",
|
|
|
|
)
|
|
|
|
}),
|
|
|
|
unstable("scrape-examples-target-crate", |o| {
|
|
|
|
o.optmulti(
|
|
|
|
"",
|
|
|
|
"scrape-examples-target-crate",
|
|
|
|
"",
|
|
|
|
"collect function call information for functions from the target crate",
|
2021-09-17 01:12:45 +00:00
|
|
|
)
|
|
|
|
}),
|
2022-02-12 05:48:59 +00:00
|
|
|
unstable("scrape-tests", |o| {
|
|
|
|
o.optflag("", "scrape-tests", "Include test code when scraping examples")
|
|
|
|
}),
|
2021-09-17 01:12:45 +00:00
|
|
|
unstable("with-examples", |o| {
|
|
|
|
o.optmulti(
|
|
|
|
"",
|
|
|
|
"with-examples",
|
|
|
|
"",
|
|
|
|
"path to function call information (for displaying examples in the documentation)",
|
|
|
|
)
|
|
|
|
}),
|
2021-12-14 06:49:29 +00:00
|
|
|
// deprecated / removed options
|
2022-10-24 08:28:55 +00:00
|
|
|
unstable("disable-minification", |o| o.optflagmulti("", "disable-minification", "removed")),
|
2021-12-14 06:49:29 +00:00
|
|
|
stable("plugin-path", |o| {
|
|
|
|
o.optmulti(
|
|
|
|
"",
|
|
|
|
"plugin-path",
|
|
|
|
"removed, see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \
|
|
|
|
for more information",
|
|
|
|
"DIR",
|
|
|
|
)
|
|
|
|
}),
|
|
|
|
stable("passes", |o| {
|
|
|
|
o.optmulti(
|
|
|
|
"",
|
|
|
|
"passes",
|
|
|
|
"removed, see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \
|
|
|
|
for more information",
|
|
|
|
"PASSES",
|
|
|
|
)
|
|
|
|
}),
|
|
|
|
stable("plugins", |o| {
|
|
|
|
o.optmulti(
|
|
|
|
"",
|
|
|
|
"plugins",
|
|
|
|
"removed, see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \
|
|
|
|
for more information",
|
|
|
|
"PLUGINS",
|
|
|
|
)
|
|
|
|
}),
|
|
|
|
stable("no-default", |o| {
|
|
|
|
o.optflagmulti(
|
|
|
|
"",
|
|
|
|
"no-defaults",
|
|
|
|
"removed, see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \
|
|
|
|
for more information",
|
|
|
|
)
|
|
|
|
}),
|
|
|
|
stable("r", |o| {
|
|
|
|
o.optopt(
|
|
|
|
"r",
|
|
|
|
"input-format",
|
|
|
|
"removed, see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \
|
|
|
|
for more information",
|
|
|
|
"[rust]",
|
|
|
|
)
|
|
|
|
}),
|
2016-10-29 21:54:04 +00:00
|
|
|
]
|
2013-09-22 06:25:48 +00:00
|
|
|
}
|
|
|
|
|
2018-07-22 21:01:09 +00:00
|
|
|
fn usage(argv0: &str) {
|
2017-06-08 21:20:55 +00:00
|
|
|
let mut options = getopts::Options::new();
|
|
|
|
for option in opts() {
|
|
|
|
(option.apply)(&mut options);
|
|
|
|
}
|
|
|
|
println!("{}", options.usage(&format!("{} [options] <input>", argv0)));
|
2021-02-18 15:15:24 +00:00
|
|
|
println!(" @path Read newline separated options from `path`\n");
|
2021-05-05 03:36:33 +00:00
|
|
|
println!(
|
|
|
|
"More information available at {}/rustdoc/what-is-rustdoc.html",
|
|
|
|
DOC_RUST_LANG_ORG_CHANNEL
|
|
|
|
);
|
2013-08-22 09:41:33 +00:00
|
|
|
}
|
2012-11-19 01:56:50 +00:00
|
|
|
|
Avoid an unnecessary thread creation at rustdoc startup.
rustdoc's `main()` immediately spawns a thread, M, with a large stack
(16MiB or 32MiB) on which it runs `main_args()`. `main_args()` does a
small amount of options processing and then calls
`setup_callbacks_and_run_in_default_thread_pool_with_globals()`, which
spawns it own thread, and M is not used further.
So, thread M seems unnecessary. However, it does serve a purpose: if the
options processing in `main_args()` panics, that panic is caught when M
is joined. So M can't simply be removed.
However, `main_options()`, which is called by `main_args()`, has a
`catch_fatal_errors()` call within it. We can move that call to `main()`
and change it to the very similar `catch_with_exit_code()`. With that in
place, M can be removed, and panics from options processing will still
be caught appropriately.
Even better, this makes rustdoc's `main()` match rustc's `main()`, which
also uses `catch_with_exit_code()`.
(Also note that the use of a 16MiB/32MiB stack was eliminated from rustc
in #55617.)
2020-08-03 09:37:22 +00:00
|
|
|
/// A result type used by several functions under `main()`.
|
2022-01-23 18:34:26 +00:00
|
|
|
type MainResult = Result<(), ErrorGuaranteed>;
|
Avoid an unnecessary thread creation at rustdoc startup.
rustdoc's `main()` immediately spawns a thread, M, with a large stack
(16MiB or 32MiB) on which it runs `main_args()`. `main_args()` does a
small amount of options processing and then calls
`setup_callbacks_and_run_in_default_thread_pool_with_globals()`, which
spawns it own thread, and M is not used further.
So, thread M seems unnecessary. However, it does serve a purpose: if the
options processing in `main_args()` panics, that panic is caught when M
is joined. So M can't simply be removed.
However, `main_options()`, which is called by `main_args()`, has a
`catch_fatal_errors()` call within it. We can move that call to `main()`
and change it to the very similar `catch_with_exit_code()`. With that in
place, M can be removed, and panics from options processing will still
be caught appropriately.
Even better, this makes rustdoc's `main()` match rustc's `main()`, which
also uses `catch_with_exit_code()`.
(Also note that the use of a 16MiB/32MiB stack was eliminated from rustc
in #55617.)
2020-08-03 09:37:22 +00:00
|
|
|
|
|
|
|
fn wrap_return(diag: &rustc_errors::Handler, res: Result<(), String>) -> MainResult {
|
2020-05-09 11:37:26 +00:00
|
|
|
match res {
|
2022-12-07 15:08:13 +00:00
|
|
|
Ok(()) => diag.has_errors().map_or(Ok(()), Err),
|
2020-05-09 11:37:26 +00:00
|
|
|
Err(err) => {
|
2022-01-23 00:49:12 +00:00
|
|
|
let reported = diag.struct_err(&err).emit();
|
|
|
|
Err(reported)
|
2020-05-09 11:37:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-16 19:34:08 +00:00
|
|
|
fn run_renderer<'tcx, T: formats::FormatRenderer<'tcx>>(
|
2020-07-30 18:54:26 +00:00
|
|
|
krate: clean::Crate,
|
|
|
|
renderopts: config::RenderOptions,
|
2021-02-12 02:29:22 +00:00
|
|
|
cache: formats::cache::Cache,
|
2021-01-01 04:25:30 +00:00
|
|
|
tcx: TyCtxt<'tcx>,
|
Avoid an unnecessary thread creation at rustdoc startup.
rustdoc's `main()` immediately spawns a thread, M, with a large stack
(16MiB or 32MiB) on which it runs `main_args()`. `main_args()` does a
small amount of options processing and then calls
`setup_callbacks_and_run_in_default_thread_pool_with_globals()`, which
spawns it own thread, and M is not used further.
So, thread M seems unnecessary. However, it does serve a purpose: if the
options processing in `main_args()` panics, that panic is caught when M
is joined. So M can't simply be removed.
However, `main_options()`, which is called by `main_args()`, has a
`catch_fatal_errors()` call within it. We can move that call to `main()`
and change it to the very similar `catch_with_exit_code()`. With that in
place, M can be removed, and panics from options processing will still
be caught appropriately.
Even better, this makes rustdoc's `main()` match rustc's `main()`, which
also uses `catch_with_exit_code()`.
(Also note that the use of a 16MiB/32MiB stack was eliminated from rustc
in #55617.)
2020-08-03 09:37:22 +00:00
|
|
|
) -> MainResult {
|
2021-04-22 23:35:20 +00:00
|
|
|
match formats::run_format::<T>(krate, renderopts, cache, tcx) {
|
2022-12-07 15:08:13 +00:00
|
|
|
Ok(_) => tcx.sess.has_errors().map_or(Ok(()), Err),
|
2020-07-30 18:54:26 +00:00
|
|
|
Err(e) => {
|
2021-04-22 23:32:24 +00:00
|
|
|
let mut msg =
|
|
|
|
tcx.sess.struct_err(&format!("couldn't generate documentation: {}", e.error));
|
2020-07-30 18:54:26 +00:00
|
|
|
let file = e.file.display().to_string();
|
2022-01-27 09:44:25 +00:00
|
|
|
if !file.is_empty() {
|
|
|
|
msg.note(&format!("failed to create or modify \"{}\"", file));
|
2020-07-30 18:54:26 +00:00
|
|
|
}
|
2022-01-27 09:44:25 +00:00
|
|
|
Err(msg.emit())
|
2020-07-30 18:54:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-07 04:36:44 +00:00
|
|
|
fn main_args(at_args: &[String]) -> MainResult {
|
|
|
|
let args = rustc_driver::args::arg_expand_all(at_args);
|
|
|
|
|
|
|
|
let mut options = getopts::Options::new();
|
|
|
|
for option in opts() {
|
|
|
|
(option.apply)(&mut options);
|
|
|
|
}
|
|
|
|
let matches = match options.parse(&args[1..]) {
|
|
|
|
Ok(m) => m,
|
|
|
|
Err(err) => {
|
|
|
|
early_error(ErrorOutputType::default(), &err.to_string());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Note that we discard any distinction between different non-zero exit
|
|
|
|
// codes from `from_matches` here.
|
2022-10-16 23:51:40 +00:00
|
|
|
let (options, render_options) = match config::Options::from_matches(&matches, args) {
|
2022-10-07 04:36:44 +00:00
|
|
|
Ok(opts) => opts,
|
|
|
|
Err(code) => {
|
|
|
|
return if code == 0 {
|
|
|
|
Ok(())
|
|
|
|
} else {
|
|
|
|
Err(ErrorGuaranteed::unchecked_claim_error_was_emitted())
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-02-14 06:01:38 +00:00
|
|
|
let diag = core::new_handler(
|
|
|
|
options.error_format,
|
|
|
|
None,
|
2022-07-06 10:57:41 +00:00
|
|
|
options.diagnostic_width,
|
2022-07-06 12:44:47 +00:00
|
|
|
&options.unstable_opts,
|
2022-02-14 06:01:38 +00:00
|
|
|
);
|
2014-03-07 03:31:41 +00:00
|
|
|
|
2018-10-30 13:47:54 +00:00
|
|
|
match (options.should_test, options.markdown_input()) {
|
2020-05-09 11:37:26 +00:00
|
|
|
(true, true) => return wrap_return(&diag, markdown::test(options)),
|
2020-08-27 16:20:15 +00:00
|
|
|
(true, false) => return doctest::run(options),
|
2019-04-18 01:17:12 +00:00
|
|
|
(false, true) => {
|
2022-10-16 23:19:46 +00:00
|
|
|
let input = options.input.clone();
|
|
|
|
let edition = options.edition;
|
2023-02-06 17:57:45 +00:00
|
|
|
let config = core::create_config(options, &render_options);
|
2022-10-16 23:19:46 +00:00
|
|
|
|
|
|
|
// `markdown::render` can invoke `doctest::make_test`, which
|
|
|
|
// requires session globals and a thread pool, so we use
|
|
|
|
// `run_compiler`.
|
2020-05-09 11:37:26 +00:00
|
|
|
return wrap_return(
|
|
|
|
&diag,
|
2022-10-16 23:19:46 +00:00
|
|
|
interface::run_compiler(config, |_compiler| {
|
|
|
|
markdown::render(&input, render_options, edition)
|
Clean up rustdoc startup.
rustc's startup has several layers, including:
- `interface::run_compiler` passes a closure, `f`, to
`run_in_thread_pool_with_globals`, which creates a thread pool, sets
up session globals, and passes `f` to `create_compiler_and_run`.
- `create_compiler_and_run` creates a `Session`, a `Compiler`, sets the
source map, and calls `f`.
rustdoc is a bit different.
- `main_args` calls `main_options` via
`run_in_thread_pool_with_globals`, which (again) creates a thread pool
(hardcoded to a single thread!) and sets up session globals.
- `main_options` has four different paths.
- The second one calls `interface::run_compiler`, which redoes the
`run_in_thread_pool_with_globals`! This is bad.
- The fourth one calls `interface::create_compiler_and_run`, which is
reasonable.
- The first and third ones don't do anything of note involving the
above functions, except for some symbol interning which requires
session globals.
In other words, rustdoc calls into `rustc_interface` at three different
levels. It's a bit confused, and feels like code where functionality has
been added by different people at different times without fully
understanding how the globally accessible stuff is set up.
This commit tidies things up. It removes the
`run_in_thread_pool_with_globals` call in `main_args`, and adjust the
four paths in `main_options` as follows.
- `markdown::test` calls `test::test_main`, which provides its own
parallelism and so doesn't need a thread pool. It had one small use of
symbol interning, which required session globals, but the commit
removes this.
- `doctest::run` already calls `interface::run_compiler`, so it doesn't
need further adjustment.
- `markdown::render` is simple but needs session globals for interning
(which can't easily be removed), so it's now wrapped in
`create_session_globals_then`.
- The fourth path now uses `interface::run_compiler`, which is
equivalent to the old `run_in_thread_pool_with_globals` +
`create_compiler_and_run` pairing.
2022-10-07 02:57:32 +00:00
|
|
|
}),
|
2020-05-09 11:37:26 +00:00
|
|
|
);
|
2019-12-22 22:42:04 +00:00
|
|
|
}
|
2014-03-07 03:31:41 +00:00
|
|
|
(false, false) => {}
|
2013-12-22 19:23:04 +00:00
|
|
|
}
|
2016-11-23 23:40:52 +00:00
|
|
|
|
2018-10-30 15:53:46 +00:00
|
|
|
// need to move these items separately because we lose them by the time the closure is called,
|
2020-11-25 19:09:11 +00:00
|
|
|
// but we can't create the Handler ahead of time because it's not Send
|
2019-01-30 20:04:56 +00:00
|
|
|
let show_coverage = options.show_coverage;
|
2020-11-12 13:57:44 +00:00
|
|
|
let run_check = options.run_check;
|
2020-07-07 04:13:03 +00:00
|
|
|
|
|
|
|
// First, parse the crate and extract all relevant information.
|
|
|
|
info!("starting to run rustc");
|
|
|
|
|
|
|
|
// Interpret the input file as a rust source file, passing it through the
|
|
|
|
// compiler all the way through the analysis passes. The rustdoc output is
|
|
|
|
// then generated from the cleaned AST of the crate. This runs all the
|
|
|
|
// plug/cleaning passes.
|
Avoid an unnecessary thread creation at rustdoc startup.
rustdoc's `main()` immediately spawns a thread, M, with a large stack
(16MiB or 32MiB) on which it runs `main_args()`. `main_args()` does a
small amount of options processing and then calls
`setup_callbacks_and_run_in_default_thread_pool_with_globals()`, which
spawns it own thread, and M is not used further.
So, thread M seems unnecessary. However, it does serve a purpose: if the
options processing in `main_args()` panics, that panic is caught when M
is joined. So M can't simply be removed.
However, `main_options()`, which is called by `main_args()`, has a
`catch_fatal_errors()` call within it. We can move that call to `main()`
and change it to the very similar `catch_with_exit_code()`. With that in
place, M can be removed, and panics from options processing will still
be caught appropriately.
Even better, this makes rustdoc's `main()` match rustc's `main()`, which
also uses `catch_with_exit_code()`.
(Also note that the use of a 16MiB/32MiB stack was eliminated from rustc
in #55617.)
2020-08-03 09:37:22 +00:00
|
|
|
let crate_version = options.crate_version.clone();
|
2020-12-12 02:57:48 +00:00
|
|
|
|
Avoid an unnecessary thread creation at rustdoc startup.
rustdoc's `main()` immediately spawns a thread, M, with a large stack
(16MiB or 32MiB) on which it runs `main_args()`. `main_args()` does a
small amount of options processing and then calls
`setup_callbacks_and_run_in_default_thread_pool_with_globals()`, which
spawns it own thread, and M is not used further.
So, thread M seems unnecessary. However, it does serve a purpose: if the
options processing in `main_args()` panics, that panic is caught when M
is joined. So M can't simply be removed.
However, `main_options()`, which is called by `main_args()`, has a
`catch_fatal_errors()` call within it. We can move that call to `main()`
and change it to the very similar `catch_with_exit_code()`. With that in
place, M can be removed, and panics from options processing will still
be caught appropriately.
Even better, this makes rustdoc's `main()` match rustc's `main()`, which
also uses `catch_with_exit_code()`.
(Also note that the use of a 16MiB/32MiB stack was eliminated from rustc
in #55617.)
2020-08-03 09:37:22 +00:00
|
|
|
let output_format = options.output_format;
|
2021-09-20 21:08:33 +00:00
|
|
|
let scrape_examples_options = options.scrape_examples_options.clone();
|
2022-12-06 20:56:02 +00:00
|
|
|
let bin_crate = options.bin_crate;
|
Clean up rustdoc startup.
rustc's startup has several layers, including:
- `interface::run_compiler` passes a closure, `f`, to
`run_in_thread_pool_with_globals`, which creates a thread pool, sets
up session globals, and passes `f` to `create_compiler_and_run`.
- `create_compiler_and_run` creates a `Session`, a `Compiler`, sets the
source map, and calls `f`.
rustdoc is a bit different.
- `main_args` calls `main_options` via
`run_in_thread_pool_with_globals`, which (again) creates a thread pool
(hardcoded to a single thread!) and sets up session globals.
- `main_options` has four different paths.
- The second one calls `interface::run_compiler`, which redoes the
`run_in_thread_pool_with_globals`! This is bad.
- The fourth one calls `interface::create_compiler_and_run`, which is
reasonable.
- The first and third ones don't do anything of note involving the
above functions, except for some symbol interning which requires
session globals.
In other words, rustdoc calls into `rustc_interface` at three different
levels. It's a bit confused, and feels like code where functionality has
been added by different people at different times without fully
understanding how the globally accessible stuff is set up.
This commit tidies things up. It removes the
`run_in_thread_pool_with_globals` call in `main_args`, and adjust the
four paths in `main_options` as follows.
- `markdown::test` calls `test::test_main`, which provides its own
parallelism and so doesn't need a thread pool. It had one small use of
symbol interning, which required session globals, but the commit
removes this.
- `doctest::run` already calls `interface::run_compiler`, so it doesn't
need further adjustment.
- `markdown::render` is simple but needs session globals for interning
(which can't easily be removed), so it's now wrapped in
`create_session_globals_then`.
- The fourth path now uses `interface::run_compiler`, which is
equivalent to the old `run_in_thread_pool_with_globals` +
`create_compiler_and_run` pairing.
2022-10-07 02:57:32 +00:00
|
|
|
|
2023-02-06 17:57:45 +00:00
|
|
|
let config = core::create_config(options, &render_options);
|
2020-07-07 04:13:03 +00:00
|
|
|
|
Clean up rustdoc startup.
rustc's startup has several layers, including:
- `interface::run_compiler` passes a closure, `f`, to
`run_in_thread_pool_with_globals`, which creates a thread pool, sets
up session globals, and passes `f` to `create_compiler_and_run`.
- `create_compiler_and_run` creates a `Session`, a `Compiler`, sets the
source map, and calls `f`.
rustdoc is a bit different.
- `main_args` calls `main_options` via
`run_in_thread_pool_with_globals`, which (again) creates a thread pool
(hardcoded to a single thread!) and sets up session globals.
- `main_options` has four different paths.
- The second one calls `interface::run_compiler`, which redoes the
`run_in_thread_pool_with_globals`! This is bad.
- The fourth one calls `interface::create_compiler_and_run`, which is
reasonable.
- The first and third ones don't do anything of note involving the
above functions, except for some symbol interning which requires
session globals.
In other words, rustdoc calls into `rustc_interface` at three different
levels. It's a bit confused, and feels like code where functionality has
been added by different people at different times without fully
understanding how the globally accessible stuff is set up.
This commit tidies things up. It removes the
`run_in_thread_pool_with_globals` call in `main_args`, and adjust the
four paths in `main_options` as follows.
- `markdown::test` calls `test::test_main`, which provides its own
parallelism and so doesn't need a thread pool. It had one small use of
symbol interning, which required session globals, but the commit
removes this.
- `doctest::run` already calls `interface::run_compiler`, so it doesn't
need further adjustment.
- `markdown::render` is simple but needs session globals for interning
(which can't easily be removed), so it's now wrapped in
`create_session_globals_then`.
- The fourth path now uses `interface::run_compiler`, which is
equivalent to the old `run_in_thread_pool_with_globals` +
`create_compiler_and_run` pairing.
2022-10-07 02:57:32 +00:00
|
|
|
interface::run_compiler(config, |compiler| {
|
2022-07-02 05:54:05 +00:00
|
|
|
let sess = compiler.session();
|
2020-07-07 04:13:03 +00:00
|
|
|
|
2022-07-02 05:54:05 +00:00
|
|
|
if sess.opts.describe_lints {
|
2022-11-25 03:42:43 +00:00
|
|
|
let mut lint_store = rustc_lint::new_lint_store(sess.enable_internal_lints());
|
2022-07-02 05:54:05 +00:00
|
|
|
let registered_lints = if let Some(register_lints) = compiler.register_lints() {
|
|
|
|
register_lints(sess, &mut lint_store);
|
|
|
|
true
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
};
|
|
|
|
rustc_driver::describe_lints(sess, &lint_store, registered_lints);
|
|
|
|
return Ok(());
|
|
|
|
}
|
2021-04-06 01:09:43 +00:00
|
|
|
|
2022-07-02 05:54:05 +00:00
|
|
|
compiler.enter(|queries| {
|
2023-02-05 19:05:46 +00:00
|
|
|
let mut gcx = abort_on_err(queries.global_ctxt(), sess);
|
2022-01-23 00:49:12 +00:00
|
|
|
if sess.diagnostic().has_errors_or_lint_errors().is_some() {
|
2020-12-12 02:57:48 +00:00
|
|
|
sess.fatal("Compilation failed, aborting rustdoc");
|
|
|
|
}
|
2019-01-30 20:04:56 +00:00
|
|
|
|
2023-02-07 05:59:50 +00:00
|
|
|
gcx.enter(|tcx| {
|
2021-02-12 02:29:22 +00:00
|
|
|
let (krate, render_opts, mut cache) = sess.time("run_global_ctxt", || {
|
2023-02-05 19:05:46 +00:00
|
|
|
core::run_global_ctxt(tcx, show_coverage, render_options, output_format)
|
2020-12-12 02:57:48 +00:00
|
|
|
});
|
|
|
|
info!("finished with rustc");
|
|
|
|
|
2021-09-20 21:08:33 +00:00
|
|
|
if let Some(options) = scrape_examples_options {
|
2022-11-27 19:11:21 +00:00
|
|
|
return scrape_examples::run(
|
|
|
|
krate,
|
|
|
|
render_opts,
|
|
|
|
cache,
|
|
|
|
tcx,
|
|
|
|
options,
|
2022-12-06 20:56:02 +00:00
|
|
|
bin_crate,
|
2022-11-27 19:11:21 +00:00
|
|
|
);
|
2021-06-03 00:21:48 +00:00
|
|
|
}
|
|
|
|
|
2021-02-12 02:29:22 +00:00
|
|
|
cache.crate_version = crate_version;
|
2020-12-12 02:57:48 +00:00
|
|
|
|
|
|
|
if show_coverage {
|
|
|
|
// if we ran coverage, bail early, we don't need to also generate docs at this point
|
|
|
|
// (also we didn't load in any of the useful passes)
|
|
|
|
return Ok(());
|
|
|
|
} else if run_check {
|
|
|
|
// Since we're in "check" mode, no need to generate anything beyond this point.
|
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
|
|
|
|
info!("going to format");
|
|
|
|
match output_format {
|
2021-01-29 02:00:07 +00:00
|
|
|
config::OutputFormat::Html => sess.time("render_html", || {
|
2021-04-22 23:35:20 +00:00
|
|
|
run_renderer::<html::render::Context<'_>>(krate, render_opts, cache, tcx)
|
2020-12-12 02:57:48 +00:00
|
|
|
}),
|
2021-01-29 02:00:07 +00:00
|
|
|
config::OutputFormat::Json => sess.time("render_json", || {
|
2021-04-22 23:35:20 +00:00
|
|
|
run_renderer::<json::JsonRenderer<'_>>(krate, render_opts, cache, tcx)
|
2020-12-12 02:57:48 +00:00
|
|
|
}),
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2012-11-19 01:56:50 +00:00
|
|
|
}
|