rustc_driver_impl

Function handle_options

Source
pub fn handle_options(
    early_dcx: &EarlyDiagCtxt,
    args: &[String],
) -> Option<Matches>
Expand description

Process command line options. Emits messages as appropriate. If compilation should continue, returns a getopts::Matches object parsed from args, otherwise returns None.

The compiler’s handling of options is a little complicated as it ties into our stability story. The current intention of each compiler option is to have one of two modes:

  1. An option is stable and can be used everywhere.
  2. An option is unstable, and can only be used on nightly.

Like unstable library and language features, however, unstable options have always required a form of “opt in” to indicate that you’re using them. This provides the easy ability to scan a code base to check to see if anything unstable is being used. Currently, this “opt in” is the -Z “zed” flag.

All options behind -Z are considered unstable by default. Other top-level options can also be considered unstable, and they were unlocked through the -Z unstable-options flag. Note that -Z remains to be the root of instability in both cases, though.

So with all that in mind, the comments below have some more detail about the contortions done here to get things to work out correctly.

This does not need to be pub for rustc itself, but @chaosite needs it to be public when using rustc as a library, see https://github.com/rust-lang/rust/commit/2b4c33817a5aaecabf4c6598d41e190080ec119e