diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2025-01-19 11:48:17 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-19 11:48:17 +0100 |
| commit | dcc71c06373770e0058190b5ac86f03c8d99cd26 (patch) | |
| tree | e75033fbed42810bdb410e5efd796eb22f7a0acd | |
| parent | dde62f9be54ad3015c056fd19222a283185c1641 (diff) | |
| parent | 93f69b23006d180e2f6cf2d6f7efeab17b2c2cf2 (diff) | |
| download | rust-dcc71c06373770e0058190b5ac86f03c8d99cd26.tar.gz rust-dcc71c06373770e0058190b5ac86f03c8d99cd26.zip | |
Rollup merge of #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.
| -rw-r--r-- | compiler/rustc_driver_impl/src/lib.rs | 11 |
1 files changed, 1 insertions, 10 deletions
diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index 0413e5e8634..f7e7aa64614 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -1191,15 +1191,6 @@ fn print_flag_list<T>(cmdline_opt: &str, flag_list: &[OptionDesc<T>]) { /// be public when using rustc as a library, see /// <https://github.com/rust-lang/rust/commit/2b4c33817a5aaecabf4c6598d41e190080ec119e> pub fn handle_options(early_dcx: &EarlyDiagCtxt, args: &[String]) -> Option<getopts::Matches> { - if args.is_empty() { - // user did not write `-v` nor `-Z unstable-options`, so do not - // include that extra information. - let nightly_build = - rustc_feature::UnstableFeatures::from_environment(None).is_nightly_build(); - usage(false, false, nightly_build); - return None; - } - // Parse with *all* options defined in the compiler, we don't worry about // option stability here we just want to parse as much as possible. let mut options = getopts::Options::new(); @@ -1245,7 +1236,7 @@ pub fn handle_options(early_dcx: &EarlyDiagCtxt, args: &[String]) -> Option<geto // (unstable option being used on stable) nightly_options::check_nightly_options(early_dcx, &matches, &config::rustc_optgroups()); - if matches.opt_present("h") || matches.opt_present("help") { + if args.is_empty() || matches.opt_present("h") || matches.opt_present("help") { // Only show unstable options in --help if we accept unstable options. let unstable_enabled = nightly_options::is_unstable_enabled(&matches); let nightly_build = nightly_options::match_is_nightly_build(&matches); |
