Rollup merge of #132754 - Zalathar:opts, r=GuillaumeGomez,jieyouxu

Simplify the internal API for declaring command-line options

The internal APIs for declaring command-line options are old, and intimidatingly complex. This PR replaces them with a single function that takes explicit `stability` and `kind` arguments, making it easier to see how each option is handled, and whether it is treated as stable or unstable.

We also don't appear to have any tests for the output of `rustc --help` and similar, so I've added a run-make test to verify that this PR doesn't change any output. (There is already a similar run-make test for rustdoc's help output.)

---

The librustdoc changes are simply adjusting to updated compiler APIs; no functional change intended.

---

A side-effect of these changes is that rustfmt can once again format the entirety of these option declaration lists, which it was not doing before.
This commit is contained in:
Matthias Krüger 2024-11-09 19:16:44 +01:00 committed by GitHub
commit 88acd493f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 807 additions and 594 deletions

View File

@ -937,7 +937,7 @@ fn usage(verbose: bool, include_unstable_options: bool, nightly_build: bool) {
let groups = if verbose { config::rustc_optgroups() } else { config::rustc_short_optgroups() }; let groups = if verbose { config::rustc_optgroups() } else { config::rustc_short_optgroups() };
let mut options = getopts::Options::new(); let mut options = getopts::Options::new();
for option in groups.iter().filter(|x| include_unstable_options || x.is_stable()) { for option in groups.iter().filter(|x| include_unstable_options || x.is_stable()) {
(option.apply)(&mut options); option.apply(&mut options);
} }
let message = "Usage: rustc [OPTIONS] INPUT"; let message = "Usage: rustc [OPTIONS] INPUT";
let nightly_help = if nightly_build { let nightly_help = if nightly_build {
@ -1219,7 +1219,7 @@ pub fn handle_options(early_dcx: &EarlyDiagCtxt, args: &[String]) -> Option<geto
let mut options = getopts::Options::new(); let mut options = getopts::Options::new();
let optgroups = config::rustc_optgroups(); let optgroups = config::rustc_optgroups();
for option in &optgroups { for option in &optgroups {
(option.apply)(&mut options); option.apply(&mut options);
} }
let matches = options.parse(args).unwrap_or_else(|e| { let matches = options.parse(args).unwrap_or_else(|e| {
let msg: Option<String> = match e { let msg: Option<String> = match e {
@ -1233,7 +1233,7 @@ pub fn handle_options(early_dcx: &EarlyDiagCtxt, args: &[String]) -> Option<geto
optgroups.iter().find(|option| option.name == opt).map(|option| { optgroups.iter().find(|option| option.name == opt).map(|option| {
// Print the help just for the option in question. // Print the help just for the option in question.
let mut options = getopts::Options::new(); let mut options = getopts::Options::new();
(option.apply)(&mut options); option.apply(&mut options);
// getopt requires us to pass a function for joining an iterator of // getopt requires us to pass a function for joining an iterator of
// strings, even though in this case we expect exactly one string. // strings, even though in this case we expect exactly one string.
options.usage_with_format(|it| { options.usage_with_format(|it| {

View File

@ -102,7 +102,7 @@ fn new_public_extern_entry<S, I>(locations: I) -> ExternEntry
fn optgroups() -> getopts::Options { fn optgroups() -> getopts::Options {
let mut opts = getopts::Options::new(); let mut opts = getopts::Options::new();
for group in rustc_optgroups() { for group in rustc_optgroups() {
(group.apply)(&mut opts); group.apply(&mut opts);
} }
return opts; return opts;
} }

View File

@ -12,7 +12,7 @@
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::str::{self, FromStr}; use std::str::{self, FromStr};
use std::sync::LazyLock; use std::sync::LazyLock;
use std::{fmt, fs, iter}; use std::{cmp, fmt, fs, iter};
use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
use rustc_data_structures::stable_hasher::{StableOrd, ToStableHashKey}; use rustc_data_structures::stable_hasher::{StableOrd, ToStableHashKey};
@ -1367,13 +1367,38 @@ pub fn build_target_config(early_dcx: &EarlyDiagCtxt, opts: &Options, sysroot: &
} }
#[derive(Copy, Clone, PartialEq, Eq, Debug)] #[derive(Copy, Clone, PartialEq, Eq, Debug)]
enum OptionStability { pub enum OptionStability {
Stable, Stable,
Unstable, Unstable,
} }
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum OptionKind {
/// An option that takes a value, and cannot appear more than once (e.g. `--out-dir`).
///
/// Corresponds to [`getopts::Options::optopt`].
Opt,
/// An option that takes a value, and can appear multiple times (e.g. `--emit`).
///
/// Corresponds to [`getopts::Options::optmulti`].
Multi,
/// An option that does not take a value, and cannot appear more than once (e.g. `--help`).
///
/// Corresponds to [`getopts::Options::optflag`].
/// The `hint` string must be empty.
Flag,
/// An option that does not take a value, and can appear multiple times (e.g. `-O`).
///
/// Corresponds to [`getopts::Options::optflagmulti`].
/// The `hint` string must be empty.
FlagMulti,
}
pub struct RustcOptGroup { pub struct RustcOptGroup {
pub apply: Box<dyn Fn(&mut getopts::Options) -> &mut getopts::Options>, apply: Box<dyn Fn(&mut getopts::Options) -> &mut getopts::Options>,
pub name: &'static str, pub name: &'static str,
stability: OptionStability, stability: OptionStability,
} }
@ -1383,73 +1408,42 @@ pub fn is_stable(&self) -> bool {
self.stability == OptionStability::Stable self.stability == OptionStability::Stable
} }
pub fn stable<F>(name: &'static str, f: F) -> RustcOptGroup pub fn apply(&self, options: &mut getopts::Options) {
where (self.apply)(options);
F: Fn(&mut getopts::Options) -> &mut getopts::Options + 'static,
{
RustcOptGroup { name, apply: Box::new(f), stability: OptionStability::Stable }
}
pub fn unstable<F>(name: &'static str, f: F) -> RustcOptGroup
where
F: Fn(&mut getopts::Options) -> &mut getopts::Options + 'static,
{
RustcOptGroup { name, apply: Box::new(f), stability: OptionStability::Unstable }
} }
} }
// The `opt` local module holds wrappers around the `getopts` API that pub fn make_opt(
// adds extra rustc-specific metadata to each option; such metadata stability: OptionStability,
// is exposed by . The public kind: OptionKind,
// functions below ending with `_u` are the functions that return short_name: &'static str,
// *unstable* options, i.e., options that are only enabled when the long_name: &'static str,
// user also passes the `-Z unstable-options` debugging flag. desc: &'static str,
mod opt { hint: &'static str,
// The `fn flag*` etc below are written so that we can use them ) -> RustcOptGroup {
// in the future; do not warn about them not being used right now. RustcOptGroup {
#![allow(dead_code)] name: cmp::max_by_key(short_name, long_name, |s| s.len()),
stability,
use super::RustcOptGroup; apply: match kind {
OptionKind::Opt => Box::new(move |opts: &mut getopts::Options| {
type R = RustcOptGroup; opts.optopt(short_name, long_name, desc, hint)
type S = &'static str; }),
OptionKind::Multi => Box::new(move |opts: &mut getopts::Options| {
fn stable<F>(name: S, f: F) -> R opts.optmulti(short_name, long_name, desc, hint)
where }),
F: Fn(&mut getopts::Options) -> &mut getopts::Options + 'static, OptionKind::Flag => {
{ assert_eq!(hint, "");
RustcOptGroup::stable(name, f) Box::new(move |opts: &mut getopts::Options| {
} opts.optflag(short_name, long_name, desc)
})
fn unstable<F>(name: S, f: F) -> R }
where OptionKind::FlagMulti => {
F: Fn(&mut getopts::Options) -> &mut getopts::Options + 'static, assert_eq!(hint, "");
{ Box::new(move |opts: &mut getopts::Options| {
RustcOptGroup::unstable(name, f) opts.optflagmulti(short_name, long_name, desc)
} })
}
fn longer(a: S, b: S) -> S { },
if a.len() > b.len() { a } else { b }
}
pub(crate) fn opt_s(a: S, b: S, c: S, d: S) -> R {
stable(longer(a, b), move |opts| opts.optopt(a, b, c, d))
}
pub(crate) fn multi_s(a: S, b: S, c: S, d: S) -> R {
stable(longer(a, b), move |opts| opts.optmulti(a, b, c, d))
}
pub(crate) fn flag_s(a: S, b: S, c: S) -> R {
stable(longer(a, b), move |opts| opts.optflag(a, b, c))
}
pub(crate) fn flagmulti_s(a: S, b: S, c: S) -> R {
stable(longer(a, b), move |opts| opts.optflagmulti(a, b, c))
}
fn opt(a: S, b: S, c: S, d: S) -> R {
unstable(longer(a, b), move |opts| opts.optopt(a, b, c, d))
}
pub(crate) fn multi(a: S, b: S, c: S, d: S) -> R {
unstable(longer(a, b), move |opts| opts.optmulti(a, b, c, d))
} }
} }
@ -1464,46 +1458,60 @@ pub(crate) fn multi(a: S, b: S, c: S, d: S) -> R {
/// including metadata for each option, such as whether the option is /// including metadata for each option, such as whether the option is
/// part of the stable long-term interface for rustc. /// part of the stable long-term interface for rustc.
pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> { pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
use OptionKind::{Flag, FlagMulti, Multi, Opt};
use OptionStability::Stable;
use self::make_opt as opt;
vec![ vec![
opt::flag_s("h", "help", "Display this message"), opt(Stable, Flag, "h", "help", "Display this message", ""),
opt::multi_s("", "cfg", "Configure the compilation environment. opt(
SPEC supports the syntax `NAME[=\"VALUE\"]`.", "SPEC"), Stable,
opt::multi_s("", "check-cfg", "Provide list of expected cfgs for checking", "SPEC"), Multi,
opt::multi_s( "",
"cfg",
"Configure the compilation environment.\n\
SPEC supports the syntax `NAME[=\"VALUE\"]`.",
"SPEC",
),
opt(Stable, Multi, "", "check-cfg", "Provide list of expected cfgs for checking", "SPEC"),
opt(
Stable,
Multi,
"L", "L",
"", "",
"Add a directory to the library search path. The "Add a directory to the library search path. \
optional KIND can be one of dependency, crate, native, The optional KIND can be one of dependency, crate, native, framework, or all (the default).",
framework, or all (the default).",
"[KIND=]PATH", "[KIND=]PATH",
), ),
opt::multi_s( opt(
Stable,
Multi,
"l", "l",
"", "",
"Link the generated crate(s) to the specified native "Link the generated crate(s) to the specified native\n\
library NAME. The optional KIND can be one of library NAME. The optional KIND can be one of\n\
static, framework, or dylib (the default). static, framework, or dylib (the default).\n\
Optional comma separated MODIFIERS (bundle|verbatim|whole-archive|as-needed) Optional comma separated MODIFIERS\n\
may be specified each with a prefix of either '+' to (bundle|verbatim|whole-archive|as-needed)\n\
enable or '-' to disable.", may be specified each with a prefix of either '+' to\n\
enable or '-' to disable.",
"[KIND[:MODIFIERS]=]NAME[:RENAME]", "[KIND[:MODIFIERS]=]NAME[:RENAME]",
), ),
make_crate_type_option(), make_crate_type_option(),
opt::opt_s("", "crate-name", "Specify the name of the crate being built", "NAME"), opt(Stable, Opt, "", "crate-name", "Specify the name of the crate being built", "NAME"),
opt::opt_s( opt(Stable, Opt, "", "edition", &EDITION_STRING, EDITION_NAME_LIST),
"", opt(
"edition", Stable,
&EDITION_STRING, Multi,
EDITION_NAME_LIST,
),
opt::multi_s(
"", "",
"emit", "emit",
"Comma separated list of types of output for \ "Comma separated list of types of output for the compiler to emit",
the compiler to emit",
"[asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info|mir]", "[asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info|mir]",
), ),
opt::multi_s( opt(
Stable,
Multi,
"", "",
"print", "print",
"Compiler information to print on stdout", "Compiler information to print on stdout",
@ -1512,41 +1520,36 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
tls-models|target-spec-json|all-target-specs-json|native-static-libs|\ tls-models|target-spec-json|all-target-specs-json|native-static-libs|\
stack-protector-strategies|link-args|deployment-target]", stack-protector-strategies|link-args|deployment-target]",
), ),
opt::flagmulti_s("g", "", "Equivalent to -C debuginfo=2"), opt(Stable, FlagMulti, "g", "", "Equivalent to -C debuginfo=2", ""),
opt::flagmulti_s("O", "", "Equivalent to -C opt-level=2"), opt(Stable, FlagMulti, "O", "", "Equivalent to -C opt-level=2", ""),
opt::opt_s("o", "", "Write output to <filename>", "FILENAME"), opt(Stable, Opt, "o", "", "Write output to <filename>", "FILENAME"),
opt::opt_s( opt(Stable, Opt, "", "out-dir", "Write output to compiler-chosen filename in <dir>", "DIR"),
"", opt(
"out-dir", Stable,
"Write output to compiler-chosen filename \ Opt,
in <dir>",
"DIR",
),
opt::opt_s(
"", "",
"explain", "explain",
"Provide a detailed explanation of an error \ "Provide a detailed explanation of an error message",
message",
"OPT", "OPT",
), ),
opt::flag_s("", "test", "Build a test harness"), opt(Stable, Flag, "", "test", "Build a test harness", ""),
opt::opt_s("", "target", "Target triple for which the code is compiled", "TARGET"), opt(Stable, Opt, "", "target", "Target triple for which the code is compiled", "TARGET"),
opt::multi_s("A", "allow", "Set lint allowed", "LINT"), opt(Stable, Multi, "A", "allow", "Set lint allowed", "LINT"),
opt::multi_s("W", "warn", "Set lint warnings", "LINT"), opt(Stable, Multi, "W", "warn", "Set lint warnings", "LINT"),
opt::multi_s("", "force-warn", "Set lint force-warn", "LINT"), opt(Stable, Multi, "", "force-warn", "Set lint force-warn", "LINT"),
opt::multi_s("D", "deny", "Set lint denied", "LINT"), opt(Stable, Multi, "D", "deny", "Set lint denied", "LINT"),
opt::multi_s("F", "forbid", "Set lint forbidden", "LINT"), opt(Stable, Multi, "F", "forbid", "Set lint forbidden", "LINT"),
opt::multi_s( opt(
Stable,
Multi,
"", "",
"cap-lints", "cap-lints",
"Set the most restrictive lint level. \ "Set the most restrictive lint level. More restrictive lints are capped at this level",
More restrictive lints are capped at this \
level",
"LEVEL", "LEVEL",
), ),
opt::multi_s("C", "codegen", "Set a codegen option", "OPT[=VALUE]"), opt(Stable, Multi, "C", "codegen", "Set a codegen option", "OPT[=VALUE]"),
opt::flag_s("V", "version", "Print version info and exit"), opt(Stable, Flag, "V", "version", "Print version info and exit", ""),
opt::flag_s("v", "verbose", "Use verbose output"), opt(Stable, Flag, "v", "verbose", "Use verbose output", ""),
] ]
} }
@ -1554,25 +1557,36 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
/// each option, such as whether the option is part of the stable /// each option, such as whether the option is part of the stable
/// long-term interface for rustc. /// long-term interface for rustc.
pub fn rustc_optgroups() -> Vec<RustcOptGroup> { pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
use OptionKind::{Multi, Opt};
use OptionStability::{Stable, Unstable};
use self::make_opt as opt;
let mut opts = rustc_short_optgroups(); let mut opts = rustc_short_optgroups();
// FIXME: none of these descriptions are actually used // FIXME: none of these descriptions are actually used
opts.extend(vec![ opts.extend(vec![
opt::multi_s( opt(
Stable,
Multi,
"", "",
"extern", "extern",
"Specify where an external rust library is located", "Specify where an external rust library is located",
"NAME[=PATH]", "NAME[=PATH]",
), ),
opt::opt_s("", "sysroot", "Override the system root", "PATH"), opt(Stable, Opt, "", "sysroot", "Override the system root", "PATH"),
opt::multi("Z", "", "Set unstable / perma-unstable options", "FLAG"), opt(Unstable, Multi, "Z", "", "Set unstable / perma-unstable options", "FLAG"),
opt::opt_s( opt(
Stable,
Opt,
"", "",
"error-format", "error-format",
"How errors and other messages are produced", "How errors and other messages are produced",
"human|json|short", "human|json|short",
), ),
opt::multi_s("", "json", "Configure the JSON output of the compiler", "CONFIG"), opt(Stable, Multi, "", "json", "Configure the JSON output of the compiler", "CONFIG"),
opt::opt_s( opt(
Stable,
Opt,
"", "",
"color", "color",
"Configure coloring of output: "Configure coloring of output:
@ -1581,19 +1595,23 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
never = never colorize output", never = never colorize output",
"auto|always|never", "auto|always|never",
), ),
opt::opt_s( opt(
Stable,
Opt,
"", "",
"diagnostic-width", "diagnostic-width",
"Inform rustc of the width of the output so that diagnostics can be truncated to fit", "Inform rustc of the width of the output so that diagnostics can be truncated to fit",
"WIDTH", "WIDTH",
), ),
opt::multi_s( opt(
Stable,
Multi,
"", "",
"remap-path-prefix", "remap-path-prefix",
"Remap source names in all output (compiler messages and output files)", "Remap source names in all output (compiler messages and output files)",
"FROM=TO", "FROM=TO",
), ),
opt::multi("", "env-set", "Inject an environment variable", "VAR=VALUE"), opt(Unstable, Multi, "", "env-set", "Inject an environment variable", "VAR=VALUE"),
]); ]);
opts opts
} }
@ -2756,7 +2774,9 @@ fn parse_pretty(early_dcx: &EarlyDiagCtxt, unstable_opts: &UnstableOptions) -> O
} }
pub fn make_crate_type_option() -> RustcOptGroup { pub fn make_crate_type_option() -> RustcOptGroup {
opt::multi_s( make_opt(
OptionStability::Stable,
OptionKind::Multi,
"", "",
"crate-type", "crate-type",
"Comma separated list of types of crates "Comma separated list of types of crates

View File

@ -215,477 +215,482 @@ fn init_logging(early_dcx: &EarlyDiagCtxt) {
} }
fn opts() -> Vec<RustcOptGroup> { fn opts() -> Vec<RustcOptGroup> {
let stable: fn(_, fn(&mut getopts::Options) -> &mut _) -> _ = RustcOptGroup::stable; use rustc_session::config::OptionKind::{Flag, FlagMulti, Multi, Opt};
let unstable: fn(_, fn(&mut getopts::Options) -> &mut _) -> _ = RustcOptGroup::unstable; use rustc_session::config::OptionStability::{Stable, Unstable};
use rustc_session::config::make_opt as opt;
vec![ vec![
stable("h", |o| o.optflagmulti("h", "help", "show this help message")), opt(Stable, FlagMulti, "h", "help", "show this help message", ""),
stable("V", |o| o.optflagmulti("V", "version", "print rustdoc's version")), opt(Stable, FlagMulti, "V", "version", "print rustdoc's version", ""),
stable("v", |o| o.optflagmulti("v", "verbose", "use verbose output")), opt(Stable, FlagMulti, "v", "verbose", "use verbose output", ""),
stable("w", |o| o.optopt("w", "output-format", "the output type to write", "[html]")), opt(Stable, Opt, "w", "output-format", "the output type to write", "[html]"),
stable("output", |o| { opt(
o.optopt( Stable,
"", Opt,
"output", "",
"Which directory to place the output. \ "output",
This option is deprecated, use --out-dir instead.", "Which directory to place the output. This option is deprecated, use --out-dir instead.",
"PATH", "PATH",
) ),
}), opt(Stable, Opt, "o", "out-dir", "which directory to place the output", "PATH"),
stable("o", |o| o.optopt("o", "out-dir", "which directory to place the output", "PATH")), opt(Stable, Opt, "", "crate-name", "specify the name of this crate", "NAME"),
stable("crate-name", |o| {
o.optopt("", "crate-name", "specify the name of this crate", "NAME")
}),
make_crate_type_option(), make_crate_type_option(),
stable("L", |o| { opt(Stable, Multi, "L", "library-path", "directory to add to crate search path", "DIR"),
o.optmulti("L", "library-path", "directory to add to crate search path", "DIR") opt(Stable, Multi, "", "cfg", "pass a --cfg to rustc", ""),
}), opt(Stable, Multi, "", "check-cfg", "pass a --check-cfg to rustc", ""),
stable("cfg", |o| o.optmulti("", "cfg", "pass a --cfg to rustc", "")), opt(Stable, Multi, "", "extern", "pass an --extern to rustc", "NAME[=PATH]"),
stable("check-cfg", |o| o.optmulti("", "check-cfg", "pass a --check-cfg to rustc", "")), opt(
stable("extern", |o| o.optmulti("", "extern", "pass an --extern to rustc", "NAME[=PATH]")), Unstable,
unstable("extern-html-root-url", |o| { Multi,
o.optmulti( "",
"", "extern-html-root-url",
"extern-html-root-url", "base URL to use for dependencies; for example, \
"base URL to use for dependencies; for example, \ \"std=/doc\" links std::vec::Vec to /doc/std/vec/struct.Vec.html",
\"std=/doc\" links std::vec::Vec to /doc/std/vec/struct.Vec.html", "NAME=URL",
"NAME=URL", ),
) opt(
}), Unstable,
unstable("extern-html-root-takes-precedence", |o| { FlagMulti,
o.optflagmulti( "",
"", "extern-html-root-takes-precedence",
"extern-html-root-takes-precedence", "give precedence to `--extern-html-root-url`, not `html_root_url`",
"give precedence to `--extern-html-root-url`, not `html_root_url`", "",
) ),
}), opt(Stable, Multi, "C", "codegen", "pass a codegen option to rustc", "OPT[=VALUE]"),
stable("C", |o| { opt(Stable, FlagMulti, "", "document-private-items", "document private items", ""),
o.optmulti("C", "codegen", "pass a codegen option to rustc", "OPT[=VALUE]") opt(
}), Unstable,
stable("document-private-items", |o| { FlagMulti,
o.optflagmulti("", "document-private-items", "document private items") "",
}), "document-hidden-items",
unstable("document-hidden-items", |o| { "document items that have doc(hidden)",
o.optflagmulti("", "document-hidden-items", "document items that have doc(hidden)") "",
}), ),
stable("test", |o| o.optflagmulti("", "test", "run code examples as tests")), opt(Stable, FlagMulti, "", "test", "run code examples as tests", ""),
stable("test-args", |o| { opt(Stable, Multi, "", "test-args", "arguments to pass to the test runner", "ARGS"),
o.optmulti("", "test-args", "arguments to pass to the test runner", "ARGS") opt(
}), Stable,
stable("test-run-directory", |o| { Opt,
o.optopt( "",
"", "test-run-directory",
"test-run-directory", "The working directory in which to run tests",
"The working directory in which to run tests", "PATH",
"PATH", ),
) opt(Stable, Opt, "", "target", "target triple to document", "TRIPLE"),
}), opt(
stable("target", |o| o.optopt("", "target", "target triple to document", "TRIPLE")), Stable,
stable("markdown-css", |o| { Multi,
o.optmulti( "",
"", "markdown-css",
"markdown-css", "CSS files to include via <link> in a rendered Markdown file",
"CSS files to include via <link> in a rendered Markdown file", "FILES",
"FILES", ),
) opt(
}), Stable,
stable("html-in-header", |o| { Multi,
o.optmulti( "",
"", "html-in-header",
"html-in-header", "files to include inline in the <head> section of a rendered Markdown file \
"files to include inline in the <head> section of a rendered Markdown file \ or generated documentation",
or generated documentation", "FILES",
"FILES", ),
) opt(
}), Stable,
stable("html-before-content", |o| { Multi,
o.optmulti( "",
"", "html-before-content",
"html-before-content", "files to include inline between <body> and the content of a rendered \
"files to include inline between <body> and the content of a rendered \ Markdown file or generated documentation",
Markdown file or generated documentation", "FILES",
"FILES", ),
) opt(
}), Stable,
stable("html-after-content", |o| { Multi,
o.optmulti( "",
"", "html-after-content",
"html-after-content", "files to include inline between the content and </body> of a rendered \
"files to include inline between the content and </body> of a rendered \ Markdown file or generated documentation",
Markdown file or generated documentation", "FILES",
"FILES", ),
) opt(
}), Unstable,
unstable("markdown-before-content", |o| { Multi,
o.optmulti( "",
"", "markdown-before-content",
"markdown-before-content", "files to include inline between <body> and the content of a rendered \
"files to include inline between <body> and the content of a rendered \ Markdown file or generated documentation",
Markdown file or generated documentation", "FILES",
"FILES", ),
) opt(
}), Unstable,
unstable("markdown-after-content", |o| { Multi,
o.optmulti( "",
"", "markdown-after-content",
"markdown-after-content", "files to include inline between the content and </body> of a rendered \
"files to include inline between the content and </body> of a rendered \ Markdown file or generated documentation",
Markdown file or generated documentation", "FILES",
"FILES", ),
) opt(Stable, Opt, "", "markdown-playground-url", "URL to send code snippets to", "URL"),
}), opt(Stable, FlagMulti, "", "markdown-no-toc", "don't include table of contents", ""),
stable("markdown-playground-url", |o| { opt(
o.optopt("", "markdown-playground-url", "URL to send code snippets to", "URL") Stable,
}), Opt,
stable("markdown-no-toc", |o| { "e",
o.optflagmulti("", "markdown-no-toc", "don't include table of contents") "extend-css",
}), "To add some CSS rules with a given file to generate doc with your own theme. \
stable("e", |o| { However, your theme might break if the rustdoc's generated HTML changes, so be careful!",
o.optopt( "PATH",
"e", ),
"extend-css", opt(
"To add some CSS rules with a given file to generate doc with your \ Unstable,
own theme. However, your theme might break if the rustdoc's generated HTML \ Multi,
changes, so be careful!", "Z",
"PATH", "",
) "unstable / perma-unstable options (only on nightly build)",
}), "FLAG",
unstable("Z", |o| { ),
o.optmulti("Z", "", "unstable / perma-unstable options (only on nightly build)", "FLAG") opt(Stable, Opt, "", "sysroot", "Override the system root", "PATH"),
}), opt(
stable("sysroot", |o| o.optopt("", "sysroot", "Override the system root", "PATH")), Unstable,
unstable("playground-url", |o| { Opt,
o.optopt( "",
"", "playground-url",
"playground-url", "URL to send code snippets to, may be reset by --markdown-playground-url \
"URL to send code snippets to, may be reset by --markdown-playground-url \ or `#![doc(html_playground_url=...)]`",
or `#![doc(html_playground_url=...)]`", "URL",
"URL", ),
) opt(
}), Unstable,
unstable("display-doctest-warnings", |o| { FlagMulti,
o.optflagmulti( "",
"", "display-doctest-warnings",
"display-doctest-warnings", "show warnings that originate in doctests",
"show warnings that originate in doctests", "",
) ),
}), opt(
stable("crate-version", |o| { Stable,
o.optopt("", "crate-version", "crate version to print into documentation", "VERSION") Opt,
}), "",
unstable("sort-modules-by-appearance", |o| { "crate-version",
o.optflagmulti( "crate version to print into documentation",
"", "VERSION",
"sort-modules-by-appearance", ),
"sort modules by where they appear in the program, rather than alphabetically", opt(
) Unstable,
}), FlagMulti,
stable("default-theme", |o| { "",
o.optopt( "sort-modules-by-appearance",
"", "sort modules by where they appear in the program, rather than alphabetically",
"default-theme", "",
"Set the default theme. THEME should be the theme name, generally lowercase. \ ),
If an unknown default theme is specified, the builtin default is used. \ opt(
The set of themes, and the rustdoc built-in default, are not stable.", Stable,
"THEME", Opt,
) "",
}), "default-theme",
unstable("default-setting", |o| { "Set the default theme. THEME should be the theme name, generally lowercase. \
o.optmulti( If an unknown default theme is specified, the builtin default is used. \
"", The set of themes, and the rustdoc built-in default, are not stable.",
"default-setting", "THEME",
"Default value for a rustdoc setting (used when \"rustdoc-SETTING\" is absent \ ),
from web browser Local Storage). If VALUE is not supplied, \"true\" is used. \ opt(
Supported SETTINGs and VALUEs are not documented and not stable.", Unstable,
"SETTING[=VALUE]", Multi,
) "",
}), "default-setting",
stable("theme", |o| { "Default value for a rustdoc setting (used when \"rustdoc-SETTING\" is absent \
o.optmulti( from web browser Local Storage). If VALUE is not supplied, \"true\" is used. \
"", Supported SETTINGs and VALUEs are not documented and not stable.",
"theme", "SETTING[=VALUE]",
"additional themes which will be added to the generated docs", ),
"FILES", opt(
) Stable,
}), Multi,
stable("check-theme", |o| { "",
o.optmulti("", "check-theme", "check if given theme is valid", "FILES") "theme",
}), "additional themes which will be added to the generated docs",
unstable("resource-suffix", |o| { "FILES",
o.optopt( ),
"", opt(Stable, Multi, "", "check-theme", "check if given theme is valid", "FILES"),
"resource-suffix", opt(
"suffix to add to CSS and JavaScript files, e.g., \"search-index.js\" will \ Unstable,
become \"search-index-suffix.js\"", Opt,
"PATH", "",
) "resource-suffix",
}), "suffix to add to CSS and JavaScript files, \
stable("edition", |o| { e.g., \"search-index.js\" will become \"search-index-suffix.js\"",
o.optopt( "PATH",
"", ),
"edition", opt(
"edition to use when compiling rust code (default: 2015)", Stable,
"EDITION", Opt,
) "",
}), "edition",
stable("color", |o| { "edition to use when compiling rust code (default: 2015)",
o.optopt( "EDITION",
"", ),
"color", opt(
"Configure coloring of output: Stable,
Opt,
"",
"color",
"Configure coloring of output:
auto = colorize, if output goes to a tty (default); auto = colorize, if output goes to a tty (default);
always = always colorize output; always = always colorize output;
never = never colorize output", never = never colorize output",
"auto|always|never", "auto|always|never",
) ),
}), opt(
stable("error-format", |o| { Stable,
o.optopt( Opt,
"", "",
"error-format", "error-format",
"How errors and other messages are produced", "How errors and other messages are produced",
"human|json|short", "human|json|short",
) ),
}), opt(
stable("diagnostic-width", |o| { Stable,
o.optopt( Opt,
"", "",
"diagnostic-width", "diagnostic-width",
"Provide width of the output for truncated error messages", "Provide width of the output for truncated error messages",
"WIDTH", "WIDTH",
) ),
}), opt(Stable, Opt, "", "json", "Configure the structure of JSON diagnostics", "CONFIG"),
stable("json", |o| { opt(Stable, Multi, "A", "allow", "Set lint allowed", "LINT"),
o.optopt("", "json", "Configure the structure of JSON diagnostics", "CONFIG") opt(Stable, Multi, "W", "warn", "Set lint warnings", "LINT"),
}), opt(Stable, Multi, "", "force-warn", "Set lint force-warn", "LINT"),
stable("allow", |o| o.optmulti("A", "allow", "Set lint allowed", "LINT")), opt(Stable, Multi, "D", "deny", "Set lint denied", "LINT"),
stable("warn", |o| o.optmulti("W", "warn", "Set lint warnings", "LINT")), opt(Stable, Multi, "F", "forbid", "Set lint forbidden", "LINT"),
stable("force-warn", |o| o.optmulti("", "force-warn", "Set lint force-warn", "LINT")), opt(
stable("deny", |o| o.optmulti("D", "deny", "Set lint denied", "LINT")), Stable,
stable("forbid", |o| o.optmulti("F", "forbid", "Set lint forbidden", "LINT")), Multi,
stable("cap-lints", |o| { "",
o.optmulti( "cap-lints",
"", "Set the most restrictive lint level. \
"cap-lints", More restrictive lints are capped at this level. \
"Set the most restrictive lint level. \ By default, it is at `forbid` level.",
More restrictive lints are capped at this \ "LEVEL",
level. By default, it is at `forbid` level.", ),
"LEVEL", opt(Unstable, Opt, "", "index-page", "Markdown file to be used as index page", "PATH"),
) opt(
}), Unstable,
unstable("index-page", |o| { FlagMulti,
o.optopt("", "index-page", "Markdown file to be used as index page", "PATH") "",
}), "enable-index-page",
unstable("enable-index-page", |o| { "To enable generation of the index page",
o.optflagmulti("", "enable-index-page", "To enable generation of the index page") "",
}), ),
unstable("static-root-path", |o| { opt(
o.optopt( Unstable,
"", Opt,
"static-root-path", "",
"Path string to force loading static files from in output pages. \ "static-root-path",
If not set, uses combinations of '../' to reach the documentation root.", "Path string to force loading static files from in output pages. \
"PATH", If not set, uses combinations of '../' to reach the documentation root.",
) "PATH",
}), ),
unstable("persist-doctests", |o| { opt(
o.optopt( Unstable,
"", Opt,
"persist-doctests", "",
"Directory to persist doctest executables into", "persist-doctests",
"PATH", "Directory to persist doctest executables into",
) "PATH",
}), ),
unstable("show-coverage", |o| { opt(
o.optflagmulti( Unstable,
"", FlagMulti,
"show-coverage", "",
"calculate percentage of public items with documentation", "show-coverage",
) "calculate percentage of public items with documentation",
}), "",
unstable("enable-per-target-ignores", |o| { ),
o.optflagmulti( opt(
"", Unstable,
"enable-per-target-ignores", FlagMulti,
"parse ignore-foo for ignoring doctests on a per-target basis", "",
) "enable-per-target-ignores",
}), "parse ignore-foo for ignoring doctests on a per-target basis",
unstable("runtool", |o| { "",
o.optopt( ),
"", opt(
"runtool", Unstable,
"", Opt,
"The tool to run tests with when building for a different target than host", "",
) "runtool",
}), "",
unstable("runtool-arg", |o| { "The tool to run tests with when building for a different target than host",
o.optmulti( ),
"", opt(
"runtool-arg", Unstable,
"", Multi,
"One (of possibly many) arguments to pass to the runtool", "",
) "runtool-arg",
}), "",
unstable("test-builder", |o| { "One (of possibly many) arguments to pass to the runtool",
o.optopt("", "test-builder", "The rustc-like binary to use as the test builder", "PATH") ),
}), opt(
unstable("test-builder-wrapper", |o| { Unstable,
o.optmulti( Opt,
"", "",
"test-builder-wrapper", "test-builder",
"Wrapper program to pass test-builder and arguments", "The rustc-like binary to use as the test builder",
"PATH", "PATH",
) ),
}), opt(
unstable("check", |o| o.optflagmulti("", "check", "Run rustdoc checks")), Unstable,
unstable("generate-redirect-map", |o| { Multi,
o.optflagmulti( "",
"", "test-builder-wrapper",
"generate-redirect-map", "Wrapper program to pass test-builder and arguments",
"Generate JSON file at the top level instead of generating HTML redirection files", "PATH",
) ),
}), opt(Unstable, FlagMulti, "", "check", "Run rustdoc checks", ""),
unstable("emit", |o| { opt(
o.optmulti( Unstable,
"", FlagMulti,
"emit", "",
"Comma separated list of types of output for rustdoc to emit", "generate-redirect-map",
"[unversioned-shared-resources,toolchain-shared-resources,invocation-specific]", "Generate JSON file at the top level instead of generating HTML redirection files",
) "",
}), ),
unstable("no-run", |o| { opt(
o.optflagmulti("", "no-run", "Compile doctests without running them") Unstable,
}), Multi,
unstable("remap-path-prefix", |o| { "",
o.optmulti( "emit",
"", "Comma separated list of types of output for rustdoc to emit",
"remap-path-prefix", "[unversioned-shared-resources,toolchain-shared-resources,invocation-specific]",
"Remap source names in compiler messages", ),
"FROM=TO", opt(Unstable, FlagMulti, "", "no-run", "Compile doctests without running them", ""),
) opt(
}), Unstable,
unstable("show-type-layout", |o| { Multi,
o.optflagmulti("", "show-type-layout", "Include the memory layout of types in the docs") "",
}), "remap-path-prefix",
unstable("nocapture", |o| { "Remap source names in compiler messages",
o.optflag("", "nocapture", "Don't capture stdout and stderr of tests") "FROM=TO",
}), ),
unstable("generate-link-to-definition", |o| { opt(
o.optflag( Unstable,
"", FlagMulti,
"generate-link-to-definition", "",
"Make the identifiers in the HTML source code pages navigable", "show-type-layout",
) "Include the memory layout of types in the docs",
}), "",
unstable("scrape-examples-output-path", |o| { ),
o.optopt( opt(Unstable, Flag, "", "nocapture", "Don't capture stdout and stderr of tests", ""),
"", opt(
"scrape-examples-output-path", Unstable,
"", Flag,
"collect function call information and output at the given path", "",
) "generate-link-to-definition",
}), "Make the identifiers in the HTML source code pages navigable",
unstable("scrape-examples-target-crate", |o| { "",
o.optmulti( ),
"", opt(
"scrape-examples-target-crate", Unstable,
"", Opt,
"collect function call information for functions from the target crate", "",
) "scrape-examples-output-path",
}), "",
unstable("scrape-tests", |o| { "collect function call information and output at the given path",
o.optflag("", "scrape-tests", "Include test code when scraping examples") ),
}), opt(
unstable("with-examples", |o| { Unstable,
o.optmulti( Multi,
"", "",
"with-examples", "scrape-examples-target-crate",
"", "",
"path to function call information (for displaying examples in the documentation)", "collect function call information for functions from the target crate",
) ),
}), opt(Unstable, Flag, "", "scrape-tests", "Include test code when scraping examples", ""),
unstable("merge", |o| { opt(
o.optopt( Unstable,
"", Multi,
"merge", "",
"Controls how rustdoc handles files from previously documented crates in the doc root "with-examples",
none = Do not write cross-crate information to the --out-dir "",
shared = Append current crate's info to files found in the --out-dir "path to function call information (for displaying examples in the documentation)",
finalize = Write current crate's info and --include-parts-dir info to the --out-dir, overwriting conflicting files", ),
"none|shared|finalize", opt(
) Unstable,
}), Opt,
unstable("parts-out-dir", |o| { "",
o.optopt( "merge",
"", "Controls how rustdoc handles files from previously documented crates in the doc root\n\
"parts-out-dir", none = Do not write cross-crate information to the --out-dir\n\
"Writes trait implementations and other info for the current crate to provided path. Only use with --merge=none", shared = Append current crate's info to files found in the --out-dir\n\
"path/to/doc.parts/<crate-name>", finalize = Write current crate's info and --include-parts-dir info to the --out-dir, overwriting conflicting files",
) "none|shared|finalize",
}), ),
unstable("include-parts-dir", |o| { opt(
o.optmulti( Unstable,
"", Opt,
"include-parts-dir", "",
"Includes trait implementations and other crate info from provided path. Only use with --merge=finalize", "parts-out-dir",
"path/to/doc.parts/<crate-name>", "Writes trait implementations and other info for the current crate to provided path. Only use with --merge=none",
) "path/to/doc.parts/<crate-name>",
}), ),
opt(
Unstable,
Multi,
"",
"include-parts-dir",
"Includes trait implementations and other crate info from provided path. Only use with --merge=finalize",
"path/to/doc.parts/<crate-name>",
),
// deprecated / removed options // deprecated / removed options
unstable("disable-minification", |o| o.optflagmulti("", "disable-minification", "removed")), opt(Unstable, FlagMulti, "", "disable-minification", "removed", ""),
stable("plugin-path", |o| { opt(
o.optmulti( Stable,
"", Multi,
"plugin-path", "",
"removed, see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \ "plugin-path",
for more information", "removed, see issue #44136 <https://github.com/rust-lang/rust/issues/44136> for more information",
"DIR", "DIR",
) ),
}), opt(
stable("passes", |o| { Stable,
o.optmulti( Multi,
"", "",
"passes", "passes",
"removed, see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \ "removed, see issue #44136 <https://github.com/rust-lang/rust/issues/44136> for more information",
for more information", "PASSES",
"PASSES", ),
) opt(
}), Stable,
stable("plugins", |o| { Multi,
o.optmulti( "",
"", "plugins",
"plugins", "removed, see issue #44136 <https://github.com/rust-lang/rust/issues/44136> for more information",
"removed, see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \ "PLUGINS",
for more information", ),
"PLUGINS", opt(
) Stable,
}), FlagMulti,
stable("no-default", |o| { "",
o.optflagmulti( "no-defaults",
"", "removed, see issue #44136 <https://github.com/rust-lang/rust/issues/44136> for more information",
"no-defaults", "",
"removed, see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \ ),
for more information", opt(
) Stable,
}), Opt,
stable("r", |o| { "r",
o.optopt( "input-format",
"r", "removed, see issue #44136 <https://github.com/rust-lang/rust/issues/44136> for more information",
"input-format", "[rust]",
"removed, see issue #44136 <https://github.com/rust-lang/rust/issues/44136> \ ),
for more information", opt(Unstable, Flag, "", "html-no-source", "Disable HTML source code pages generation", ""),
"[rust]",
)
}),
unstable("html-no-source", |o| {
o.optflag("", "html-no-source", "Disable HTML source code pages generation")
}),
] ]
} }
fn usage(argv0: &str) { fn usage(argv0: &str) {
let mut options = getopts::Options::new(); let mut options = getopts::Options::new();
for option in opts() { for option in opts() {
(option.apply)(&mut options); option.apply(&mut options);
} }
println!("{}", options.usage(&format!("{argv0} [options] <input>"))); println!("{}", options.usage(&format!("{argv0} [options] <input>")));
println!(" @path Read newline separated options from `path`\n"); println!(" @path Read newline separated options from `path`\n");
@ -769,7 +774,7 @@ fn main_args(
let mut options = getopts::Options::new(); let mut options = getopts::Options::new();
for option in opts() { for option in opts() {
(option.apply)(&mut options); option.apply(&mut options);
} }
let matches = match options.parse(&args) { let matches = match options.parse(&args) {
Ok(m) => m, Ok(m) => m,

View File

@ -41,6 +41,7 @@ pub mod rfs {
pub use object; pub use object;
pub use regex; pub use regex;
pub use serde_json; pub use serde_json;
pub use similar;
pub use wasmparser; pub use wasmparser;
// tidy-alphabetical-end // tidy-alphabetical-end

View File

@ -0,0 +1,29 @@
@@ -51,10 +51,27 @@
Set a codegen option
-V, --version Print version info and exit
-v, --verbose Use verbose output
+ --extern NAME[=PATH]
+ Specify where an external rust library is located
+ --sysroot PATH Override the system root
+ --error-format human|json|short
+ How errors and other messages are produced
+ --json CONFIG Configure the JSON output of the compiler
+ --color auto|always|never
+ Configure coloring of output:
+ auto = colorize, if output goes to a tty (default);
+ always = always colorize output;
+ never = never colorize output
+ --diagnostic-width WIDTH
+ Inform rustc of the width of the output so that
+ diagnostics can be truncated to fit
+ --remap-path-prefix FROM=TO
+ Remap source names in all output (compiler messages
+ and output files)
+ @path Read newline separated options from `path`
Additional help:
-C help Print codegen options
-W help Print 'lint' options and default settings
-Z help Print unstable compiler options
- --help -v Print the full set of options rustc accepts

View File

@ -0,0 +1,77 @@
Usage: rustc [OPTIONS] INPUT
Options:
-h, --help Display this message
--cfg SPEC Configure the compilation environment.
SPEC supports the syntax `NAME[="VALUE"]`.
--check-cfg SPEC
Provide list of expected cfgs for checking
-L [KIND=]PATH Add a directory to the library search path. The
optional KIND can be one of dependency, crate, native,
framework, or all (the default).
-l [KIND[:MODIFIERS]=]NAME[:RENAME]
Link the generated crate(s) to the specified native
library NAME. The optional KIND can be one of
static, framework, or dylib (the default).
Optional comma separated MODIFIERS
(bundle|verbatim|whole-archive|as-needed)
may be specified each with a prefix of either '+' to
enable or '-' to disable.
--crate-type [bin|lib|rlib|dylib|cdylib|staticlib|proc-macro]
Comma separated list of types of crates
for the compiler to emit
--crate-name NAME
Specify the name of the crate being built
--edition 2015|2018|2021|2024
Specify which edition of the compiler to use when
compiling code. The default is 2015 and the latest
stable edition is 2021.
--emit [asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info|mir]
Comma separated list of types of output for the
compiler to emit
--print [crate-name|file-names|sysroot|target-libdir|cfg|check-cfg|calling-conventions|target-list|target-cpus|target-features|relocation-models|code-models|tls-models|target-spec-json|all-target-specs-json|native-static-libs|stack-protector-strategies|link-args|deployment-target]
Compiler information to print on stdout
-g Equivalent to -C debuginfo=2
-O Equivalent to -C opt-level=2
-o FILENAME Write output to <filename>
--out-dir DIR Write output to compiler-chosen filename in <dir>
--explain OPT Provide a detailed explanation of an error message
--test Build a test harness
--target TARGET Target triple for which the code is compiled
-A, --allow LINT Set lint allowed
-W, --warn LINT Set lint warnings
--force-warn LINT
Set lint force-warn
-D, --deny LINT Set lint denied
-F, --forbid LINT Set lint forbidden
--cap-lints LEVEL
Set the most restrictive lint level. More restrictive
lints are capped at this level
-C, --codegen OPT[=VALUE]
Set a codegen option
-V, --version Print version info and exit
-v, --verbose Use verbose output
--extern NAME[=PATH]
Specify where an external rust library is located
--sysroot PATH Override the system root
--error-format human|json|short
How errors and other messages are produced
--json CONFIG Configure the JSON output of the compiler
--color auto|always|never
Configure coloring of output:
auto = colorize, if output goes to a tty (default);
always = always colorize output;
never = never colorize output
--diagnostic-width WIDTH
Inform rustc of the width of the output so that
diagnostics can be truncated to fit
--remap-path-prefix FROM=TO
Remap source names in all output (compiler messages
and output files)
@path Read newline separated options from `path`
Additional help:
-C help Print codegen options
-W help Print 'lint' options and default settings
-Z help Print unstable compiler options

View File

@ -0,0 +1,60 @@
Usage: rustc [OPTIONS] INPUT
Options:
-h, --help Display this message
--cfg SPEC Configure the compilation environment.
SPEC supports the syntax `NAME[="VALUE"]`.
--check-cfg SPEC
Provide list of expected cfgs for checking
-L [KIND=]PATH Add a directory to the library search path. The
optional KIND can be one of dependency, crate, native,
framework, or all (the default).
-l [KIND[:MODIFIERS]=]NAME[:RENAME]
Link the generated crate(s) to the specified native
library NAME. The optional KIND can be one of
static, framework, or dylib (the default).
Optional comma separated MODIFIERS
(bundle|verbatim|whole-archive|as-needed)
may be specified each with a prefix of either '+' to
enable or '-' to disable.
--crate-type [bin|lib|rlib|dylib|cdylib|staticlib|proc-macro]
Comma separated list of types of crates
for the compiler to emit
--crate-name NAME
Specify the name of the crate being built
--edition 2015|2018|2021|2024
Specify which edition of the compiler to use when
compiling code. The default is 2015 and the latest
stable edition is 2021.
--emit [asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info|mir]
Comma separated list of types of output for the
compiler to emit
--print [crate-name|file-names|sysroot|target-libdir|cfg|check-cfg|calling-conventions|target-list|target-cpus|target-features|relocation-models|code-models|tls-models|target-spec-json|all-target-specs-json|native-static-libs|stack-protector-strategies|link-args|deployment-target]
Compiler information to print on stdout
-g Equivalent to -C debuginfo=2
-O Equivalent to -C opt-level=2
-o FILENAME Write output to <filename>
--out-dir DIR Write output to compiler-chosen filename in <dir>
--explain OPT Provide a detailed explanation of an error message
--test Build a test harness
--target TARGET Target triple for which the code is compiled
-A, --allow LINT Set lint allowed
-W, --warn LINT Set lint warnings
--force-warn LINT
Set lint force-warn
-D, --deny LINT Set lint denied
-F, --forbid LINT Set lint forbidden
--cap-lints LEVEL
Set the most restrictive lint level. More restrictive
lints are capped at this level
-C, --codegen OPT[=VALUE]
Set a codegen option
-V, --version Print version info and exit
-v, --verbose Use verbose output
Additional help:
-C help Print codegen options
-W help Print 'lint' options and default settings
-Z help Print unstable compiler options
--help -v Print the full set of options rustc accepts

View File

@ -0,0 +1,21 @@
// Tests `rustc --help` and similar invocations against snapshots and each other.
use run_make_support::{bare_rustc, diff, similar};
fn main() {
// `rustc --help`
let help = bare_rustc().arg("--help").run().stdout_utf8();
diff().expected_file("help.stdout").actual_text("(rustc --help)", &help).run();
// `rustc` should be the same as `rustc --help`
let bare = bare_rustc().run().stdout_utf8();
diff().expected_text("(rustc --help)", &help).actual_text("(rustc)", &bare).run();
// `rustc --help -v` should give a similar but longer help message
let help_v = bare_rustc().arg("--help").arg("-v").run().stdout_utf8();
diff().expected_file("help-v.stdout").actual_text("(rustc --help -v)", &help_v).run();
// Check the diff between `rustc --help` and `rustc --help -v`.
let help_v_diff = similar::TextDiff::from_lines(&help, &help_v).unified_diff().to_string();
diff().expected_file("help-v.diff").actual_text("actual", &help_v_diff).run();
}