Skip to content

Commit dcc71c0

Browse files
Rollup merge of rust-lang#135716 - Zalathar:usage-no-args, r=lqd
Don't skip argument parsing when running `rustc` with no arguments Setting up the argument parser to parse no arguments is a tiny bit of wasted work, but avoids an otherwise-unnecessary special case, in a scenario (printing a help message and quitting) where perf at this scale really doesn't matter anyway. In particular, this lets us avoid having to deal with multiple different APIs to determine whether the compiler is nightly or not. --- This special-case handling for rustc with no arguments is very very old (long predating 1.0), and used to be much simpler, without any need to set up boolean values to handle various conditional cases. So I don't think it was ever explicitly decided that having this special case was worth the extra complexity; it just started out simple and accumulated complexity over time.
2 parents dde62f9 + 93f69b2 commit dcc71c0

File tree

1 file changed

+1
-10
lines changed
  • compiler/rustc_driver_impl/src

1 file changed

+1
-10
lines changed

compiler/rustc_driver_impl/src/lib.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -1191,15 +1191,6 @@ fn print_flag_list<T>(cmdline_opt: &str, flag_list: &[OptionDesc<T>]) {
11911191
/// be public when using rustc as a library, see
11921192
/// <https://github.com/rust-lang/rust/commit/2b4c33817a5aaecabf4c6598d41e190080ec119e>
11931193
pub fn handle_options(early_dcx: &EarlyDiagCtxt, args: &[String]) -> Option<getopts::Matches> {
1194-
if args.is_empty() {
1195-
// user did not write `-v` nor `-Z unstable-options`, so do not
1196-
// include that extra information.
1197-
let nightly_build =
1198-
rustc_feature::UnstableFeatures::from_environment(None).is_nightly_build();
1199-
usage(false, false, nightly_build);
1200-
return None;
1201-
}
1202-
12031194
// Parse with *all* options defined in the compiler, we don't worry about
12041195
// option stability here we just want to parse as much as possible.
12051196
let mut options = getopts::Options::new();
@@ -1245,7 +1236,7 @@ pub fn handle_options(early_dcx: &EarlyDiagCtxt, args: &[String]) -> Option<geto
12451236
// (unstable option being used on stable)
12461237
nightly_options::check_nightly_options(early_dcx, &matches, &config::rustc_optgroups());
12471238

1248-
if matches.opt_present("h") || matches.opt_present("help") {
1239+
if args.is_empty() || matches.opt_present("h") || matches.opt_present("help") {
12491240
// Only show unstable options in --help if we accept unstable options.
12501241
let unstable_enabled = nightly_options::is_unstable_enabled(&matches);
12511242
let nightly_build = nightly_options::match_is_nightly_build(&matches);

0 commit comments

Comments
 (0)