]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_session/src/options.rs
clippy::single_char_pattern
[rust.git] / compiler / rustc_session / src / options.rs
1 use crate::config::*;
2
3 use crate::early_error;
4 use crate::lint;
5 use crate::search_paths::SearchPath;
6 use crate::utils::NativeLib;
7
8 use rustc_target::spec::{CodeModel, LinkerFlavor, MergeFunctions, PanicStrategy, SanitizerSet};
9 use rustc_target::spec::{RelocModel, RelroLevel, SplitDebuginfo, TargetTriple, TlsModel};
10
11 use rustc_feature::UnstableFeatures;
12 use rustc_span::edition::Edition;
13 use rustc_span::SourceFileHashAlgorithm;
14
15 use std::collections::BTreeMap;
16
17 use std::collections::hash_map::DefaultHasher;
18 use std::hash::Hasher;
19 use std::num::NonZeroUsize;
20 use std::path::PathBuf;
21 use std::str;
22
23 macro_rules! insert {
24     ($opt_name:ident, $opt_expr:expr, $sub_hashes:expr) => {
25         if $sub_hashes
26             .insert(stringify!($opt_name), $opt_expr as &dyn dep_tracking::DepTrackingHash)
27             .is_some()
28         {
29             panic!("duplicate key in CLI DepTrackingHash: {}", stringify!($opt_name))
30         }
31     };
32 }
33
34 macro_rules! hash_opt {
35     ($opt_name:ident, $opt_expr:expr, $sub_hashes:expr, $_for_crate_hash: ident, [UNTRACKED]) => {{}};
36     ($opt_name:ident, $opt_expr:expr, $sub_hashes:expr, $_for_crate_hash: ident, [TRACKED]) => {{ insert!($opt_name, $opt_expr, $sub_hashes) }};
37     ($opt_name:ident, $opt_expr:expr, $sub_hashes:expr, $for_crate_hash: ident, [TRACKED_NO_CRATE_HASH]) => {{
38         if !$for_crate_hash {
39             insert!($opt_name, $opt_expr, $sub_hashes)
40         }
41     }};
42     ($opt_name:ident, $opt_expr:expr, $sub_hashes:expr, $_for_crate_hash: ident, [SUBSTRUCT]) => {{}};
43 }
44
45 macro_rules! hash_substruct {
46     ($opt_name:ident, $opt_expr:expr, $error_format:expr, $for_crate_hash:expr, $hasher:expr, [UNTRACKED]) => {{}};
47     ($opt_name:ident, $opt_expr:expr, $error_format:expr, $for_crate_hash:expr, $hasher:expr, [TRACKED]) => {{}};
48     ($opt_name:ident, $opt_expr:expr, $error_format:expr, $for_crate_hash:expr, $hasher:expr, [TRACKED_NO_CRATE_HASH]) => {{}};
49     ($opt_name:ident, $opt_expr:expr, $error_format:expr, $for_crate_hash:expr, $hasher:expr, [SUBSTRUCT]) => {
50         use crate::config::dep_tracking::DepTrackingHash;
51         $opt_expr.dep_tracking_hash($for_crate_hash, $error_format).hash(
52             $hasher,
53             $error_format,
54             $for_crate_hash,
55         );
56     };
57 }
58
59 macro_rules! top_level_options {
60     ( $( #[$top_level_attr:meta] )* pub struct Options { $(
61         $( #[$attr:meta] )*
62         $opt:ident : $t:ty [$dep_tracking_marker:ident],
63     )* } ) => (
64         #[derive(Clone)]
65         $( #[$top_level_attr] )*
66         pub struct Options {
67             $(
68                 $( #[$attr] )*
69                 pub $opt: $t
70             ),*
71         }
72
73         impl Options {
74             pub fn dep_tracking_hash(&self, for_crate_hash: bool) -> u64 {
75                 let mut sub_hashes = BTreeMap::new();
76                 $({
77                     hash_opt!($opt,
78                                 &self.$opt,
79                                 &mut sub_hashes,
80                                 for_crate_hash,
81                                 [$dep_tracking_marker]);
82                 })*
83                 let mut hasher = DefaultHasher::new();
84                 dep_tracking::stable_hash(sub_hashes,
85                                           &mut hasher,
86                                           self.error_format,
87                                           for_crate_hash);
88                 $({
89                     hash_substruct!($opt,
90                         &self.$opt,
91                         self.error_format,
92                         for_crate_hash,
93                         &mut hasher,
94                         [$dep_tracking_marker]);
95                 })*
96                 hasher.finish()
97             }
98         }
99     );
100 }
101
102 top_level_options!(
103     /// The top-level command-line options struct.
104     ///
105     /// For each option, one has to specify how it behaves with regard to the
106     /// dependency tracking system of incremental compilation. This is done via the
107     /// square-bracketed directive after the field type. The options are:
108     ///
109     /// - `[TRACKED]`
110     /// A change in the given field will cause the compiler to completely clear the
111     /// incremental compilation cache before proceeding.
112     ///
113     /// - `[TRACKED_NO_CRATE_HASH]`
114     /// Same as `[TRACKED]`, but will not affect the crate hash. This is useful for options that only
115     /// affect the incremental cache.
116     ///
117     /// - `[UNTRACKED]`
118     /// Incremental compilation is not influenced by this option.
119     ///
120     /// - `[SUBSTRUCT]`
121     /// Second-level sub-structs containing more options.
122     ///
123     /// If you add a new option to this struct or one of the sub-structs like
124     /// `CodegenOptions`, think about how it influences incremental compilation. If in
125     /// doubt, specify `[TRACKED]`, which is always "correct" but might lead to
126     /// unnecessary re-compilation.
127     pub struct Options {
128         /// The crate config requested for the session, which may be combined
129         /// with additional crate configurations during the compile process.
130         crate_types: Vec<CrateType> [TRACKED],
131         optimize: OptLevel [TRACKED],
132         /// Include the `debug_assertions` flag in dependency tracking, since it
133         /// can influence whether overflow checks are done or not.
134         debug_assertions: bool [TRACKED],
135         debuginfo: DebugInfo [TRACKED],
136         lint_opts: Vec<(String, lint::Level)> [TRACKED_NO_CRATE_HASH],
137         lint_cap: Option<lint::Level> [TRACKED_NO_CRATE_HASH],
138         describe_lints: bool [UNTRACKED],
139         output_types: OutputTypes [TRACKED],
140         search_paths: Vec<SearchPath> [UNTRACKED],
141         libs: Vec<NativeLib> [TRACKED],
142         maybe_sysroot: Option<PathBuf> [UNTRACKED],
143
144         target_triple: TargetTriple [TRACKED],
145
146         test: bool [TRACKED],
147         error_format: ErrorOutputType [UNTRACKED],
148
149         /// If `Some`, enable incremental compilation, using the given
150         /// directory to store intermediate results.
151         incremental: Option<PathBuf> [UNTRACKED],
152
153         debugging_opts: DebuggingOptions [SUBSTRUCT],
154         prints: Vec<PrintRequest> [UNTRACKED],
155         /// Determines which borrow checker(s) to run. This is the parsed, sanitized
156         /// version of `debugging_opts.borrowck`, which is just a plain string.
157         borrowck_mode: BorrowckMode [UNTRACKED],
158         cg: CodegenOptions [SUBSTRUCT],
159         externs: Externs [UNTRACKED],
160         extern_dep_specs: ExternDepSpecs [UNTRACKED],
161         crate_name: Option<String> [TRACKED],
162         /// An optional name to use as the crate for std during std injection,
163         /// written `extern crate name as std`. Defaults to `std`. Used by
164         /// out-of-tree drivers.
165         alt_std_name: Option<String> [TRACKED],
166         /// Indicates how the compiler should treat unstable features.
167         unstable_features: UnstableFeatures [TRACKED],
168
169         /// Indicates whether this run of the compiler is actually rustdoc. This
170         /// is currently just a hack and will be removed eventually, so please
171         /// try to not rely on this too much.
172         actually_rustdoc: bool [TRACKED],
173
174         /// Control path trimming.
175         trimmed_def_paths: TrimmedDefPaths [TRACKED],
176
177         /// Specifications of codegen units / ThinLTO which are forced as a
178         /// result of parsing command line options. These are not necessarily
179         /// what rustc was invoked with, but massaged a bit to agree with
180         /// commands like `--emit llvm-ir` which they're often incompatible with
181         /// if we otherwise use the defaults of rustc.
182         cli_forced_codegen_units: Option<usize> [UNTRACKED],
183         cli_forced_thinlto_off: bool [UNTRACKED],
184
185         /// Remap source path prefixes in all output (messages, object files, debug, etc.).
186         remap_path_prefix: Vec<(PathBuf, PathBuf)> [TRACKED_NO_CRATE_HASH],
187         /// Base directory containing the `src/` for the Rust standard library, and
188         /// potentially `rustc` as well, if we can can find it. Right now it's always
189         /// `$sysroot/lib/rustlib/src/rust` (i.e. the `rustup` `rust-src` component).
190         ///
191         /// This directory is what the virtual `/rustc/$hash` is translated back to,
192         /// if Rust was built with path remapping to `/rustc/$hash` enabled
193         /// (the `rust.remap-debuginfo` option in `config.toml`).
194         real_rust_source_base_dir: Option<PathBuf> [TRACKED_NO_CRATE_HASH],
195
196         edition: Edition [TRACKED],
197
198         /// `true` if we're emitting JSON blobs about each artifact produced
199         /// by the compiler.
200         json_artifact_notifications: bool [TRACKED],
201
202         /// `true` if we're emitting a JSON blob containing the unused externs
203         json_unused_externs: bool [UNTRACKED],
204
205         pretty: Option<PpMode> [UNTRACKED],
206     }
207 );
208
209 /// Defines all `CodegenOptions`/`DebuggingOptions` fields and parsers all at once. The goal of this
210 /// macro is to define an interface that can be programmatically used by the option parser
211 /// to initialize the struct without hardcoding field names all over the place.
212 ///
213 /// The goal is to invoke this macro once with the correct fields, and then this macro generates all
214 /// necessary code. The main gotcha of this macro is the `cgsetters` module which is a bunch of
215 /// generated code to parse an option into its respective field in the struct. There are a few
216 /// hand-written parsers for parsing specific types of values in this module.
217 macro_rules! options {
218     ($struct_name:ident, $stat:ident, $prefix:expr, $outputname:expr,
219      $($( #[$attr:meta] )* $opt:ident : $t:ty = (
220         $init:expr,
221         $parse:ident,
222         [$dep_tracking_marker:ident],
223         $desc:expr)
224      ),* ,) =>
225 (
226     #[derive(Clone)]
227     pub struct $struct_name { $(pub $opt: $t),* }
228
229     impl Default for $struct_name {
230         fn default() -> $struct_name {
231             $struct_name { $( $( #[$attr] )* $opt: $init),* }
232         }
233     }
234
235     impl $struct_name {
236         pub fn build(
237             matches: &getopts::Matches,
238             error_format: ErrorOutputType,
239         ) -> $struct_name {
240             build_options(matches, $stat, $prefix, $outputname, error_format)
241         }
242
243         fn dep_tracking_hash(&self, for_crate_hash: bool, error_format: ErrorOutputType) -> u64 {
244             let mut sub_hashes = BTreeMap::new();
245             $({
246                 hash_opt!($opt,
247                             &self.$opt,
248                             &mut sub_hashes,
249                             for_crate_hash,
250                             [$dep_tracking_marker]);
251             })*
252             let mut hasher = DefaultHasher::new();
253             dep_tracking::stable_hash(sub_hashes,
254                                         &mut hasher,
255                                         error_format,
256                                         for_crate_hash
257                                         );
258             hasher.finish()
259         }
260     }
261
262     pub const $stat: OptionDescrs<$struct_name> =
263         &[ $( (stringify!($opt), $opt, desc::$parse, $desc) ),* ];
264
265     $(
266         fn $opt(cg: &mut $struct_name, v: Option<&str>) -> bool {
267             parse::$parse(&mut redirect_field!(cg.$opt), v)
268         }
269     )*
270
271 ) }
272
273 // Sometimes different options need to build a common structure.
274 // That structure can be kept in one of the options' fields, the others become dummy.
275 macro_rules! redirect_field {
276     ($cg:ident.link_arg) => {
277         $cg.link_args
278     };
279     ($cg:ident.pre_link_arg) => {
280         $cg.pre_link_args
281     };
282     ($cg:ident.$field:ident) => {
283         $cg.$field
284     };
285 }
286
287 type OptionSetter<O> = fn(&mut O, v: Option<&str>) -> bool;
288 type OptionDescrs<O> = &'static [(&'static str, OptionSetter<O>, &'static str, &'static str)];
289
290 fn build_options<O: Default>(
291     matches: &getopts::Matches,
292     descrs: OptionDescrs<O>,
293     prefix: &str,
294     outputname: &str,
295     error_format: ErrorOutputType,
296 ) -> O {
297     let mut op = O::default();
298     for option in matches.opt_strs(prefix) {
299         let (key, value) = match option.split_once('=') {
300             None => (option, None),
301             Some((k, v)) => (k.to_string(), Some(v)),
302         };
303
304         let option_to_lookup = key.replace("-", "_");
305         match descrs.iter().find(|(name, ..)| *name == option_to_lookup) {
306             Some((_, setter, type_desc, _)) => {
307                 if !setter(&mut op, value) {
308                     match value {
309                         None => early_error(
310                             error_format,
311                             &format!(
312                                 "{0} option `{1}` requires {2} ({3} {1}=<value>)",
313                                 outputname, key, type_desc, prefix
314                             ),
315                         ),
316                         Some(value) => early_error(
317                             error_format,
318                             &format!(
319                                 "incorrect value `{}` for {} option `{}` - {} was expected",
320                                 value, outputname, key, type_desc
321                             ),
322                         ),
323                     }
324                 }
325             }
326             None => early_error(error_format, &format!("unknown {} option: `{}`", outputname, key)),
327         }
328     }
329     return op;
330 }
331
332 #[allow(non_upper_case_globals)]
333 mod desc {
334     pub const parse_no_flag: &str = "no value";
335     pub const parse_bool: &str = "one of: `y`, `yes`, `on`, `n`, `no`, or `off`";
336     pub const parse_opt_bool: &str = parse_bool;
337     pub const parse_string: &str = "a string";
338     pub const parse_opt_string: &str = parse_string;
339     pub const parse_string_push: &str = parse_string;
340     pub const parse_opt_pathbuf: &str = "a path";
341     pub const parse_list: &str = "a space-separated list of strings";
342     pub const parse_opt_comma_list: &str = "a comma-separated list of strings";
343     pub const parse_number: &str = "a number";
344     pub const parse_opt_number: &str = parse_number;
345     pub const parse_threads: &str = parse_number;
346     pub const parse_passes: &str = "a space-separated list of passes, or `all`";
347     pub const parse_panic_strategy: &str = "either `unwind` or `abort`";
348     pub const parse_relro_level: &str = "one of: `full`, `partial`, or `off`";
349     pub const parse_sanitizers: &str =
350         "comma separated list of sanitizers: `address`, `hwaddress`, `leak`, `memory` or `thread`";
351     pub const parse_sanitizer_memory_track_origins: &str = "0, 1, or 2";
352     pub const parse_cfguard: &str =
353         "either a boolean (`yes`, `no`, `on`, `off`, etc), `checks`, or `nochecks`";
354     pub const parse_strip: &str = "either `none`, `debuginfo`, or `symbols`";
355     pub const parse_linker_flavor: &str = ::rustc_target::spec::LinkerFlavor::one_of();
356     pub const parse_optimization_fuel: &str = "crate=integer";
357     pub const parse_mir_spanview: &str = "`statement` (default), `terminator`, or `block`";
358     pub const parse_instrument_coverage: &str =
359         "`all` (default), `except-unused-generics`, `except-unused-functions`, or `off`";
360     pub const parse_unpretty: &str = "`string` or `string=string`";
361     pub const parse_treat_err_as_bug: &str = "either no value or a number bigger than 0";
362     pub const parse_lto: &str =
363         "either a boolean (`yes`, `no`, `on`, `off`, etc), `thin`, `fat`, or omitted";
364     pub const parse_linker_plugin_lto: &str =
365         "either a boolean (`yes`, `no`, `on`, `off`, etc), or the path to the linker plugin";
366     pub const parse_switch_with_opt_path: &str =
367         "an optional path to the profiling data output directory";
368     pub const parse_merge_functions: &str = "one of: `disabled`, `trampolines`, or `aliases`";
369     pub const parse_symbol_mangling_version: &str = "either `legacy` or `v0` (RFC 2603)";
370     pub const parse_src_file_hash: &str = "either `md5` or `sha1`";
371     pub const parse_relocation_model: &str =
372         "one of supported relocation models (`rustc --print relocation-models`)";
373     pub const parse_code_model: &str = "one of supported code models (`rustc --print code-models`)";
374     pub const parse_tls_model: &str = "one of supported TLS models (`rustc --print tls-models`)";
375     pub const parse_target_feature: &str = parse_string;
376     pub const parse_wasi_exec_model: &str = "either `command` or `reactor`";
377     pub const parse_split_debuginfo: &str =
378         "one of supported split-debuginfo modes (`off`, `packed`, or `unpacked`)";
379     pub const parse_gcc_ld: &str = "one of: no value, `lld`";
380 }
381
382 mod parse {
383     crate use super::*;
384     use std::str::FromStr;
385
386     /// This is for boolean options that don't take a value and start with
387     /// `no-`. This style of option is deprecated.
388     crate fn parse_no_flag(slot: &mut bool, v: Option<&str>) -> bool {
389         match v {
390             None => {
391                 *slot = true;
392                 true
393             }
394             Some(_) => false,
395         }
396     }
397
398     /// Use this for any boolean option that has a static default.
399     crate fn parse_bool(slot: &mut bool, v: Option<&str>) -> bool {
400         match v {
401             Some("y") | Some("yes") | Some("on") | None => {
402                 *slot = true;
403                 true
404             }
405             Some("n") | Some("no") | Some("off") => {
406                 *slot = false;
407                 true
408             }
409             _ => false,
410         }
411     }
412
413     /// Use this for any boolean option that lacks a static default. (The
414     /// actions taken when such an option is not specified will depend on
415     /// other factors, such as other options, or target options.)
416     crate fn parse_opt_bool(slot: &mut Option<bool>, v: Option<&str>) -> bool {
417         match v {
418             Some("y") | Some("yes") | Some("on") | None => {
419                 *slot = Some(true);
420                 true
421             }
422             Some("n") | Some("no") | Some("off") => {
423                 *slot = Some(false);
424                 true
425             }
426             _ => false,
427         }
428     }
429
430     /// Use this for any string option that has a static default.
431     crate fn parse_string(slot: &mut String, v: Option<&str>) -> bool {
432         match v {
433             Some(s) => {
434                 *slot = s.to_string();
435                 true
436             }
437             None => false,
438         }
439     }
440
441     /// Use this for any string option that lacks a static default.
442     crate fn parse_opt_string(slot: &mut Option<String>, v: Option<&str>) -> bool {
443         match v {
444             Some(s) => {
445                 *slot = Some(s.to_string());
446                 true
447             }
448             None => false,
449         }
450     }
451
452     crate fn parse_opt_pathbuf(slot: &mut Option<PathBuf>, v: Option<&str>) -> bool {
453         match v {
454             Some(s) => {
455                 *slot = Some(PathBuf::from(s));
456                 true
457             }
458             None => false,
459         }
460     }
461
462     crate fn parse_string_push(slot: &mut Vec<String>, v: Option<&str>) -> bool {
463         match v {
464             Some(s) => {
465                 slot.push(s.to_string());
466                 true
467             }
468             None => false,
469         }
470     }
471
472     crate fn parse_list(slot: &mut Vec<String>, v: Option<&str>) -> bool {
473         match v {
474             Some(s) => {
475                 slot.extend(s.split_whitespace().map(|s| s.to_string()));
476                 true
477             }
478             None => false,
479         }
480     }
481
482     crate fn parse_opt_comma_list(slot: &mut Option<Vec<String>>, v: Option<&str>) -> bool {
483         match v {
484             Some(s) => {
485                 let mut v: Vec<_> = s.split(',').map(|s| s.to_string()).collect();
486                 v.sort_unstable();
487                 *slot = Some(v);
488                 true
489             }
490             None => false,
491         }
492     }
493
494     crate fn parse_threads(slot: &mut usize, v: Option<&str>) -> bool {
495         match v.and_then(|s| s.parse().ok()) {
496             Some(0) => {
497                 *slot = ::num_cpus::get();
498                 true
499             }
500             Some(i) => {
501                 *slot = i;
502                 true
503             }
504             None => false,
505         }
506     }
507
508     /// Use this for any numeric option that has a static default.
509     crate fn parse_number<T: Copy + FromStr>(slot: &mut T, v: Option<&str>) -> bool {
510         match v.and_then(|s| s.parse().ok()) {
511             Some(i) => {
512                 *slot = i;
513                 true
514             }
515             None => false,
516         }
517     }
518
519     /// Use this for any numeric option that lacks a static default.
520     crate fn parse_opt_number<T: Copy + FromStr>(slot: &mut Option<T>, v: Option<&str>) -> bool {
521         match v {
522             Some(s) => {
523                 *slot = s.parse().ok();
524                 slot.is_some()
525             }
526             None => false,
527         }
528     }
529
530     crate fn parse_passes(slot: &mut Passes, v: Option<&str>) -> bool {
531         match v {
532             Some("all") => {
533                 *slot = Passes::All;
534                 true
535             }
536             v => {
537                 let mut passes = vec![];
538                 if parse_list(&mut passes, v) {
539                     *slot = Passes::Some(passes);
540                     true
541                 } else {
542                     false
543                 }
544             }
545         }
546     }
547
548     crate fn parse_panic_strategy(slot: &mut Option<PanicStrategy>, v: Option<&str>) -> bool {
549         match v {
550             Some("unwind") => *slot = Some(PanicStrategy::Unwind),
551             Some("abort") => *slot = Some(PanicStrategy::Abort),
552             _ => return false,
553         }
554         true
555     }
556
557     crate fn parse_relro_level(slot: &mut Option<RelroLevel>, v: Option<&str>) -> bool {
558         match v {
559             Some(s) => match s.parse::<RelroLevel>() {
560                 Ok(level) => *slot = Some(level),
561                 _ => return false,
562             },
563             _ => return false,
564         }
565         true
566     }
567
568     crate fn parse_sanitizers(slot: &mut SanitizerSet, v: Option<&str>) -> bool {
569         if let Some(v) = v {
570             for s in v.split(',') {
571                 *slot |= match s {
572                     "address" => SanitizerSet::ADDRESS,
573                     "leak" => SanitizerSet::LEAK,
574                     "memory" => SanitizerSet::MEMORY,
575                     "thread" => SanitizerSet::THREAD,
576                     "hwaddress" => SanitizerSet::HWADDRESS,
577                     _ => return false,
578                 }
579             }
580             true
581         } else {
582             false
583         }
584     }
585
586     crate fn parse_sanitizer_memory_track_origins(slot: &mut usize, v: Option<&str>) -> bool {
587         match v {
588             Some("2") | None => {
589                 *slot = 2;
590                 true
591             }
592             Some("1") => {
593                 *slot = 1;
594                 true
595             }
596             Some("0") => {
597                 *slot = 0;
598                 true
599             }
600             Some(_) => false,
601         }
602     }
603
604     crate fn parse_strip(slot: &mut Strip, v: Option<&str>) -> bool {
605         match v {
606             Some("none") => *slot = Strip::None,
607             Some("debuginfo") => *slot = Strip::Debuginfo,
608             Some("symbols") => *slot = Strip::Symbols,
609             _ => return false,
610         }
611         true
612     }
613
614     crate fn parse_cfguard(slot: &mut CFGuard, v: Option<&str>) -> bool {
615         if v.is_some() {
616             let mut bool_arg = None;
617             if parse_opt_bool(&mut bool_arg, v) {
618                 *slot = if bool_arg.unwrap() { CFGuard::Checks } else { CFGuard::Disabled };
619                 return true;
620             }
621         }
622
623         *slot = match v {
624             None => CFGuard::Checks,
625             Some("checks") => CFGuard::Checks,
626             Some("nochecks") => CFGuard::NoChecks,
627             Some(_) => return false,
628         };
629         true
630     }
631
632     crate fn parse_linker_flavor(slot: &mut Option<LinkerFlavor>, v: Option<&str>) -> bool {
633         match v.and_then(LinkerFlavor::from_str) {
634             Some(lf) => *slot = Some(lf),
635             _ => return false,
636         }
637         true
638     }
639
640     crate fn parse_optimization_fuel(slot: &mut Option<(String, u64)>, v: Option<&str>) -> bool {
641         match v {
642             None => false,
643             Some(s) => {
644                 let parts = s.split('=').collect::<Vec<_>>();
645                 if parts.len() != 2 {
646                     return false;
647                 }
648                 let crate_name = parts[0].to_string();
649                 let fuel = parts[1].parse::<u64>();
650                 if fuel.is_err() {
651                     return false;
652                 }
653                 *slot = Some((crate_name, fuel.unwrap()));
654                 true
655             }
656         }
657     }
658
659     crate fn parse_unpretty(slot: &mut Option<String>, v: Option<&str>) -> bool {
660         match v {
661             None => false,
662             Some(s) if s.split('=').count() <= 2 => {
663                 *slot = Some(s.to_string());
664                 true
665             }
666             _ => false,
667         }
668     }
669
670     crate fn parse_mir_spanview(slot: &mut Option<MirSpanview>, v: Option<&str>) -> bool {
671         if v.is_some() {
672             let mut bool_arg = None;
673             if parse_opt_bool(&mut bool_arg, v) {
674                 *slot = if bool_arg.unwrap() { Some(MirSpanview::Statement) } else { None };
675                 return true;
676             }
677         }
678
679         let v = match v {
680             None => {
681                 *slot = Some(MirSpanview::Statement);
682                 return true;
683             }
684             Some(v) => v,
685         };
686
687         *slot = Some(match v.trim_end_matches('s') {
688             "statement" | "stmt" => MirSpanview::Statement,
689             "terminator" | "term" => MirSpanview::Terminator,
690             "block" | "basicblock" => MirSpanview::Block,
691             _ => return false,
692         });
693         true
694     }
695
696     crate fn parse_instrument_coverage(
697         slot: &mut Option<InstrumentCoverage>,
698         v: Option<&str>,
699     ) -> bool {
700         if v.is_some() {
701             let mut bool_arg = None;
702             if parse_opt_bool(&mut bool_arg, v) {
703                 *slot = if bool_arg.unwrap() { Some(InstrumentCoverage::All) } else { None };
704                 return true;
705             }
706         }
707
708         let v = match v {
709             None => {
710                 *slot = Some(InstrumentCoverage::All);
711                 return true;
712             }
713             Some(v) => v,
714         };
715
716         *slot = Some(match v {
717             "all" => InstrumentCoverage::All,
718             "except-unused-generics" | "except_unused_generics" => {
719                 InstrumentCoverage::ExceptUnusedGenerics
720             }
721             "except-unused-functions" | "except_unused_functions" => {
722                 InstrumentCoverage::ExceptUnusedFunctions
723             }
724             "off" | "no" | "n" | "false" | "0" => InstrumentCoverage::Off,
725             _ => return false,
726         });
727         true
728     }
729
730     crate fn parse_treat_err_as_bug(slot: &mut Option<NonZeroUsize>, v: Option<&str>) -> bool {
731         match v {
732             Some(s) => {
733                 *slot = s.parse().ok();
734                 slot.is_some()
735             }
736             None => {
737                 *slot = NonZeroUsize::new(1);
738                 true
739             }
740         }
741     }
742
743     crate fn parse_lto(slot: &mut LtoCli, v: Option<&str>) -> bool {
744         if v.is_some() {
745             let mut bool_arg = None;
746             if parse_opt_bool(&mut bool_arg, v) {
747                 *slot = if bool_arg.unwrap() { LtoCli::Yes } else { LtoCli::No };
748                 return true;
749             }
750         }
751
752         *slot = match v {
753             None => LtoCli::NoParam,
754             Some("thin") => LtoCli::Thin,
755             Some("fat") => LtoCli::Fat,
756             Some(_) => return false,
757         };
758         true
759     }
760
761     crate fn parse_linker_plugin_lto(slot: &mut LinkerPluginLto, v: Option<&str>) -> bool {
762         if v.is_some() {
763             let mut bool_arg = None;
764             if parse_opt_bool(&mut bool_arg, v) {
765                 *slot = if bool_arg.unwrap() {
766                     LinkerPluginLto::LinkerPluginAuto
767                 } else {
768                     LinkerPluginLto::Disabled
769                 };
770                 return true;
771             }
772         }
773
774         *slot = match v {
775             None => LinkerPluginLto::LinkerPluginAuto,
776             Some(path) => LinkerPluginLto::LinkerPlugin(PathBuf::from(path)),
777         };
778         true
779     }
780
781     crate fn parse_switch_with_opt_path(slot: &mut SwitchWithOptPath, v: Option<&str>) -> bool {
782         *slot = match v {
783             None => SwitchWithOptPath::Enabled(None),
784             Some(path) => SwitchWithOptPath::Enabled(Some(PathBuf::from(path))),
785         };
786         true
787     }
788
789     crate fn parse_merge_functions(slot: &mut Option<MergeFunctions>, v: Option<&str>) -> bool {
790         match v.and_then(|s| MergeFunctions::from_str(s).ok()) {
791             Some(mergefunc) => *slot = Some(mergefunc),
792             _ => return false,
793         }
794         true
795     }
796
797     crate fn parse_relocation_model(slot: &mut Option<RelocModel>, v: Option<&str>) -> bool {
798         match v.and_then(|s| RelocModel::from_str(s).ok()) {
799             Some(relocation_model) => *slot = Some(relocation_model),
800             None if v == Some("default") => *slot = None,
801             _ => return false,
802         }
803         true
804     }
805
806     crate fn parse_code_model(slot: &mut Option<CodeModel>, v: Option<&str>) -> bool {
807         match v.and_then(|s| CodeModel::from_str(s).ok()) {
808             Some(code_model) => *slot = Some(code_model),
809             _ => return false,
810         }
811         true
812     }
813
814     crate fn parse_tls_model(slot: &mut Option<TlsModel>, v: Option<&str>) -> bool {
815         match v.and_then(|s| TlsModel::from_str(s).ok()) {
816             Some(tls_model) => *slot = Some(tls_model),
817             _ => return false,
818         }
819         true
820     }
821
822     crate fn parse_symbol_mangling_version(
823         slot: &mut Option<SymbolManglingVersion>,
824         v: Option<&str>,
825     ) -> bool {
826         *slot = match v {
827             Some("legacy") => Some(SymbolManglingVersion::Legacy),
828             Some("v0") => Some(SymbolManglingVersion::V0),
829             _ => return false,
830         };
831         true
832     }
833
834     crate fn parse_src_file_hash(
835         slot: &mut Option<SourceFileHashAlgorithm>,
836         v: Option<&str>,
837     ) -> bool {
838         match v.and_then(|s| SourceFileHashAlgorithm::from_str(s).ok()) {
839             Some(hash_kind) => *slot = Some(hash_kind),
840             _ => return false,
841         }
842         true
843     }
844
845     crate fn parse_target_feature(slot: &mut String, v: Option<&str>) -> bool {
846         match v {
847             Some(s) => {
848                 if !slot.is_empty() {
849                     slot.push_str(",");
850                 }
851                 slot.push_str(s);
852                 true
853             }
854             None => false,
855         }
856     }
857
858     crate fn parse_wasi_exec_model(slot: &mut Option<WasiExecModel>, v: Option<&str>) -> bool {
859         match v {
860             Some("command") => *slot = Some(WasiExecModel::Command),
861             Some("reactor") => *slot = Some(WasiExecModel::Reactor),
862             _ => return false,
863         }
864         true
865     }
866
867     crate fn parse_split_debuginfo(slot: &mut Option<SplitDebuginfo>, v: Option<&str>) -> bool {
868         match v.and_then(|s| SplitDebuginfo::from_str(s).ok()) {
869             Some(e) => *slot = Some(e),
870             _ => return false,
871         }
872         true
873     }
874
875     crate fn parse_gcc_ld(slot: &mut Option<LdImpl>, v: Option<&str>) -> bool {
876         match v {
877             None => *slot = None,
878             Some("lld") => *slot = Some(LdImpl::Lld),
879             _ => return false,
880         }
881         true
882     }
883 }
884
885 options! {
886     CodegenOptions, CG_OPTIONS, "C", "codegen",
887
888     // This list is in alphabetical order.
889     //
890     // If you add a new option, please update:
891     // - compiler/rustc_interface/src/tests.rs
892     // - src/doc/rustc/src/codegen-options/index.md
893
894     ar: String = (String::new(), parse_string, [UNTRACKED],
895         "this option is deprecated and does nothing"),
896     code_model: Option<CodeModel> = (None, parse_code_model, [TRACKED],
897         "choose the code model to use (`rustc --print code-models` for details)"),
898     codegen_units: Option<usize> = (None, parse_opt_number, [UNTRACKED],
899         "divide crate into N units to optimize in parallel"),
900     control_flow_guard: CFGuard = (CFGuard::Disabled, parse_cfguard, [TRACKED],
901         "use Windows Control Flow Guard (default: no)"),
902     debug_assertions: Option<bool> = (None, parse_opt_bool, [TRACKED],
903         "explicitly enable the `cfg(debug_assertions)` directive"),
904     debuginfo: usize = (0, parse_number, [TRACKED],
905         "debug info emission level (0 = no debug info, 1 = line tables only, \
906         2 = full debug info with variable and type information; default: 0)"),
907     default_linker_libraries: bool = (false, parse_bool, [UNTRACKED],
908         "allow the linker to link its default libraries (default: no)"),
909     embed_bitcode: bool = (true, parse_bool, [TRACKED],
910         "emit bitcode in rlibs (default: yes)"),
911     extra_filename: String = (String::new(), parse_string, [UNTRACKED],
912         "extra data to put in each output filename"),
913     force_frame_pointers: Option<bool> = (None, parse_opt_bool, [TRACKED],
914         "force use of the frame pointers"),
915     force_unwind_tables: Option<bool> = (None, parse_opt_bool, [TRACKED],
916         "force use of unwind tables"),
917     incremental: Option<String> = (None, parse_opt_string, [UNTRACKED],
918         "enable incremental compilation"),
919     inline_threshold: Option<u32> = (None, parse_opt_number, [TRACKED],
920         "set the threshold for inlining a function"),
921     link_arg: (/* redirected to link_args */) = ((), parse_string_push, [UNTRACKED],
922         "a single extra argument to append to the linker invocation (can be used several times)"),
923     link_args: Vec<String> = (Vec::new(), parse_list, [UNTRACKED],
924         "extra arguments to append to the linker invocation (space separated)"),
925     link_dead_code: Option<bool> = (None, parse_opt_bool, [TRACKED],
926         "keep dead code at link time (useful for code coverage) (default: no)"),
927     link_self_contained: Option<bool> = (None, parse_opt_bool, [UNTRACKED],
928         "control whether to link Rust provided C objects/libraries or rely
929         on C toolchain installed in the system"),
930     linker: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
931         "system linker to link outputs with"),
932     linker_flavor: Option<LinkerFlavor> = (None, parse_linker_flavor, [UNTRACKED],
933         "linker flavor"),
934     linker_plugin_lto: LinkerPluginLto = (LinkerPluginLto::Disabled,
935         parse_linker_plugin_lto, [TRACKED],
936         "generate build artifacts that are compatible with linker-based LTO"),
937     llvm_args: Vec<String> = (Vec::new(), parse_list, [TRACKED],
938         "a list of arguments to pass to LLVM (space separated)"),
939     lto: LtoCli = (LtoCli::Unspecified, parse_lto, [TRACKED],
940         "perform LLVM link-time optimizations"),
941     metadata: Vec<String> = (Vec::new(), parse_list, [TRACKED],
942         "metadata to mangle symbol names with"),
943     no_prepopulate_passes: bool = (false, parse_no_flag, [TRACKED],
944         "give an empty list of passes to the pass manager"),
945     no_redzone: Option<bool> = (None, parse_opt_bool, [TRACKED],
946         "disable the use of the redzone"),
947     no_stack_check: bool = (false, parse_no_flag, [UNTRACKED],
948         "this option is deprecated and does nothing"),
949     no_vectorize_loops: bool = (false, parse_no_flag, [TRACKED],
950         "disable loop vectorization optimization passes"),
951     no_vectorize_slp: bool = (false, parse_no_flag, [TRACKED],
952         "disable LLVM's SLP vectorization pass"),
953     opt_level: String = ("0".to_string(), parse_string, [TRACKED],
954         "optimization level (0-3, s, or z; default: 0)"),
955     overflow_checks: Option<bool> = (None, parse_opt_bool, [TRACKED],
956         "use overflow checks for integer arithmetic"),
957     panic: Option<PanicStrategy> = (None, parse_panic_strategy, [TRACKED],
958         "panic strategy to compile crate with"),
959     passes: Vec<String> = (Vec::new(), parse_list, [TRACKED],
960         "a list of extra LLVM passes to run (space separated)"),
961     prefer_dynamic: bool = (false, parse_bool, [TRACKED],
962         "prefer dynamic linking to static linking (default: no)"),
963     profile_generate: SwitchWithOptPath = (SwitchWithOptPath::Disabled,
964         parse_switch_with_opt_path, [TRACKED],
965         "compile the program with profiling instrumentation"),
966     profile_use: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
967         "use the given `.profdata` file for profile-guided optimization"),
968     relocation_model: Option<RelocModel> = (None, parse_relocation_model, [TRACKED],
969         "control generation of position-independent code (PIC) \
970         (`rustc --print relocation-models` for details)"),
971     remark: Passes = (Passes::Some(Vec::new()), parse_passes, [UNTRACKED],
972         "print remarks for these optimization passes (space separated, or \"all\")"),
973     rpath: bool = (false, parse_bool, [UNTRACKED],
974         "set rpath values in libs/exes (default: no)"),
975     save_temps: bool = (false, parse_bool, [UNTRACKED],
976         "save all temporary output files during compilation (default: no)"),
977     soft_float: bool = (false, parse_bool, [TRACKED],
978         "use soft float ABI (*eabihf targets only) (default: no)"),
979     split_debuginfo: Option<SplitDebuginfo> = (None, parse_split_debuginfo, [TRACKED],
980         "how to handle split-debuginfo, a platform-specific option"),
981     target_cpu: Option<String> = (None, parse_opt_string, [TRACKED],
982         "select target processor (`rustc --print target-cpus` for details)"),
983     target_feature: String = (String::new(), parse_target_feature, [TRACKED],
984         "target specific attributes. (`rustc --print target-features` for details). \
985         This feature is unsafe."),
986
987     // This list is in alphabetical order.
988     //
989     // If you add a new option, please update:
990     // - compiler/rustc_interface/src/tests.rs
991     // - src/doc/rustc/src/codegen-options/index.md
992 }
993
994 options! {
995     DebuggingOptions, DB_OPTIONS, "Z", "debugging",
996
997     // This list is in alphabetical order.
998     //
999     // If you add a new option, please update:
1000     // - compiler/rustc_interface/src/tests.rs
1001
1002     allow_features: Option<Vec<String>> = (None, parse_opt_comma_list, [TRACKED],
1003         "only allow the listed language features to be enabled in code (space separated)"),
1004     always_encode_mir: bool = (false, parse_bool, [TRACKED],
1005         "encode MIR of all functions into the crate metadata (default: no)"),
1006     assume_incomplete_release: bool = (false, parse_bool, [TRACKED],
1007         "make cfg(version) treat the current version as incomplete (default: no)"),
1008     asm_comments: bool = (false, parse_bool, [TRACKED],
1009         "generate comments into the assembly (may change behavior) (default: no)"),
1010     ast_json: bool = (false, parse_bool, [UNTRACKED],
1011         "print the AST as JSON and halt (default: no)"),
1012     ast_json_noexpand: bool = (false, parse_bool, [UNTRACKED],
1013         "print the pre-expansion AST as JSON and halt (default: no)"),
1014     binary_dep_depinfo: bool = (false, parse_bool, [TRACKED],
1015         "include artifacts (sysroot, crate dependencies) used during compilation in dep-info \
1016         (default: no)"),
1017     borrowck: String = ("migrate".to_string(), parse_string, [UNTRACKED],
1018         "select which borrowck is used (`mir` or `migrate`) (default: `migrate`)"),
1019     cgu_partitioning_strategy: Option<String> = (None, parse_opt_string, [TRACKED],
1020         "the codegen unit partitioning strategy to use"),
1021     chalk: bool = (false, parse_bool, [TRACKED],
1022         "enable the experimental Chalk-based trait solving engine"),
1023     codegen_backend: Option<String> = (None, parse_opt_string, [TRACKED],
1024         "the backend to use"),
1025     combine_cgu: bool = (false, parse_bool, [TRACKED],
1026         "combine CGUs into a single one"),
1027     crate_attr: Vec<String> = (Vec::new(), parse_string_push, [TRACKED],
1028         "inject the given attribute in the crate"),
1029     debug_macros: bool = (false, parse_bool, [TRACKED],
1030         "emit line numbers debug info inside macros (default: no)"),
1031     deduplicate_diagnostics: bool = (true, parse_bool, [UNTRACKED],
1032         "deduplicate identical diagnostics (default: yes)"),
1033     dep_info_omit_d_target: bool = (false, parse_bool, [TRACKED],
1034         "in dep-info output, omit targets for tracking dependencies of the dep-info files \
1035         themselves (default: no)"),
1036     dep_tasks: bool = (false, parse_bool, [UNTRACKED],
1037         "print tasks that execute and the color their dep node gets (requires debug build) \
1038         (default: no)"),
1039     dont_buffer_diagnostics: bool = (false, parse_bool, [UNTRACKED],
1040         "emit diagnostics rather than buffering (breaks NLL error downgrading, sorting) \
1041         (default: no)"),
1042     dual_proc_macros: bool = (false, parse_bool, [TRACKED],
1043         "load proc macros for both target and host, but only link to the target (default: no)"),
1044     dump_dep_graph: bool = (false, parse_bool, [UNTRACKED],
1045         "dump the dependency graph to $RUST_DEP_GRAPH (default: /tmp/dep_graph.gv) \
1046         (default: no)"),
1047     dump_mir: Option<String> = (None, parse_opt_string, [UNTRACKED],
1048         "dump MIR state to file.
1049         `val` is used to select which passes and functions to dump. For example:
1050         `all` matches all passes and functions,
1051         `foo` matches all passes for functions whose name contains 'foo',
1052         `foo & ConstProp` only the 'ConstProp' pass for function names containing 'foo',
1053         `foo | bar` all passes for function names containing 'foo' or 'bar'."),
1054     dump_mir_dataflow: bool = (false, parse_bool, [UNTRACKED],
1055         "in addition to `.mir` files, create graphviz `.dot` files with dataflow results \
1056         (default: no)"),
1057     dump_mir_dir: String = ("mir_dump".to_string(), parse_string, [UNTRACKED],
1058         "the directory the MIR is dumped into (default: `mir_dump`)"),
1059     dump_mir_exclude_pass_number: bool = (false, parse_bool, [UNTRACKED],
1060         "exclude the pass number when dumping MIR (used in tests) (default: no)"),
1061     dump_mir_graphviz: bool = (false, parse_bool, [UNTRACKED],
1062         "in addition to `.mir` files, create graphviz `.dot` files (and with \
1063         `-Z instrument-coverage`, also create a `.dot` file for the MIR-derived \
1064         coverage graph) (default: no)"),
1065     dump_mir_spanview: Option<MirSpanview> = (None, parse_mir_spanview, [UNTRACKED],
1066         "in addition to `.mir` files, create `.html` files to view spans for \
1067         all `statement`s (including terminators), only `terminator` spans, or \
1068         computed `block` spans (one span encompassing a block's terminator and \
1069         all statements). If `-Z instrument-coverage` is also enabled, create \
1070         an additional `.html` file showing the computed coverage spans."),
1071     emit_future_incompat_report: bool = (false, parse_bool, [UNTRACKED],
1072         "emits a future-incompatibility report for lints (RFC 2834)"),
1073     emit_stack_sizes: bool = (false, parse_bool, [UNTRACKED],
1074         "emit a section containing stack size metadata (default: no)"),
1075     fewer_names: Option<bool> = (None, parse_opt_bool, [TRACKED],
1076         "reduce memory use by retaining fewer names within compilation artifacts (LLVM-IR) \
1077         (default: no)"),
1078     force_overflow_checks: Option<bool> = (None, parse_opt_bool, [TRACKED],
1079         "force overflow checks on or off"),
1080     force_unstable_if_unmarked: bool = (false, parse_bool, [TRACKED],
1081         "force all crates to be `rustc_private` unstable (default: no)"),
1082     fuel: Option<(String, u64)> = (None, parse_optimization_fuel, [TRACKED],
1083         "set the optimization fuel quota for a crate"),
1084     function_sections: Option<bool> = (None, parse_opt_bool, [TRACKED],
1085         "whether each function should go in its own section"),
1086     future_incompat_test: bool = (false, parse_bool, [UNTRACKED],
1087         "forces all lints to be future incompatible, used for internal testing (default: no)"),
1088     gcc_ld: Option<LdImpl> = (None, parse_gcc_ld, [TRACKED], "implementation of ld used by cc"),
1089     graphviz_dark_mode: bool = (false, parse_bool, [UNTRACKED],
1090         "use dark-themed colors in graphviz output (default: no)"),
1091     graphviz_font: String = ("Courier, monospace".to_string(), parse_string, [UNTRACKED],
1092         "use the given `fontname` in graphviz output; can be overridden by setting \
1093         environment variable `RUSTC_GRAPHVIZ_FONT` (default: `Courier, monospace`)"),
1094     hir_stats: bool = (false, parse_bool, [UNTRACKED],
1095         "print some statistics about AST and HIR (default: no)"),
1096     human_readable_cgu_names: bool = (false, parse_bool, [TRACKED],
1097         "generate human-readable, predictable names for codegen units (default: no)"),
1098     identify_regions: bool = (false, parse_bool, [UNTRACKED],
1099         "display unnamed regions as `'<id>`, using a non-ident unique id (default: no)"),
1100     incremental_ignore_spans: bool = (false, parse_bool, [UNTRACKED],
1101         "ignore spans during ICH computation -- used for testing (default: no)"),
1102     incremental_info: bool = (false, parse_bool, [UNTRACKED],
1103         "print high-level information about incremental reuse (or the lack thereof) \
1104         (default: no)"),
1105     incremental_verify_ich: bool = (false, parse_bool, [UNTRACKED],
1106         "verify incr. comp. hashes of green query instances (default: no)"),
1107     inline_mir: Option<bool> = (None, parse_opt_bool, [TRACKED],
1108         "enable MIR inlining (default: no)"),
1109     inline_mir_threshold: Option<usize> = (None, parse_opt_number, [TRACKED],
1110         "a default MIR inlining threshold (default: 50)"),
1111     inline_mir_hint_threshold: Option<usize> = (None, parse_opt_number, [TRACKED],
1112         "inlining threshold for functions with inline hint (default: 100)"),
1113     inline_in_all_cgus: Option<bool> = (None, parse_opt_bool, [TRACKED],
1114         "control whether `#[inline]` functions are in all CGUs"),
1115     input_stats: bool = (false, parse_bool, [UNTRACKED],
1116         "gather statistics about the input (default: no)"),
1117     instrument_coverage: Option<InstrumentCoverage> = (None, parse_instrument_coverage, [TRACKED],
1118         "instrument the generated code to support LLVM source-based code coverage \
1119         reports (note, the compiler build config must include `profiler = true`); \
1120         implies `-Z symbol-mangling-version=v0`. Optional values are:
1121         `=all` (implicit value)
1122         `=except-unused-generics`
1123         `=except-unused-functions`
1124         `=off` (default)"),
1125     instrument_mcount: bool = (false, parse_bool, [TRACKED],
1126         "insert function instrument code for mcount-based tracing (default: no)"),
1127     keep_hygiene_data: bool = (false, parse_bool, [UNTRACKED],
1128         "keep hygiene data after analysis (default: no)"),
1129     link_native_libraries: bool = (true, parse_bool, [UNTRACKED],
1130         "link native libraries in the linker invocation (default: yes)"),
1131     link_only: bool = (false, parse_bool, [TRACKED],
1132         "link the `.rlink` file generated by `-Z no-link` (default: no)"),
1133     llvm_plugins: Vec<String> = (Vec::new(), parse_list, [TRACKED],
1134         "a list LLVM plugins to enable (space separated)"),
1135     llvm_time_trace: bool = (false, parse_bool, [UNTRACKED],
1136         "generate JSON tracing data file from LLVM data (default: no)"),
1137     ls: bool = (false, parse_bool, [UNTRACKED],
1138         "list the symbols defined by a library crate (default: no)"),
1139     macro_backtrace: bool = (false, parse_bool, [UNTRACKED],
1140         "show macro backtraces (default: no)"),
1141     merge_functions: Option<MergeFunctions> = (None, parse_merge_functions, [TRACKED],
1142         "control the operation of the MergeFunctions LLVM pass, taking \
1143         the same values as the target option of the same name"),
1144     meta_stats: bool = (false, parse_bool, [UNTRACKED],
1145         "gather metadata statistics (default: no)"),
1146     mir_emit_retag: bool = (false, parse_bool, [TRACKED],
1147         "emit Retagging MIR statements, interpreted e.g., by miri; implies -Zmir-opt-level=0 \
1148         (default: no)"),
1149     mir_opt_level: Option<usize> = (None, parse_opt_number, [TRACKED],
1150         "MIR optimization level (0-4; default: 1 in non optimized builds and 2 in optimized builds)"),
1151     mutable_noalias: Option<bool> = (None, parse_opt_bool, [TRACKED],
1152         "emit noalias metadata for mutable references (default: yes for LLVM >= 12, otherwise no)"),
1153     new_llvm_pass_manager: Option<bool> = (None, parse_opt_bool, [TRACKED],
1154         "use new LLVM pass manager (default: no)"),
1155     nll_facts: bool = (false, parse_bool, [UNTRACKED],
1156         "dump facts from NLL analysis into side files (default: no)"),
1157     nll_facts_dir: String = ("nll-facts".to_string(), parse_string, [UNTRACKED],
1158         "the directory the NLL facts are dumped into (default: `nll-facts`)"),
1159     no_analysis: bool = (false, parse_no_flag, [UNTRACKED],
1160         "parse and expand the source, but run no analysis"),
1161     no_codegen: bool = (false, parse_no_flag, [TRACKED_NO_CRATE_HASH],
1162         "run all passes except codegen; no output"),
1163     no_generate_arange_section: bool = (false, parse_no_flag, [TRACKED],
1164         "omit DWARF address ranges that give faster lookups"),
1165     no_interleave_lints: bool = (false, parse_no_flag, [UNTRACKED],
1166         "execute lints separately; allows benchmarking individual lints"),
1167     no_leak_check: bool = (false, parse_no_flag, [UNTRACKED],
1168         "disable the 'leak check' for subtyping; unsound, but useful for tests"),
1169     no_link: bool = (false, parse_no_flag, [TRACKED],
1170         "compile without linking"),
1171     no_parallel_llvm: bool = (false, parse_no_flag, [UNTRACKED],
1172         "run LLVM in non-parallel mode (while keeping codegen-units and ThinLTO)"),
1173     normalize_docs: bool = (false, parse_bool, [TRACKED],
1174         "normalize associated items in rustdoc when generating documentation"),
1175     osx_rpath_install_name: bool = (false, parse_bool, [TRACKED],
1176         "pass `-install_name @rpath/...` to the macOS linker (default: no)"),
1177     panic_abort_tests: bool = (false, parse_bool, [TRACKED],
1178         "support compiling tests with panic=abort (default: no)"),
1179     parse_only: bool = (false, parse_bool, [UNTRACKED],
1180         "parse only; do not compile, assemble, or link (default: no)"),
1181     perf_stats: bool = (false, parse_bool, [UNTRACKED],
1182         "print some performance-related statistics (default: no)"),
1183     plt: Option<bool> = (None, parse_opt_bool, [TRACKED],
1184         "whether to use the PLT when calling into shared libraries;
1185         only has effect for PIC code on systems with ELF binaries
1186         (default: PLT is disabled if full relro is enabled)"),
1187     polonius: bool = (false, parse_bool, [TRACKED],
1188         "enable polonius-based borrow-checker (default: no)"),
1189     polymorphize: bool = (false, parse_bool, [TRACKED],
1190           "perform polymorphization analysis"),
1191     pre_link_arg: (/* redirected to pre_link_args */) = ((), parse_string_push, [UNTRACKED],
1192         "a single extra argument to prepend the linker invocation (can be used several times)"),
1193     pre_link_args: Vec<String> = (Vec::new(), parse_list, [UNTRACKED],
1194         "extra arguments to prepend to the linker invocation (space separated)"),
1195     precise_enum_drop_elaboration: bool = (true, parse_bool, [TRACKED],
1196         "use a more precise version of drop elaboration for matches on enums (default: yes). \
1197         This results in better codegen, but has caused miscompilations on some tier 2 platforms. \
1198         See #77382 and #74551."),
1199     print_fuel: Option<String> = (None, parse_opt_string, [TRACKED],
1200         "make rustc print the total optimization fuel used by a crate"),
1201     print_link_args: bool = (false, parse_bool, [UNTRACKED],
1202         "print the arguments passed to the linker (default: no)"),
1203     print_llvm_passes: bool = (false, parse_bool, [UNTRACKED],
1204         "print the LLVM optimization passes being run (default: no)"),
1205     print_mono_items: Option<String> = (None, parse_opt_string, [UNTRACKED],
1206         "print the result of the monomorphization collection pass"),
1207     print_type_sizes: bool = (false, parse_bool, [UNTRACKED],
1208         "print layout information for each type encountered (default: no)"),
1209     proc_macro_backtrace: bool = (false, parse_bool, [UNTRACKED],
1210          "show backtraces for panics during proc-macro execution (default: no)"),
1211     profile: bool = (false, parse_bool, [TRACKED],
1212         "insert profiling code (default: no)"),
1213     profile_closures: bool = (false, parse_no_flag, [UNTRACKED],
1214         "profile size of closures"),
1215     profile_emit: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
1216         "file path to emit profiling data at runtime when using 'profile' \
1217         (default based on relative source path)"),
1218     profiler_runtime: Option<String> = (Some(String::from("profiler_builtins")), parse_opt_string, [TRACKED],
1219         "name of the profiler runtime crate to automatically inject, or None to disable"),
1220     query_dep_graph: bool = (false, parse_bool, [UNTRACKED],
1221         "enable queries of the dependency graph for regression testing (default: no)"),
1222     query_stats: bool = (false, parse_bool, [UNTRACKED],
1223         "print some statistics about the query system (default: no)"),
1224     relax_elf_relocations: Option<bool> = (None, parse_opt_bool, [TRACKED],
1225         "whether ELF relocations can be relaxed"),
1226     relro_level: Option<RelroLevel> = (None, parse_relro_level, [TRACKED],
1227         "choose which RELRO level to use"),
1228     simulate_remapped_rust_src_base: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
1229         "simulate the effect of remap-debuginfo = true at bootstrapping by remapping path \
1230         to rust's source base directory. only meant for testing purposes"),
1231     report_delayed_bugs: bool = (false, parse_bool, [TRACKED],
1232         "immediately print bugs registered with `delay_span_bug` (default: no)"),
1233     sanitizer: SanitizerSet = (SanitizerSet::empty(), parse_sanitizers, [TRACKED],
1234         "use a sanitizer"),
1235     sanitizer_memory_track_origins: usize = (0, parse_sanitizer_memory_track_origins, [TRACKED],
1236         "enable origins tracking in MemorySanitizer"),
1237     sanitizer_recover: SanitizerSet = (SanitizerSet::empty(), parse_sanitizers, [TRACKED],
1238         "enable recovery for selected sanitizers"),
1239     saturating_float_casts: Option<bool> = (None, parse_opt_bool, [TRACKED],
1240         "make float->int casts UB-free: numbers outside the integer type's range are clipped to \
1241         the max/min integer respectively, and NaN is mapped to 0 (default: yes)"),
1242     save_analysis: bool = (false, parse_bool, [UNTRACKED],
1243         "write syntax and type analysis (in JSON format) information, in \
1244         addition to normal output (default: no)"),
1245     self_profile: SwitchWithOptPath = (SwitchWithOptPath::Disabled,
1246         parse_switch_with_opt_path, [UNTRACKED],
1247         "run the self profiler and output the raw event data"),
1248     /// keep this in sync with the event filter names in librustc_data_structures/profiling.rs
1249     self_profile_events: Option<Vec<String>> = (None, parse_opt_comma_list, [UNTRACKED],
1250         "specify the events recorded by the self profiler;
1251         for example: `-Z self-profile-events=default,query-keys`
1252         all options: none, all, default, generic-activity, query-provider, query-cache-hit
1253                      query-blocked, incr-cache-load, incr-result-hashing, query-keys, function-args, args, llvm"),
1254     share_generics: Option<bool> = (None, parse_opt_bool, [TRACKED],
1255         "make the current crate share its generic instantiations"),
1256     show_span: Option<String> = (None, parse_opt_string, [TRACKED],
1257         "show spans for compiler debugging (expr|pat|ty)"),
1258     span_debug: bool = (false, parse_bool, [UNTRACKED],
1259         "forward proc_macro::Span's `Debug` impl to `Span`"),
1260     /// o/w tests have closure@path
1261     span_free_formats: bool = (false, parse_bool, [UNTRACKED],
1262         "exclude spans when debug-printing compiler state (default: no)"),
1263     src_hash_algorithm: Option<SourceFileHashAlgorithm> = (None, parse_src_file_hash, [TRACKED],
1264         "hash algorithm of source files in debug info (`md5`, `sha1`, or `sha256`)"),
1265     strip: Strip = (Strip::None, parse_strip, [UNTRACKED],
1266         "tell the linker which information to strip (`none` (default), `debuginfo` or `symbols`)"),
1267     split_dwarf_inlining: bool = (true, parse_bool, [UNTRACKED],
1268         "provide minimal debug info in the object/executable to facilitate online \
1269          symbolication/stack traces in the absence of .dwo/.dwp files when using Split DWARF"),
1270     symbol_mangling_version: Option<SymbolManglingVersion> = (None,
1271         parse_symbol_mangling_version, [TRACKED],
1272         "which mangling version to use for symbol names ('legacy' (default) or 'v0')"),
1273     teach: bool = (false, parse_bool, [TRACKED],
1274         "show extended diagnostic help (default: no)"),
1275     terminal_width: Option<usize> = (None, parse_opt_number, [UNTRACKED],
1276         "set the current terminal width"),
1277     tune_cpu: Option<String> = (None, parse_opt_string, [TRACKED],
1278         "select processor to schedule for (`rustc --print target-cpus` for details)"),
1279     thinlto: Option<bool> = (None, parse_opt_bool, [TRACKED],
1280         "enable ThinLTO when possible"),
1281     thir_unsafeck: bool = (false, parse_bool, [TRACKED],
1282         "use the work-in-progress THIR unsafety checker. NOTE: this is unsound (default: no)"),
1283     /// We default to 1 here since we want to behave like
1284     /// a sequential compiler for now. This'll likely be adjusted
1285     /// in the future. Note that -Zthreads=0 is the way to get
1286     /// the num_cpus behavior.
1287     threads: usize = (1, parse_threads, [UNTRACKED],
1288         "use a thread pool with N threads"),
1289     time: bool = (false, parse_bool, [UNTRACKED],
1290         "measure time of rustc processes (default: no)"),
1291     time_llvm_passes: bool = (false, parse_bool, [UNTRACKED],
1292         "measure time of each LLVM pass (default: no)"),
1293     time_passes: bool = (false, parse_bool, [UNTRACKED],
1294         "measure time of each rustc pass (default: no)"),
1295     tls_model: Option<TlsModel> = (None, parse_tls_model, [TRACKED],
1296         "choose the TLS model to use (`rustc --print tls-models` for details)"),
1297     trace_macros: bool = (false, parse_bool, [UNTRACKED],
1298         "for every macro invocation, print its name and arguments (default: no)"),
1299     trap_unreachable: Option<bool> = (None, parse_opt_bool, [TRACKED],
1300         "generate trap instructions for unreachable intrinsics (default: use target setting, usually yes)"),
1301     treat_err_as_bug: Option<NonZeroUsize> = (None, parse_treat_err_as_bug, [TRACKED],
1302         "treat error number `val` that occurs as bug"),
1303     trim_diagnostic_paths: bool = (true, parse_bool, [UNTRACKED],
1304         "in diagnostics, use heuristics to shorten paths referring to items"),
1305     ui_testing: bool = (false, parse_bool, [UNTRACKED],
1306         "emit compiler diagnostics in a form suitable for UI testing (default: no)"),
1307     unleash_the_miri_inside_of_you: bool = (false, parse_bool, [TRACKED],
1308         "take the brakes off const evaluation. NOTE: this is unsound (default: no)"),
1309     unpretty: Option<String> = (None, parse_unpretty, [UNTRACKED],
1310         "present the input source, unstable (and less-pretty) variants;
1311         valid types are any of the types for `--pretty`, as well as:
1312         `expanded`, `expanded,identified`,
1313         `expanded,hygiene` (with internal representations),
1314         `everybody_loops` (all function bodies replaced with `loop {}`),
1315         `ast-tree` (raw AST before expansion),
1316         `ast-tree,expanded` (raw AST after expansion),
1317         `hir` (the HIR), `hir,identified`,
1318         `hir,typed` (HIR with types for each node),
1319         `hir-tree` (dump the raw HIR),
1320         `mir` (the MIR), or `mir-cfg` (graphviz formatted MIR)"),
1321     unsound_mir_opts: bool = (false, parse_bool, [TRACKED],
1322         "enable unsound and buggy MIR optimizations (default: no)"),
1323     unstable_options: bool = (false, parse_bool, [UNTRACKED],
1324         "adds unstable command line options to rustc interface (default: no)"),
1325     use_ctors_section: Option<bool> = (None, parse_opt_bool, [TRACKED],
1326         "use legacy .ctors section for initializers rather than .init_array"),
1327     validate_mir: bool = (false, parse_bool, [UNTRACKED],
1328         "validate MIR after each transformation"),
1329     verbose: bool = (false, parse_bool, [UNTRACKED],
1330         "in general, enable more debug printouts (default: no)"),
1331     verify_llvm_ir: bool = (false, parse_bool, [TRACKED],
1332         "verify LLVM IR (default: no)"),
1333     wasi_exec_model: Option<WasiExecModel> = (None, parse_wasi_exec_model, [TRACKED],
1334         "whether to build a wasi command or reactor"),
1335
1336     // This list is in alphabetical order.
1337     //
1338     // If you add a new option, please update:
1339     // - compiler/rustc_interface/src/tests.rs
1340 }
1341
1342 #[derive(Clone, Hash, PartialEq, Eq, Debug)]
1343 pub enum WasiExecModel {
1344     Command,
1345     Reactor,
1346 }
1347
1348 #[derive(Clone, Copy, Hash)]
1349 pub enum LdImpl {
1350     Lld,
1351 }