rustc_session/
options.rs

1use std::collections::BTreeMap;
2use std::hash::{DefaultHasher, Hasher};
3use std::num::{IntErrorKind, NonZero};
4use std::path::PathBuf;
5use std::str;
6
7use rustc_abi::Align;
8use rustc_data_structures::fx::FxIndexMap;
9use rustc_data_structures::profiling::TimePassesFormat;
10use rustc_data_structures::stable_hasher::Hash64;
11use rustc_errors::{ColorConfig, LanguageIdentifier, TerminalUrl};
12use rustc_feature::UnstableFeatures;
13use rustc_macros::{Decodable, Encodable};
14use rustc_span::edition::Edition;
15use rustc_span::{RealFileName, SourceFileHashAlgorithm};
16use rustc_target::spec::{
17    CodeModel, FramePointer, LinkerFlavorCli, MergeFunctions, OnBrokenPipe, PanicStrategy,
18    RelocModel, RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, SymbolVisibility,
19    TargetTuple, TlsModel, WasmCAbi,
20};
21
22use crate::config::*;
23use crate::search_paths::SearchPath;
24use crate::utils::NativeLib;
25use crate::{EarlyDiagCtxt, lint};
26
27macro_rules! insert {
28    ($opt_name:ident, $opt_expr:expr, $sub_hashes:expr) => {
29        if $sub_hashes
30            .insert(stringify!($opt_name), $opt_expr as &dyn dep_tracking::DepTrackingHash)
31            .is_some()
32        {
33            panic!("duplicate key in CLI DepTrackingHash: {}", stringify!($opt_name))
34        }
35    };
36}
37
38macro_rules! hash_opt {
39    ($opt_name:ident, $opt_expr:expr, $sub_hashes:expr, $_for_crate_hash: ident, [UNTRACKED]) => {{}};
40    ($opt_name:ident, $opt_expr:expr, $sub_hashes:expr, $_for_crate_hash: ident, [TRACKED]) => {{ insert!($opt_name, $opt_expr, $sub_hashes) }};
41    ($opt_name:ident, $opt_expr:expr, $sub_hashes:expr, $for_crate_hash: ident, [TRACKED_NO_CRATE_HASH]) => {{
42        if !$for_crate_hash {
43            insert!($opt_name, $opt_expr, $sub_hashes)
44        }
45    }};
46    ($opt_name:ident, $opt_expr:expr, $sub_hashes:expr, $_for_crate_hash: ident, [SUBSTRUCT]) => {{}};
47}
48
49macro_rules! hash_substruct {
50    ($opt_name:ident, $opt_expr:expr, $error_format:expr, $for_crate_hash:expr, $hasher:expr, [UNTRACKED]) => {{}};
51    ($opt_name:ident, $opt_expr:expr, $error_format:expr, $for_crate_hash:expr, $hasher:expr, [TRACKED]) => {{}};
52    ($opt_name:ident, $opt_expr:expr, $error_format:expr, $for_crate_hash:expr, $hasher:expr, [TRACKED_NO_CRATE_HASH]) => {{}};
53    ($opt_name:ident, $opt_expr:expr, $error_format:expr, $for_crate_hash:expr, $hasher:expr, [SUBSTRUCT]) => {
54        use crate::config::dep_tracking::DepTrackingHash;
55        $opt_expr.dep_tracking_hash($for_crate_hash, $error_format).hash(
56            $hasher,
57            $error_format,
58            $for_crate_hash,
59        );
60    };
61}
62
63/// Extended target modifier info.
64/// For example, when external target modifier is '-Zregparm=2':
65/// Target modifier enum value + user value ('2') from external crate
66/// is converted into description: prefix ('Z'), name ('regparm'), tech value ('Some(2)').
67pub struct ExtendedTargetModifierInfo {
68    /// Flag prefix (usually, 'C' for codegen flags or 'Z' for unstable flags)
69    pub prefix: String,
70    /// Flag name
71    pub name: String,
72    /// Flag parsed technical value
73    pub tech_value: String,
74}
75
76/// A recorded -Zopt_name=opt_value (or -Copt_name=opt_value)
77/// which alter the ABI or effectiveness of exploit mitigations.
78#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Encodable, Decodable)]
79pub struct TargetModifier {
80    /// Option enum value
81    pub opt: OptionsTargetModifiers,
82    /// User-provided option value (before parsing)
83    pub value_name: String,
84}
85
86impl TargetModifier {
87    pub fn extend(&self) -> ExtendedTargetModifierInfo {
88        self.opt.reparse(&self.value_name)
89    }
90}
91
92fn tmod_push_impl(
93    opt: OptionsTargetModifiers,
94    tmod_vals: &BTreeMap<OptionsTargetModifiers, String>,
95    tmods: &mut Vec<TargetModifier>,
96) {
97    tmods.push(TargetModifier { opt, value_name: tmod_vals.get(&opt).cloned().unwrap_or_default() })
98}
99
100macro_rules! tmod_push {
101    ($struct_name:ident, $tmod_enum_name:ident, $opt_name:ident, $mods:expr, $tmod_vals:expr) => {
102        tmod_push_impl(
103            OptionsTargetModifiers::$struct_name($tmod_enum_name::$opt_name),
104            $tmod_vals,
105            $mods,
106        );
107    };
108}
109
110macro_rules! gather_tmods {
111    ($struct_name:ident, $tmod_enum_name:ident, $opt_name:ident, $opt_expr:expr, $mods:expr, $tmod_vals:expr,
112        [SUBSTRUCT], [TARGET_MODIFIER]) => {
113        compile_error!("SUBSTRUCT can't be target modifier");
114    };
115    ($struct_name:ident, $tmod_enum_name:ident, $opt_name:ident, $opt_expr:expr, $mods:expr, $tmod_vals:expr,
116        [UNTRACKED], [TARGET_MODIFIER]) => {
117        tmod_push!($struct_name, $tmod_enum_name, $opt_name, $mods, $tmod_vals)
118    };
119    ($struct_name:ident, $tmod_enum_name:ident, $opt_name:ident, $opt_expr:expr, $mods:expr, $tmod_vals:expr,
120        [TRACKED], [TARGET_MODIFIER]) => {
121        tmod_push!($struct_name, $tmod_enum_name, $opt_name, $mods, $tmod_vals)
122    };
123    ($struct_name:ident, $tmod_enum_name:ident, $opt_name:ident, $opt_expr:expr, $mods:expr, $tmod_vals:expr,
124        [TRACKED_NO_CRATE_HASH], [TARGET_MODIFIER]) => {
125        tmod_push!($struct_name, $tmod_enum_name, $opt_name, $mods, $tmod_vals)
126    };
127    ($struct_name:ident, $tmod_enum_name:ident, $opt_name:ident, $opt_expr:expr, $mods:expr, $tmod_vals:expr,
128        [SUBSTRUCT], []) => {
129        $opt_expr.gather_target_modifiers($mods, $tmod_vals);
130    };
131    ($struct_name:ident, $tmod_enum_name:ident, $opt_name:ident, $opt_expr:expr, $mods:expr, $tmod_vals:expr,
132        [UNTRACKED], []) => {{}};
133    ($struct_name:ident, $tmod_enum_name:ident, $opt_name:ident, $opt_expr:expr, $mods:expr, $tmod_vals:expr,
134        [TRACKED], []) => {{}};
135    ($struct_name:ident, $tmod_enum_name:ident, $opt_name:ident, $opt_expr:expr, $mods:expr, $tmod_vals:expr,
136        [TRACKED_NO_CRATE_HASH], []) => {{}};
137}
138
139macro_rules! gather_tmods_top_level {
140    ($_opt_name:ident, $opt_expr:expr, $mods:expr, $tmod_vals:expr, [SUBSTRUCT $substruct_enum:ident]) => {
141        $opt_expr.gather_target_modifiers($mods, $tmod_vals);
142    };
143    ($opt_name:ident, $opt_expr:expr, $mods:expr, $tmod_vals:expr, [$non_substruct:ident TARGET_MODIFIER]) => {
144        compile_error!("Top level option can't be target modifier");
145    };
146    ($opt_name:ident, $opt_expr:expr, $mods:expr, $tmod_vals:expr, [$non_substruct:ident]) => {};
147}
148
149/// Macro for generating OptionsTargetsModifiers top-level enum with impl.
150/// Will generate something like:
151/// ```rust,ignore (illustrative)
152/// pub enum OptionsTargetModifiers {
153///     CodegenOptions(CodegenOptionsTargetModifiers),
154///     UnstableOptions(UnstableOptionsTargetModifiers),
155/// }
156/// impl OptionsTargetModifiers {
157///     pub fn reparse(&self, user_value: &str) -> ExtendedTargetModifierInfo {
158///         match self {
159///             Self::CodegenOptions(v) => v.reparse(user_value),
160///             Self::UnstableOptions(v) => v.reparse(user_value),
161///         }
162///     }
163///     pub fn is_target_modifier(flag_name: &str) -> bool {
164///         CodegenOptionsTargetModifiers::is_target_modifier(flag_name) ||
165///         UnstableOptionsTargetModifiers::is_target_modifier(flag_name)
166///     }
167/// }
168/// ```
169macro_rules! top_level_tmod_enum {
170    ($( {$($optinfo:tt)*} ),* $(,)*) => {
171        top_level_tmod_enum! { @parse {}, (user_value){}; $($($optinfo)*|)* }
172    };
173    // Termination
174    (
175        @parse
176        {$($variant:tt($substruct_enum:tt))*},
177        ($user_value:ident){$($pout:tt)*};
178    ) => {
179        #[allow(non_camel_case_types)]
180        #[derive(PartialEq, Eq, PartialOrd, Ord, Debug, Copy, Clone, Encodable, Decodable)]
181        pub enum OptionsTargetModifiers {
182            $($variant($substruct_enum)),*
183        }
184        impl OptionsTargetModifiers {
185            #[allow(unused_variables)]
186            pub fn reparse(&self, $user_value: &str) -> ExtendedTargetModifierInfo {
187                #[allow(unreachable_patterns)]
188                match self {
189                    $($pout)*
190                    _ => panic!("unknown target modifier option: {:?}", *self)
191                }
192            }
193            pub fn is_target_modifier(flag_name: &str) -> bool {
194                $($substruct_enum::is_target_modifier(flag_name))||*
195            }
196        }
197    };
198    // Adding SUBSTRUCT option group into $eout
199    (
200        @parse {$($eout:tt)*}, ($puser_value:ident){$($pout:tt)*};
201            [SUBSTRUCT $substruct_enum:ident $variant:ident] |
202        $($tail:tt)*
203    ) => {
204        top_level_tmod_enum! {
205            @parse
206            {
207                $($eout)*
208                $variant($substruct_enum)
209            },
210            ($puser_value){
211                $($pout)*
212                Self::$variant(v) => v.reparse($puser_value),
213            };
214            $($tail)*
215        }
216    };
217    // Skipping non-target-modifier and non-substruct
218    (
219        @parse {$($eout:tt)*}, ($puser_value:ident){$($pout:tt)*};
220            [$non_substruct:ident] |
221        $($tail:tt)*
222    ) => {
223        top_level_tmod_enum! {
224            @parse
225            {
226                $($eout)*
227            },
228            ($puser_value){
229                $($pout)*
230            };
231            $($tail)*
232        }
233    };
234}
235
236macro_rules! top_level_options {
237    ( $( #[$top_level_attr:meta] )* pub struct Options { $(
238        $( #[$attr:meta] )*
239        $opt:ident : $t:ty [$dep_tracking_marker:ident $( $tmod:ident $variant:ident )?],
240    )* } ) => (
241        top_level_tmod_enum!( {$([$dep_tracking_marker $($tmod $variant),*])|*} );
242
243        #[derive(Clone)]
244        $( #[$top_level_attr] )*
245        pub struct Options {
246            $(
247                $( #[$attr] )*
248                pub $opt: $t
249            ),*,
250            pub target_modifiers: BTreeMap<OptionsTargetModifiers, String>,
251        }
252
253        impl Options {
254            pub fn dep_tracking_hash(&self, for_crate_hash: bool) -> u64 {
255                let mut sub_hashes = BTreeMap::new();
256                $({
257                    hash_opt!($opt,
258                                &self.$opt,
259                                &mut sub_hashes,
260                                for_crate_hash,
261                                [$dep_tracking_marker]);
262                })*
263                let mut hasher = DefaultHasher::new();
264                dep_tracking::stable_hash(sub_hashes,
265                                          &mut hasher,
266                                          self.error_format,
267                                          for_crate_hash);
268                $({
269                    hash_substruct!($opt,
270                        &self.$opt,
271                        self.error_format,
272                        for_crate_hash,
273                        &mut hasher,
274                        [$dep_tracking_marker]);
275                })*
276                hasher.finish()
277            }
278
279            pub fn gather_target_modifiers(&self) -> Vec<TargetModifier> {
280                let mut mods = Vec::<TargetModifier>::new();
281                $({
282                    gather_tmods_top_level!($opt,
283                        &self.$opt, &mut mods, &self.target_modifiers,
284                        [$dep_tracking_marker $($tmod),*]);
285                })*
286                mods.sort_by(|a, b| a.opt.cmp(&b.opt));
287                mods
288            }
289        }
290    );
291}
292
293top_level_options!(
294    /// The top-level command-line options struct.
295    ///
296    /// For each option, one has to specify how it behaves with regard to the
297    /// dependency tracking system of incremental compilation. This is done via the
298    /// square-bracketed directive after the field type. The options are:
299    ///
300    /// - `[TRACKED]`
301    /// A change in the given field will cause the compiler to completely clear the
302    /// incremental compilation cache before proceeding.
303    ///
304    /// - `[TRACKED_NO_CRATE_HASH]`
305    /// Same as `[TRACKED]`, but will not affect the crate hash. This is useful for options that
306    /// only affect the incremental cache.
307    ///
308    /// - `[UNTRACKED]`
309    /// Incremental compilation is not influenced by this option.
310    ///
311    /// - `[SUBSTRUCT]`
312    /// Second-level sub-structs containing more options.
313    ///
314    /// If you add a new option to this struct or one of the sub-structs like
315    /// `CodegenOptions`, think about how it influences incremental compilation. If in
316    /// doubt, specify `[TRACKED]`, which is always "correct" but might lead to
317    /// unnecessary re-compilation.
318    #[rustc_lint_opt_ty]
319    pub struct Options {
320        /// The crate config requested for the session, which may be combined
321        /// with additional crate configurations during the compile process.
322        #[rustc_lint_opt_deny_field_access("use `TyCtxt::crate_types` instead of this field")]
323        crate_types: Vec<CrateType> [TRACKED],
324        optimize: OptLevel [TRACKED],
325        /// Include the `debug_assertions` flag in dependency tracking, since it
326        /// can influence whether overflow checks are done or not.
327        debug_assertions: bool [TRACKED],
328        debuginfo: DebugInfo [TRACKED],
329        debuginfo_compression: DebugInfoCompression [TRACKED],
330        lint_opts: Vec<(String, lint::Level)> [TRACKED_NO_CRATE_HASH],
331        lint_cap: Option<lint::Level> [TRACKED_NO_CRATE_HASH],
332        describe_lints: bool [UNTRACKED],
333        output_types: OutputTypes [TRACKED],
334        search_paths: Vec<SearchPath> [UNTRACKED],
335        libs: Vec<NativeLib> [TRACKED],
336        maybe_sysroot: Option<PathBuf> [UNTRACKED],
337
338        target_triple: TargetTuple [TRACKED],
339
340        /// Effective logical environment used by `env!`/`option_env!` macros
341        logical_env: FxIndexMap<String, String> [TRACKED],
342
343        test: bool [TRACKED],
344        error_format: ErrorOutputType [UNTRACKED],
345        diagnostic_width: Option<usize> [UNTRACKED],
346
347        /// If `Some`, enable incremental compilation, using the given
348        /// directory to store intermediate results.
349        incremental: Option<PathBuf> [UNTRACKED],
350        assert_incr_state: Option<IncrementalStateAssertion> [UNTRACKED],
351        /// Set by the `Config::hash_untracked_state` callback for custom
352        /// drivers to invalidate the incremental cache
353        #[rustc_lint_opt_deny_field_access("should only be used via `Config::hash_untracked_state`")]
354        untracked_state_hash: Hash64 [TRACKED_NO_CRATE_HASH],
355
356        unstable_opts: UnstableOptions [SUBSTRUCT UnstableOptionsTargetModifiers UnstableOptions],
357        prints: Vec<PrintRequest> [UNTRACKED],
358        cg: CodegenOptions [SUBSTRUCT CodegenOptionsTargetModifiers CodegenOptions],
359        externs: Externs [UNTRACKED],
360        crate_name: Option<String> [TRACKED],
361        /// Indicates how the compiler should treat unstable features.
362        unstable_features: UnstableFeatures [TRACKED],
363
364        /// Indicates whether this run of the compiler is actually rustdoc. This
365        /// is currently just a hack and will be removed eventually, so please
366        /// try to not rely on this too much.
367        actually_rustdoc: bool [TRACKED],
368        /// Whether name resolver should resolve documentation links.
369        resolve_doc_links: ResolveDocLinks [TRACKED],
370
371        /// Control path trimming.
372        trimmed_def_paths: bool [TRACKED],
373
374        /// Specifications of codegen units / ThinLTO which are forced as a
375        /// result of parsing command line options. These are not necessarily
376        /// what rustc was invoked with, but massaged a bit to agree with
377        /// commands like `--emit llvm-ir` which they're often incompatible with
378        /// if we otherwise use the defaults of rustc.
379        #[rustc_lint_opt_deny_field_access("use `Session::codegen_units` instead of this field")]
380        cli_forced_codegen_units: Option<usize> [UNTRACKED],
381        #[rustc_lint_opt_deny_field_access("use `Session::lto` instead of this field")]
382        cli_forced_local_thinlto_off: bool [UNTRACKED],
383
384        /// Remap source path prefixes in all output (messages, object files, debug, etc.).
385        remap_path_prefix: Vec<(PathBuf, PathBuf)> [TRACKED_NO_CRATE_HASH],
386        /// Base directory containing the `src/` for the Rust standard library, and
387        /// potentially `rustc` as well, if we can find it. Right now it's always
388        /// `$sysroot/lib/rustlib/src/rust` (i.e. the `rustup` `rust-src` component).
389        ///
390        /// This directory is what the virtual `/rustc/$hash` is translated back to,
391        /// if Rust was built with path remapping to `/rustc/$hash` enabled
392        /// (the `rust.remap-debuginfo` option in `config.toml`).
393        real_rust_source_base_dir: Option<PathBuf> [TRACKED_NO_CRATE_HASH],
394
395        edition: Edition [TRACKED],
396
397        /// `true` if we're emitting JSON blobs about each artifact produced
398        /// by the compiler.
399        json_artifact_notifications: bool [TRACKED],
400
401        /// `true` if we're emitting a JSON blob containing the unused externs
402        json_unused_externs: JsonUnusedExterns [UNTRACKED],
403
404        /// `true` if we're emitting a JSON job containing a future-incompat report for lints
405        json_future_incompat: bool [TRACKED],
406
407        pretty: Option<PpMode> [UNTRACKED],
408
409        /// The (potentially remapped) working directory
410        working_dir: RealFileName [TRACKED],
411        color: ColorConfig [UNTRACKED],
412
413        verbose: bool [TRACKED_NO_CRATE_HASH],
414    }
415);
416
417macro_rules! tmod_enum_opt {
418    ($struct_name:ident, $tmod_enum_name:ident, $opt:ident, $v:ident) => {
419        Some(OptionsTargetModifiers::$struct_name($tmod_enum_name::$opt))
420    };
421    ($struct_name:ident, $tmod_enum_name:ident, $opt:ident, ) => {
422        None
423    };
424}
425
426macro_rules! tmod_enum {
427    ($tmod_enum_name:ident, $prefix:expr, $( {$($optinfo:tt)*} ),* $(,)*) => {
428        tmod_enum! { $tmod_enum_name, $prefix, @parse {}, (user_value){}; $($($optinfo)*|)* }
429    };
430    // Termination
431    (
432        $tmod_enum_name:ident, $prefix:expr,
433        @parse
434        {$($eout:tt)*},
435        ($user_value:ident){$($pout:tt)*};
436    ) => {
437        #[allow(non_camel_case_types)]
438        #[derive(PartialEq, Eq, PartialOrd, Ord, Debug, Copy, Clone, Encodable, Decodable)]
439        pub enum $tmod_enum_name {
440            $($eout),*
441        }
442        impl $tmod_enum_name {
443            #[allow(unused_variables)]
444            pub fn reparse(&self, $user_value: &str) -> ExtendedTargetModifierInfo {
445                #[allow(unreachable_patterns)]
446                match self {
447                    $($pout)*
448                    _ => panic!("unknown target modifier option: {:?}", *self)
449                }
450            }
451            pub fn is_target_modifier(flag_name: &str) -> bool {
452                match flag_name.replace('-', "_").as_str() {
453                    $(stringify!($eout) => true,)*
454                    _ => false,
455                }
456            }
457        }
458    };
459    // Adding target-modifier option into $eout
460    (
461        $tmod_enum_name:ident, $prefix:expr,
462        @parse {$($eout:tt)*}, ($puser_value:ident){$($pout:tt)*};
463            $opt:ident, $parse:ident, $t:ty, [TARGET_MODIFIER] |
464        $($tail:tt)*
465    ) => {
466        tmod_enum! {
467            $tmod_enum_name, $prefix,
468            @parse
469            {
470                $($eout)*
471                $opt
472            },
473            ($puser_value){
474                $($pout)*
475                Self::$opt => {
476                    let mut parsed : $t = Default::default();
477                    parse::$parse(&mut parsed, Some($puser_value));
478                    ExtendedTargetModifierInfo {
479                        prefix: $prefix.to_string(),
480                        name: stringify!($opt).to_string().replace('_', "-"),
481                        tech_value: format!("{:?}", parsed),
482                    }
483                },
484            };
485            $($tail)*
486        }
487    };
488    // Skipping non-target-modifier
489    (
490        $tmod_enum_name:ident, $prefix:expr,
491        @parse {$($eout:tt)*}, ($puser_value:ident){$($pout:tt)*};
492            $opt:ident, $parse:ident, $t:ty, [] |
493        $($tail:tt)*
494    ) => {
495        tmod_enum! {
496            $tmod_enum_name, $prefix,
497            @parse
498            {
499                $($eout)*
500            },
501            ($puser_value){
502                $($pout)*
503            };
504            $($tail)*
505        }
506    };
507}
508
509/// Defines all `CodegenOptions`/`DebuggingOptions` fields and parsers all at once. The goal of this
510/// macro is to define an interface that can be programmatically used by the option parser
511/// to initialize the struct without hardcoding field names all over the place.
512///
513/// The goal is to invoke this macro once with the correct fields, and then this macro generates all
514/// necessary code. The main gotcha of this macro is the `cgsetters` module which is a bunch of
515/// generated code to parse an option into its respective field in the struct. There are a few
516/// hand-written parsers for parsing specific types of values in this module.
517macro_rules! options {
518    ($struct_name:ident, $tmod_enum_name:ident, $stat:ident, $optmod:ident, $prefix:expr, $outputname:expr,
519     $($( #[$attr:meta] )* $opt:ident : $t:ty = (
520        $init:expr,
521        $parse:ident,
522        [$dep_tracking_marker:ident $( $tmod:ident )?],
523        $desc:expr
524        $(, deprecated_do_nothing: $dnn:literal )?)
525     ),* ,) =>
526(
527    #[derive(Clone)]
528    #[rustc_lint_opt_ty]
529    pub struct $struct_name { $( $( #[$attr] )* pub $opt: $t),* }
530
531    tmod_enum!( $tmod_enum_name, $prefix, {$($opt, $parse, $t, [$($tmod),*])|*} );
532
533    impl Default for $struct_name {
534        fn default() -> $struct_name {
535            $struct_name { $($opt: $init),* }
536        }
537    }
538
539    impl $struct_name {
540        pub fn build(
541            early_dcx: &EarlyDiagCtxt,
542            matches: &getopts::Matches,
543            target_modifiers: &mut BTreeMap<OptionsTargetModifiers, String>,
544        ) -> $struct_name {
545            build_options(early_dcx, matches, target_modifiers, $stat, $prefix, $outputname)
546        }
547
548        fn dep_tracking_hash(&self, for_crate_hash: bool, error_format: ErrorOutputType) -> u64 {
549            let mut sub_hashes = BTreeMap::new();
550            $({
551                hash_opt!($opt,
552                            &self.$opt,
553                            &mut sub_hashes,
554                            for_crate_hash,
555                            [$dep_tracking_marker]);
556            })*
557            let mut hasher = DefaultHasher::new();
558            dep_tracking::stable_hash(sub_hashes,
559                                        &mut hasher,
560                                        error_format,
561                                        for_crate_hash
562                                        );
563            hasher.finish()
564        }
565
566        pub fn gather_target_modifiers(
567            &self,
568            _mods: &mut Vec<TargetModifier>,
569            _tmod_vals: &BTreeMap<OptionsTargetModifiers, String>,
570        ) {
571            $({
572                gather_tmods!($struct_name, $tmod_enum_name, $opt, &self.$opt, _mods, _tmod_vals,
573                    [$dep_tracking_marker], [$($tmod),*]);
574            })*
575        }
576    }
577
578    pub const $stat: OptionDescrs<$struct_name> =
579        &[ $( OptionDesc{ name: stringify!($opt), setter: $optmod::$opt,
580            type_desc: desc::$parse, desc: $desc, is_deprecated_and_do_nothing: false $( || $dnn )?,
581            tmod: tmod_enum_opt!($struct_name, $tmod_enum_name, $opt, $($tmod),*) } ),* ];
582
583    mod $optmod {
584    $(
585        pub(super) fn $opt(cg: &mut super::$struct_name, v: Option<&str>) -> bool {
586            super::parse::$parse(&mut redirect_field!(cg.$opt), v)
587        }
588    )*
589    }
590
591) }
592
593impl CodegenOptions {
594    // JUSTIFICATION: defn of the suggested wrapper fn
595    #[allow(rustc::bad_opt_access)]
596    pub fn instrument_coverage(&self) -> InstrumentCoverage {
597        self.instrument_coverage
598    }
599}
600
601// Sometimes different options need to build a common structure.
602// That structure can be kept in one of the options' fields, the others become dummy.
603macro_rules! redirect_field {
604    ($cg:ident.link_arg) => {
605        $cg.link_args
606    };
607    ($cg:ident.pre_link_arg) => {
608        $cg.pre_link_args
609    };
610    ($cg:ident.$field:ident) => {
611        $cg.$field
612    };
613}
614
615type OptionSetter<O> = fn(&mut O, v: Option<&str>) -> bool;
616type OptionDescrs<O> = &'static [OptionDesc<O>];
617
618pub struct OptionDesc<O> {
619    name: &'static str,
620    setter: OptionSetter<O>,
621    // description for return value/type from mod desc
622    type_desc: &'static str,
623    // description for option from options table
624    desc: &'static str,
625    is_deprecated_and_do_nothing: bool,
626    tmod: Option<OptionsTargetModifiers>,
627}
628
629impl<O> OptionDesc<O> {
630    pub fn name(&self) -> &'static str {
631        self.name
632    }
633
634    pub fn desc(&self) -> &'static str {
635        self.desc
636    }
637}
638
639#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
640fn build_options<O: Default>(
641    early_dcx: &EarlyDiagCtxt,
642    matches: &getopts::Matches,
643    target_modifiers: &mut BTreeMap<OptionsTargetModifiers, String>,
644    descrs: OptionDescrs<O>,
645    prefix: &str,
646    outputname: &str,
647) -> O {
648    let mut op = O::default();
649    for option in matches.opt_strs(prefix) {
650        let (key, value) = match option.split_once('=') {
651            None => (option, None),
652            Some((k, v)) => (k.to_string(), Some(v)),
653        };
654
655        let option_to_lookup = key.replace('-', "_");
656        match descrs.iter().find(|opt_desc| opt_desc.name == option_to_lookup) {
657            Some(OptionDesc {
658                name: _,
659                setter,
660                type_desc,
661                desc,
662                is_deprecated_and_do_nothing,
663                tmod,
664            }) => {
665                if *is_deprecated_and_do_nothing {
666                    // deprecation works for prefixed options only
667                    assert!(!prefix.is_empty());
668                    early_dcx.early_warn(format!("`-{prefix} {key}`: {desc}"));
669                }
670                if !setter(&mut op, value) {
671                    match value {
672                        None => early_dcx.early_fatal(
673                            format!(
674                                "{outputname} option `{key}` requires {type_desc} ({prefix} {key}=<value>)"
675                            ),
676                        ),
677                        Some(value) => early_dcx.early_fatal(
678                            format!(
679                                "incorrect value `{value}` for {outputname} option `{key}` - {type_desc} was expected"
680                            ),
681                        ),
682                    }
683                }
684                if let Some(tmod) = *tmod
685                    && let Some(value) = value
686                {
687                    target_modifiers.insert(tmod, value.to_string());
688                }
689            }
690            None => early_dcx.early_fatal(format!("unknown {outputname} option: `{key}`")),
691        }
692    }
693    op
694}
695
696#[allow(non_upper_case_globals)]
697mod desc {
698    pub(crate) const parse_no_value: &str = "no value";
699    pub(crate) const parse_bool: &str =
700        "one of: `y`, `yes`, `on`, `true`, `n`, `no`, `off` or `false`";
701    pub(crate) const parse_opt_bool: &str = parse_bool;
702    pub(crate) const parse_string: &str = "a string";
703    pub(crate) const parse_opt_string: &str = parse_string;
704    pub(crate) const parse_string_push: &str = parse_string;
705    pub(crate) const parse_opt_langid: &str = "a language identifier";
706    pub(crate) const parse_opt_pathbuf: &str = "a path";
707    pub(crate) const parse_list: &str = "a space-separated list of strings";
708    pub(crate) const parse_list_with_polarity: &str =
709        "a comma-separated list of strings, with elements beginning with + or -";
710    pub(crate) const parse_autodiff: &str = "a comma separated list of settings: `Print`, `PrintTA`, `PrintAA`, `PrintPerf`, `PrintModBefore`, `PrintModAfterOpts`, `PrintModAfterEnzyme`, `LooseTypes`, `NoModOptAfter`, `EnableFncOpt`, `NoVecUnroll`, `Inline`";
711    pub(crate) const parse_comma_list: &str = "a comma-separated list of strings";
712    pub(crate) const parse_opt_comma_list: &str = parse_comma_list;
713    pub(crate) const parse_number: &str = "a number";
714    pub(crate) const parse_opt_number: &str = parse_number;
715    pub(crate) const parse_frame_pointer: &str = "one of `true`/`yes`/`on`, `false`/`no`/`off`, or (with -Zunstable-options) `non-leaf` or `always`";
716    pub(crate) const parse_threads: &str = parse_number;
717    pub(crate) const parse_time_passes_format: &str = "`text` (default) or `json`";
718    pub(crate) const parse_passes: &str = "a space-separated list of passes, or `all`";
719    pub(crate) const parse_panic_strategy: &str = "either `unwind` or `abort`";
720    pub(crate) const parse_on_broken_pipe: &str = "either `kill`, `error`, or `inherit`";
721    pub(crate) const parse_patchable_function_entry: &str = "either two comma separated integers (total_nops,prefix_nops), with prefix_nops <= total_nops, or one integer (total_nops)";
722    pub(crate) const parse_opt_panic_strategy: &str = parse_panic_strategy;
723    pub(crate) const parse_oom_strategy: &str = "either `panic` or `abort`";
724    pub(crate) const parse_relro_level: &str = "one of: `full`, `partial`, or `off`";
725    pub(crate) const parse_sanitizers: &str = "comma separated list of sanitizers: `address`, `cfi`, `dataflow`, `hwaddress`, `kcfi`, `kernel-address`, `leak`, `memory`, `memtag`, `safestack`, `shadow-call-stack`, or `thread`";
726    pub(crate) const parse_sanitizer_memory_track_origins: &str = "0, 1, or 2";
727    pub(crate) const parse_cfguard: &str =
728        "either a boolean (`yes`, `no`, `on`, `off`, etc), `checks`, or `nochecks`";
729    pub(crate) const parse_cfprotection: &str = "`none`|`no`|`n` (default), `branch`, `return`, or `full`|`yes`|`y` (equivalent to `branch` and `return`)";
730    pub(crate) const parse_debuginfo: &str = "either an integer (0, 1, 2), `none`, `line-directives-only`, `line-tables-only`, `limited`, or `full`";
731    pub(crate) const parse_debuginfo_compression: &str = "one of `none`, `zlib`, or `zstd`";
732    pub(crate) const parse_mir_strip_debuginfo: &str =
733        "one of `none`, `locals-in-tiny-functions`, or `all-locals`";
734    pub(crate) const parse_collapse_macro_debuginfo: &str = "one of `no`, `external`, or `yes`";
735    pub(crate) const parse_strip: &str = "either `none`, `debuginfo`, or `symbols`";
736    pub(crate) const parse_linker_flavor: &str = ::rustc_target::spec::LinkerFlavorCli::one_of();
737    pub(crate) const parse_dump_mono_stats: &str = "`markdown` (default) or `json`";
738    pub(crate) const parse_instrument_coverage: &str = parse_bool;
739    pub(crate) const parse_coverage_options: &str =
740        "`block` | `branch` | `condition` | `mcdc` | `no-mir-spans`";
741    pub(crate) const parse_instrument_xray: &str = "either a boolean (`yes`, `no`, `on`, `off`, etc), or a comma separated list of settings: `always` or `never` (mutually exclusive), `ignore-loops`, `instruction-threshold=N`, `skip-entry`, `skip-exit`";
742    pub(crate) const parse_unpretty: &str = "`string` or `string=string`";
743    pub(crate) const parse_treat_err_as_bug: &str = "either no value or a non-negative number";
744    pub(crate) const parse_next_solver_config: &str =
745        "either `globally` (when used without an argument), `coherence` (default) or `no`";
746    pub(crate) const parse_lto: &str =
747        "either a boolean (`yes`, `no`, `on`, `off`, etc), `thin`, `fat`, or omitted";
748    pub(crate) const parse_linker_plugin_lto: &str =
749        "either a boolean (`yes`, `no`, `on`, `off`, etc), or the path to the linker plugin";
750    pub(crate) const parse_location_detail: &str = "either `none`, or a comma separated list of location details to track: `file`, `line`, or `column`";
751    pub(crate) const parse_fmt_debug: &str = "either `full`, `shallow`, or `none`";
752    pub(crate) const parse_switch_with_opt_path: &str =
753        "an optional path to the profiling data output directory";
754    pub(crate) const parse_merge_functions: &str =
755        "one of: `disabled`, `trampolines`, or `aliases`";
756    pub(crate) const parse_symbol_mangling_version: &str =
757        "one of: `legacy`, `v0` (RFC 2603), or `hashed`";
758    pub(crate) const parse_opt_symbol_visibility: &str =
759        "one of: `hidden`, `protected`, or `interposable`";
760    pub(crate) const parse_cargo_src_file_hash: &str =
761        "one of `blake3`, `md5`, `sha1`, or `sha256`";
762    pub(crate) const parse_src_file_hash: &str = "one of `md5`, `sha1`, or `sha256`";
763    pub(crate) const parse_relocation_model: &str =
764        "one of supported relocation models (`rustc --print relocation-models`)";
765    pub(crate) const parse_code_model: &str =
766        "one of supported code models (`rustc --print code-models`)";
767    pub(crate) const parse_tls_model: &str =
768        "one of supported TLS models (`rustc --print tls-models`)";
769    pub(crate) const parse_target_feature: &str = parse_string;
770    pub(crate) const parse_terminal_url: &str =
771        "either a boolean (`yes`, `no`, `on`, `off`, etc), or `auto`";
772    pub(crate) const parse_wasi_exec_model: &str = "either `command` or `reactor`";
773    pub(crate) const parse_split_debuginfo: &str =
774        "one of supported split-debuginfo modes (`off`, `packed`, or `unpacked`)";
775    pub(crate) const parse_split_dwarf_kind: &str =
776        "one of supported split dwarf modes (`split` or `single`)";
777    pub(crate) const parse_link_self_contained: &str = "one of: `y`, `yes`, `on`, `n`, `no`, `off`, or a list of enabled (`+` prefix) and disabled (`-` prefix) \
778        components: `crto`, `libc`, `unwind`, `linker`, `sanitizers`, `mingw`";
779    pub(crate) const parse_linker_features: &str =
780        "a list of enabled (`+` prefix) and disabled (`-` prefix) features: `lld`";
781    pub(crate) const parse_polonius: &str = "either no value or `legacy` (the default), or `next`";
782    pub(crate) const parse_stack_protector: &str =
783        "one of (`none` (default), `basic`, `strong`, or `all`)";
784    pub(crate) const parse_branch_protection: &str = "a `,` separated combination of `bti`, `pac-ret`, followed by a combination of `pc`, `b-key`, or `leaf`";
785    pub(crate) const parse_proc_macro_execution_strategy: &str =
786        "one of supported execution strategies (`same-thread`, or `cross-thread`)";
787    pub(crate) const parse_remap_path_scope: &str =
788        "comma separated list of scopes: `macro`, `diagnostics`, `debuginfo`, `object`, `all`";
789    pub(crate) const parse_inlining_threshold: &str =
790        "either a boolean (`yes`, `no`, `on`, `off`, etc), or a non-negative number";
791    pub(crate) const parse_llvm_module_flag: &str = "<key>:<type>:<value>:<behavior>. Type must currently be `u32`. Behavior should be one of (`error`, `warning`, `require`, `override`, `append`, `appendunique`, `max`, `min`)";
792    pub(crate) const parse_function_return: &str = "`keep` or `thunk-extern`";
793    pub(crate) const parse_wasm_c_abi: &str = "`legacy` or `spec`";
794    pub(crate) const parse_mir_include_spans: &str =
795        "either a boolean (`yes`, `no`, `on`, `off`, etc), or `nll` (default: `nll`)";
796    pub(crate) const parse_align: &str = "a number that is a power of 2 between 1 and 2^29";
797}
798
799pub mod parse {
800    use std::str::FromStr;
801
802    pub(crate) use super::*;
803    pub(crate) const MAX_THREADS_CAP: usize = 256;
804
805    /// This is for boolean options that don't take a value, and are true simply
806    /// by existing on the command-line.
807    ///
808    /// This style of option is deprecated, and is mainly used by old options
809    /// beginning with `no-`.
810    pub(crate) fn parse_no_value(slot: &mut bool, v: Option<&str>) -> bool {
811        match v {
812            None => {
813                *slot = true;
814                true
815            }
816            // Trying to specify a value is always forbidden.
817            Some(_) => false,
818        }
819    }
820
821    /// Use this for any boolean option that has a static default.
822    pub(crate) fn parse_bool(slot: &mut bool, v: Option<&str>) -> bool {
823        match v {
824            Some("y") | Some("yes") | Some("on") | Some("true") | None => {
825                *slot = true;
826                true
827            }
828            Some("n") | Some("no") | Some("off") | Some("false") => {
829                *slot = false;
830                true
831            }
832            _ => false,
833        }
834    }
835
836    /// Use this for any boolean option that lacks a static default. (The
837    /// actions taken when such an option is not specified will depend on
838    /// other factors, such as other options, or target options.)
839    pub(crate) fn parse_opt_bool(slot: &mut Option<bool>, v: Option<&str>) -> bool {
840        match v {
841            Some("y") | Some("yes") | Some("on") | Some("true") | None => {
842                *slot = Some(true);
843                true
844            }
845            Some("n") | Some("no") | Some("off") | Some("false") => {
846                *slot = Some(false);
847                true
848            }
849            _ => false,
850        }
851    }
852
853    /// Parses whether polonius is enabled, and if so, which version.
854    pub(crate) fn parse_polonius(slot: &mut Polonius, v: Option<&str>) -> bool {
855        match v {
856            Some("legacy") | None => {
857                *slot = Polonius::Legacy;
858                true
859            }
860            Some("next") => {
861                *slot = Polonius::Next;
862                true
863            }
864            _ => false,
865        }
866    }
867
868    /// Use this for any string option that has a static default.
869    pub(crate) fn parse_string(slot: &mut String, v: Option<&str>) -> bool {
870        match v {
871            Some(s) => {
872                *slot = s.to_string();
873                true
874            }
875            None => false,
876        }
877    }
878
879    /// Use this for any string option that lacks a static default.
880    pub(crate) fn parse_opt_string(slot: &mut Option<String>, v: Option<&str>) -> bool {
881        match v {
882            Some(s) => {
883                *slot = Some(s.to_string());
884                true
885            }
886            None => false,
887        }
888    }
889
890    /// Parse an optional language identifier, e.g. `en-US` or `zh-CN`.
891    pub(crate) fn parse_opt_langid(slot: &mut Option<LanguageIdentifier>, v: Option<&str>) -> bool {
892        match v {
893            Some(s) => {
894                *slot = rustc_errors::LanguageIdentifier::from_str(s).ok();
895                true
896            }
897            None => false,
898        }
899    }
900
901    pub(crate) fn parse_opt_pathbuf(slot: &mut Option<PathBuf>, v: Option<&str>) -> bool {
902        match v {
903            Some(s) => {
904                *slot = Some(PathBuf::from(s));
905                true
906            }
907            None => false,
908        }
909    }
910
911    pub(crate) fn parse_string_push(slot: &mut Vec<String>, v: Option<&str>) -> bool {
912        match v {
913            Some(s) => {
914                slot.push(s.to_string());
915                true
916            }
917            None => false,
918        }
919    }
920
921    pub(crate) fn parse_list(slot: &mut Vec<String>, v: Option<&str>) -> bool {
922        match v {
923            Some(s) => {
924                slot.extend(s.split_whitespace().map(|s| s.to_string()));
925                true
926            }
927            None => false,
928        }
929    }
930
931    pub(crate) fn parse_list_with_polarity(
932        slot: &mut Vec<(String, bool)>,
933        v: Option<&str>,
934    ) -> bool {
935        match v {
936            Some(s) => {
937                for s in s.split(',') {
938                    let Some(pass_name) = s.strip_prefix(&['+', '-'][..]) else { return false };
939                    slot.push((pass_name.to_string(), &s[..1] == "+"));
940                }
941                true
942            }
943            None => false,
944        }
945    }
946
947    pub(crate) fn parse_fmt_debug(opt: &mut FmtDebug, v: Option<&str>) -> bool {
948        *opt = match v {
949            Some("full") => FmtDebug::Full,
950            Some("shallow") => FmtDebug::Shallow,
951            Some("none") => FmtDebug::None,
952            _ => return false,
953        };
954        true
955    }
956
957    pub(crate) fn parse_location_detail(ld: &mut LocationDetail, v: Option<&str>) -> bool {
958        if let Some(v) = v {
959            ld.line = false;
960            ld.file = false;
961            ld.column = false;
962            if v == "none" {
963                return true;
964            }
965            for s in v.split(',') {
966                match s {
967                    "file" => ld.file = true,
968                    "line" => ld.line = true,
969                    "column" => ld.column = true,
970                    _ => return false,
971                }
972            }
973            true
974        } else {
975            false
976        }
977    }
978
979    pub(crate) fn parse_comma_list(slot: &mut Vec<String>, v: Option<&str>) -> bool {
980        match v {
981            Some(s) => {
982                let mut v: Vec<_> = s.split(',').map(|s| s.to_string()).collect();
983                v.sort_unstable();
984                *slot = v;
985                true
986            }
987            None => false,
988        }
989    }
990
991    pub(crate) fn parse_opt_comma_list(slot: &mut Option<Vec<String>>, v: Option<&str>) -> bool {
992        match v {
993            Some(s) => {
994                let mut v: Vec<_> = s.split(',').map(|s| s.to_string()).collect();
995                v.sort_unstable();
996                *slot = Some(v);
997                true
998            }
999            None => false,
1000        }
1001    }
1002
1003    pub(crate) fn parse_threads(slot: &mut usize, v: Option<&str>) -> bool {
1004        let ret = match v.and_then(|s| s.parse().ok()) {
1005            Some(0) => {
1006                *slot = std::thread::available_parallelism().map_or(1, NonZero::<usize>::get);
1007                true
1008            }
1009            Some(i) => {
1010                *slot = i;
1011                true
1012            }
1013            None => false,
1014        };
1015        // We want to cap the number of threads here to avoid large numbers like 999999 and compiler panics.
1016        // This solution was suggested here https://github.com/rust-lang/rust/issues/117638#issuecomment-1800925067
1017        *slot = slot.clone().min(MAX_THREADS_CAP);
1018        ret
1019    }
1020
1021    /// Use this for any numeric option that has a static default.
1022    pub(crate) fn parse_number<T: Copy + FromStr>(slot: &mut T, v: Option<&str>) -> bool {
1023        match v.and_then(|s| s.parse().ok()) {
1024            Some(i) => {
1025                *slot = i;
1026                true
1027            }
1028            None => false,
1029        }
1030    }
1031
1032    /// Use this for any numeric option that lacks a static default.
1033    pub(crate) fn parse_opt_number<T: Copy + FromStr>(
1034        slot: &mut Option<T>,
1035        v: Option<&str>,
1036    ) -> bool {
1037        match v {
1038            Some(s) => {
1039                *slot = s.parse().ok();
1040                slot.is_some()
1041            }
1042            None => false,
1043        }
1044    }
1045
1046    pub(crate) fn parse_frame_pointer(slot: &mut FramePointer, v: Option<&str>) -> bool {
1047        let mut yes = false;
1048        match v {
1049            _ if parse_bool(&mut yes, v) && yes => slot.ratchet(FramePointer::Always),
1050            _ if parse_bool(&mut yes, v) => slot.ratchet(FramePointer::MayOmit),
1051            Some("always") => slot.ratchet(FramePointer::Always),
1052            Some("non-leaf") => slot.ratchet(FramePointer::NonLeaf),
1053            _ => return false,
1054        };
1055        true
1056    }
1057
1058    pub(crate) fn parse_passes(slot: &mut Passes, v: Option<&str>) -> bool {
1059        match v {
1060            Some("all") => {
1061                *slot = Passes::All;
1062                true
1063            }
1064            v => {
1065                let mut passes = vec![];
1066                if parse_list(&mut passes, v) {
1067                    slot.extend(passes);
1068                    true
1069                } else {
1070                    false
1071                }
1072            }
1073        }
1074    }
1075
1076    pub(crate) fn parse_opt_panic_strategy(
1077        slot: &mut Option<PanicStrategy>,
1078        v: Option<&str>,
1079    ) -> bool {
1080        match v {
1081            Some("unwind") => *slot = Some(PanicStrategy::Unwind),
1082            Some("abort") => *slot = Some(PanicStrategy::Abort),
1083            _ => return false,
1084        }
1085        true
1086    }
1087
1088    pub(crate) fn parse_panic_strategy(slot: &mut PanicStrategy, v: Option<&str>) -> bool {
1089        match v {
1090            Some("unwind") => *slot = PanicStrategy::Unwind,
1091            Some("abort") => *slot = PanicStrategy::Abort,
1092            _ => return false,
1093        }
1094        true
1095    }
1096
1097    pub(crate) fn parse_on_broken_pipe(slot: &mut OnBrokenPipe, v: Option<&str>) -> bool {
1098        match v {
1099            // OnBrokenPipe::Default can't be explicitly specified
1100            Some("kill") => *slot = OnBrokenPipe::Kill,
1101            Some("error") => *slot = OnBrokenPipe::Error,
1102            Some("inherit") => *slot = OnBrokenPipe::Inherit,
1103            _ => return false,
1104        }
1105        true
1106    }
1107
1108    pub(crate) fn parse_patchable_function_entry(
1109        slot: &mut PatchableFunctionEntry,
1110        v: Option<&str>,
1111    ) -> bool {
1112        let mut total_nops = 0;
1113        let mut prefix_nops = 0;
1114
1115        if !parse_number(&mut total_nops, v) {
1116            let parts = v.and_then(|v| v.split_once(',')).unzip();
1117            if !parse_number(&mut total_nops, parts.0) {
1118                return false;
1119            }
1120            if !parse_number(&mut prefix_nops, parts.1) {
1121                return false;
1122            }
1123        }
1124
1125        if let Some(pfe) =
1126            PatchableFunctionEntry::from_total_and_prefix_nops(total_nops, prefix_nops)
1127        {
1128            *slot = pfe;
1129            return true;
1130        }
1131        false
1132    }
1133
1134    pub(crate) fn parse_oom_strategy(slot: &mut OomStrategy, v: Option<&str>) -> bool {
1135        match v {
1136            Some("panic") => *slot = OomStrategy::Panic,
1137            Some("abort") => *slot = OomStrategy::Abort,
1138            _ => return false,
1139        }
1140        true
1141    }
1142
1143    pub(crate) fn parse_relro_level(slot: &mut Option<RelroLevel>, v: Option<&str>) -> bool {
1144        match v {
1145            Some(s) => match s.parse::<RelroLevel>() {
1146                Ok(level) => *slot = Some(level),
1147                _ => return false,
1148            },
1149            _ => return false,
1150        }
1151        true
1152    }
1153
1154    pub(crate) fn parse_sanitizers(slot: &mut SanitizerSet, v: Option<&str>) -> bool {
1155        if let Some(v) = v {
1156            for s in v.split(',') {
1157                *slot |= match s {
1158                    "address" => SanitizerSet::ADDRESS,
1159                    "cfi" => SanitizerSet::CFI,
1160                    "dataflow" => SanitizerSet::DATAFLOW,
1161                    "kcfi" => SanitizerSet::KCFI,
1162                    "kernel-address" => SanitizerSet::KERNELADDRESS,
1163                    "leak" => SanitizerSet::LEAK,
1164                    "memory" => SanitizerSet::MEMORY,
1165                    "memtag" => SanitizerSet::MEMTAG,
1166                    "shadow-call-stack" => SanitizerSet::SHADOWCALLSTACK,
1167                    "thread" => SanitizerSet::THREAD,
1168                    "hwaddress" => SanitizerSet::HWADDRESS,
1169                    "safestack" => SanitizerSet::SAFESTACK,
1170                    _ => return false,
1171                }
1172            }
1173            true
1174        } else {
1175            false
1176        }
1177    }
1178
1179    pub(crate) fn parse_sanitizer_memory_track_origins(slot: &mut usize, v: Option<&str>) -> bool {
1180        match v {
1181            Some("2") | None => {
1182                *slot = 2;
1183                true
1184            }
1185            Some("1") => {
1186                *slot = 1;
1187                true
1188            }
1189            Some("0") => {
1190                *slot = 0;
1191                true
1192            }
1193            Some(_) => false,
1194        }
1195    }
1196
1197    pub(crate) fn parse_strip(slot: &mut Strip, v: Option<&str>) -> bool {
1198        match v {
1199            Some("none") => *slot = Strip::None,
1200            Some("debuginfo") => *slot = Strip::Debuginfo,
1201            Some("symbols") => *slot = Strip::Symbols,
1202            _ => return false,
1203        }
1204        true
1205    }
1206
1207    pub(crate) fn parse_cfguard(slot: &mut CFGuard, v: Option<&str>) -> bool {
1208        if v.is_some() {
1209            let mut bool_arg = None;
1210            if parse_opt_bool(&mut bool_arg, v) {
1211                *slot = if bool_arg.unwrap() { CFGuard::Checks } else { CFGuard::Disabled };
1212                return true;
1213            }
1214        }
1215
1216        *slot = match v {
1217            None => CFGuard::Checks,
1218            Some("checks") => CFGuard::Checks,
1219            Some("nochecks") => CFGuard::NoChecks,
1220            Some(_) => return false,
1221        };
1222        true
1223    }
1224
1225    pub(crate) fn parse_cfprotection(slot: &mut CFProtection, v: Option<&str>) -> bool {
1226        if v.is_some() {
1227            let mut bool_arg = None;
1228            if parse_opt_bool(&mut bool_arg, v) {
1229                *slot = if bool_arg.unwrap() { CFProtection::Full } else { CFProtection::None };
1230                return true;
1231            }
1232        }
1233
1234        *slot = match v {
1235            None | Some("none") => CFProtection::None,
1236            Some("branch") => CFProtection::Branch,
1237            Some("return") => CFProtection::Return,
1238            Some("full") => CFProtection::Full,
1239            Some(_) => return false,
1240        };
1241        true
1242    }
1243
1244    pub(crate) fn parse_debuginfo(slot: &mut DebugInfo, v: Option<&str>) -> bool {
1245        match v {
1246            Some("0") | Some("none") => *slot = DebugInfo::None,
1247            Some("line-directives-only") => *slot = DebugInfo::LineDirectivesOnly,
1248            Some("line-tables-only") => *slot = DebugInfo::LineTablesOnly,
1249            Some("1") | Some("limited") => *slot = DebugInfo::Limited,
1250            Some("2") | Some("full") => *slot = DebugInfo::Full,
1251            _ => return false,
1252        }
1253        true
1254    }
1255
1256    pub(crate) fn parse_debuginfo_compression(
1257        slot: &mut DebugInfoCompression,
1258        v: Option<&str>,
1259    ) -> bool {
1260        match v {
1261            Some("none") => *slot = DebugInfoCompression::None,
1262            Some("zlib") => *slot = DebugInfoCompression::Zlib,
1263            Some("zstd") => *slot = DebugInfoCompression::Zstd,
1264            _ => return false,
1265        };
1266        true
1267    }
1268
1269    pub(crate) fn parse_mir_strip_debuginfo(slot: &mut MirStripDebugInfo, v: Option<&str>) -> bool {
1270        match v {
1271            Some("none") => *slot = MirStripDebugInfo::None,
1272            Some("locals-in-tiny-functions") => *slot = MirStripDebugInfo::LocalsInTinyFunctions,
1273            Some("all-locals") => *slot = MirStripDebugInfo::AllLocals,
1274            _ => return false,
1275        };
1276        true
1277    }
1278
1279    pub(crate) fn parse_linker_flavor(slot: &mut Option<LinkerFlavorCli>, v: Option<&str>) -> bool {
1280        match v.and_then(LinkerFlavorCli::from_str) {
1281            Some(lf) => *slot = Some(lf),
1282            _ => return false,
1283        }
1284        true
1285    }
1286
1287    pub(crate) fn parse_opt_symbol_visibility(
1288        slot: &mut Option<SymbolVisibility>,
1289        v: Option<&str>,
1290    ) -> bool {
1291        if let Some(v) = v {
1292            if let Ok(vis) = SymbolVisibility::from_str(v) {
1293                *slot = Some(vis);
1294            } else {
1295                return false;
1296            }
1297        }
1298        true
1299    }
1300
1301    pub(crate) fn parse_unpretty(slot: &mut Option<String>, v: Option<&str>) -> bool {
1302        match v {
1303            None => false,
1304            Some(s) if s.split('=').count() <= 2 => {
1305                *slot = Some(s.to_string());
1306                true
1307            }
1308            _ => false,
1309        }
1310    }
1311
1312    pub(crate) fn parse_time_passes_format(slot: &mut TimePassesFormat, v: Option<&str>) -> bool {
1313        match v {
1314            None => true,
1315            Some("json") => {
1316                *slot = TimePassesFormat::Json;
1317                true
1318            }
1319            Some("text") => {
1320                *slot = TimePassesFormat::Text;
1321                true
1322            }
1323            Some(_) => false,
1324        }
1325    }
1326
1327    pub(crate) fn parse_dump_mono_stats(slot: &mut DumpMonoStatsFormat, v: Option<&str>) -> bool {
1328        match v {
1329            None => true,
1330            Some("json") => {
1331                *slot = DumpMonoStatsFormat::Json;
1332                true
1333            }
1334            Some("markdown") => {
1335                *slot = DumpMonoStatsFormat::Markdown;
1336                true
1337            }
1338            Some(_) => false,
1339        }
1340    }
1341
1342    pub(crate) fn parse_autodiff(slot: &mut Vec<AutoDiff>, v: Option<&str>) -> bool {
1343        let Some(v) = v else {
1344            *slot = vec![];
1345            return true;
1346        };
1347        let mut v: Vec<&str> = v.split(",").collect();
1348        v.sort_unstable();
1349        for &val in v.iter() {
1350            let variant = match val {
1351                "PrintTA" => AutoDiff::PrintTA,
1352                "PrintAA" => AutoDiff::PrintAA,
1353                "PrintPerf" => AutoDiff::PrintPerf,
1354                "Print" => AutoDiff::Print,
1355                "PrintModBefore" => AutoDiff::PrintModBefore,
1356                "PrintModAfterOpts" => AutoDiff::PrintModAfterOpts,
1357                "PrintModAfterEnzyme" => AutoDiff::PrintModAfterEnzyme,
1358                "LooseTypes" => AutoDiff::LooseTypes,
1359                "NoModOptAfter" => AutoDiff::NoModOptAfter,
1360                "EnableFncOpt" => AutoDiff::EnableFncOpt,
1361                "NoVecUnroll" => AutoDiff::NoVecUnroll,
1362                "Inline" => AutoDiff::Inline,
1363                _ => {
1364                    // FIXME(ZuseZ4): print an error saying which value is not recognized
1365                    return false;
1366                }
1367            };
1368            slot.push(variant);
1369        }
1370
1371        true
1372    }
1373
1374    pub(crate) fn parse_instrument_coverage(
1375        slot: &mut InstrumentCoverage,
1376        v: Option<&str>,
1377    ) -> bool {
1378        if v.is_some() {
1379            let mut bool_arg = false;
1380            if parse_bool(&mut bool_arg, v) {
1381                *slot = if bool_arg { InstrumentCoverage::Yes } else { InstrumentCoverage::No };
1382                return true;
1383            }
1384        }
1385
1386        let Some(v) = v else {
1387            *slot = InstrumentCoverage::Yes;
1388            return true;
1389        };
1390
1391        // Parse values that have historically been accepted by stable compilers,
1392        // even though they're currently just aliases for boolean values.
1393        *slot = match v {
1394            "all" => InstrumentCoverage::Yes,
1395            "0" => InstrumentCoverage::No,
1396            _ => return false,
1397        };
1398        true
1399    }
1400
1401    pub(crate) fn parse_coverage_options(slot: &mut CoverageOptions, v: Option<&str>) -> bool {
1402        let Some(v) = v else { return true };
1403
1404        for option in v.split(',') {
1405            match option {
1406                "block" => slot.level = CoverageLevel::Block,
1407                "branch" => slot.level = CoverageLevel::Branch,
1408                "condition" => slot.level = CoverageLevel::Condition,
1409                "mcdc" => slot.level = CoverageLevel::Mcdc,
1410                "no-mir-spans" => slot.no_mir_spans = true,
1411                "discard-all-spans-in-codegen" => slot.discard_all_spans_in_codegen = true,
1412                _ => return false,
1413            }
1414        }
1415        true
1416    }
1417
1418    pub(crate) fn parse_instrument_xray(
1419        slot: &mut Option<InstrumentXRay>,
1420        v: Option<&str>,
1421    ) -> bool {
1422        if v.is_some() {
1423            let mut bool_arg = None;
1424            if parse_opt_bool(&mut bool_arg, v) {
1425                *slot = if bool_arg.unwrap() { Some(InstrumentXRay::default()) } else { None };
1426                return true;
1427            }
1428        }
1429
1430        let options = slot.get_or_insert_default();
1431        let mut seen_always = false;
1432        let mut seen_never = false;
1433        let mut seen_ignore_loops = false;
1434        let mut seen_instruction_threshold = false;
1435        let mut seen_skip_entry = false;
1436        let mut seen_skip_exit = false;
1437        for option in v.into_iter().flat_map(|v| v.split(',')) {
1438            match option {
1439                "always" if !seen_always && !seen_never => {
1440                    options.always = true;
1441                    options.never = false;
1442                    seen_always = true;
1443                }
1444                "never" if !seen_never && !seen_always => {
1445                    options.never = true;
1446                    options.always = false;
1447                    seen_never = true;
1448                }
1449                "ignore-loops" if !seen_ignore_loops => {
1450                    options.ignore_loops = true;
1451                    seen_ignore_loops = true;
1452                }
1453                option
1454                    if option.starts_with("instruction-threshold")
1455                        && !seen_instruction_threshold =>
1456                {
1457                    let Some(("instruction-threshold", n)) = option.split_once('=') else {
1458                        return false;
1459                    };
1460                    match n.parse() {
1461                        Ok(n) => options.instruction_threshold = Some(n),
1462                        Err(_) => return false,
1463                    }
1464                    seen_instruction_threshold = true;
1465                }
1466                "skip-entry" if !seen_skip_entry => {
1467                    options.skip_entry = true;
1468                    seen_skip_entry = true;
1469                }
1470                "skip-exit" if !seen_skip_exit => {
1471                    options.skip_exit = true;
1472                    seen_skip_exit = true;
1473                }
1474                _ => return false,
1475            }
1476        }
1477        true
1478    }
1479
1480    pub(crate) fn parse_treat_err_as_bug(
1481        slot: &mut Option<NonZero<usize>>,
1482        v: Option<&str>,
1483    ) -> bool {
1484        match v {
1485            Some(s) => match s.parse() {
1486                Ok(val) => {
1487                    *slot = Some(val);
1488                    true
1489                }
1490                Err(e) => {
1491                    *slot = None;
1492                    e.kind() == &IntErrorKind::Zero
1493                }
1494            },
1495            None => {
1496                *slot = NonZero::new(1);
1497                true
1498            }
1499        }
1500    }
1501
1502    pub(crate) fn parse_next_solver_config(slot: &mut NextSolverConfig, v: Option<&str>) -> bool {
1503        if let Some(config) = v {
1504            *slot = match config {
1505                "no" => NextSolverConfig { coherence: false, globally: false },
1506                "coherence" => NextSolverConfig { coherence: true, globally: false },
1507                "globally" => NextSolverConfig { coherence: true, globally: true },
1508                _ => return false,
1509            };
1510        } else {
1511            *slot = NextSolverConfig { coherence: true, globally: true };
1512        }
1513
1514        true
1515    }
1516
1517    pub(crate) fn parse_lto(slot: &mut LtoCli, v: Option<&str>) -> bool {
1518        if v.is_some() {
1519            let mut bool_arg = None;
1520            if parse_opt_bool(&mut bool_arg, v) {
1521                *slot = if bool_arg.unwrap() { LtoCli::Yes } else { LtoCli::No };
1522                return true;
1523            }
1524        }
1525
1526        *slot = match v {
1527            None => LtoCli::NoParam,
1528            Some("thin") => LtoCli::Thin,
1529            Some("fat") => LtoCli::Fat,
1530            Some(_) => return false,
1531        };
1532        true
1533    }
1534
1535    pub(crate) fn parse_linker_plugin_lto(slot: &mut LinkerPluginLto, v: Option<&str>) -> bool {
1536        if v.is_some() {
1537            let mut bool_arg = None;
1538            if parse_opt_bool(&mut bool_arg, v) {
1539                *slot = if bool_arg.unwrap() {
1540                    LinkerPluginLto::LinkerPluginAuto
1541                } else {
1542                    LinkerPluginLto::Disabled
1543                };
1544                return true;
1545            }
1546        }
1547
1548        *slot = match v {
1549            None => LinkerPluginLto::LinkerPluginAuto,
1550            Some(path) => LinkerPluginLto::LinkerPlugin(PathBuf::from(path)),
1551        };
1552        true
1553    }
1554
1555    pub(crate) fn parse_switch_with_opt_path(
1556        slot: &mut SwitchWithOptPath,
1557        v: Option<&str>,
1558    ) -> bool {
1559        *slot = match v {
1560            None => SwitchWithOptPath::Enabled(None),
1561            Some(path) => SwitchWithOptPath::Enabled(Some(PathBuf::from(path))),
1562        };
1563        true
1564    }
1565
1566    pub(crate) fn parse_merge_functions(
1567        slot: &mut Option<MergeFunctions>,
1568        v: Option<&str>,
1569    ) -> bool {
1570        match v.and_then(|s| MergeFunctions::from_str(s).ok()) {
1571            Some(mergefunc) => *slot = Some(mergefunc),
1572            _ => return false,
1573        }
1574        true
1575    }
1576
1577    pub(crate) fn parse_remap_path_scope(
1578        slot: &mut RemapPathScopeComponents,
1579        v: Option<&str>,
1580    ) -> bool {
1581        if let Some(v) = v {
1582            *slot = RemapPathScopeComponents::empty();
1583            for s in v.split(',') {
1584                *slot |= match s {
1585                    "macro" => RemapPathScopeComponents::MACRO,
1586                    "diagnostics" => RemapPathScopeComponents::DIAGNOSTICS,
1587                    "debuginfo" => RemapPathScopeComponents::DEBUGINFO,
1588                    "object" => RemapPathScopeComponents::OBJECT,
1589                    "all" => RemapPathScopeComponents::all(),
1590                    _ => return false,
1591                }
1592            }
1593            true
1594        } else {
1595            false
1596        }
1597    }
1598
1599    pub(crate) fn parse_relocation_model(slot: &mut Option<RelocModel>, v: Option<&str>) -> bool {
1600        match v.and_then(|s| RelocModel::from_str(s).ok()) {
1601            Some(relocation_model) => *slot = Some(relocation_model),
1602            None if v == Some("default") => *slot = None,
1603            _ => return false,
1604        }
1605        true
1606    }
1607
1608    pub(crate) fn parse_code_model(slot: &mut Option<CodeModel>, v: Option<&str>) -> bool {
1609        match v.and_then(|s| CodeModel::from_str(s).ok()) {
1610            Some(code_model) => *slot = Some(code_model),
1611            _ => return false,
1612        }
1613        true
1614    }
1615
1616    pub(crate) fn parse_tls_model(slot: &mut Option<TlsModel>, v: Option<&str>) -> bool {
1617        match v.and_then(|s| TlsModel::from_str(s).ok()) {
1618            Some(tls_model) => *slot = Some(tls_model),
1619            _ => return false,
1620        }
1621        true
1622    }
1623
1624    pub(crate) fn parse_terminal_url(slot: &mut TerminalUrl, v: Option<&str>) -> bool {
1625        *slot = match v {
1626            Some("on" | "" | "yes" | "y") | None => TerminalUrl::Yes,
1627            Some("off" | "no" | "n") => TerminalUrl::No,
1628            Some("auto") => TerminalUrl::Auto,
1629            _ => return false,
1630        };
1631        true
1632    }
1633
1634    pub(crate) fn parse_symbol_mangling_version(
1635        slot: &mut Option<SymbolManglingVersion>,
1636        v: Option<&str>,
1637    ) -> bool {
1638        *slot = match v {
1639            Some("legacy") => Some(SymbolManglingVersion::Legacy),
1640            Some("v0") => Some(SymbolManglingVersion::V0),
1641            Some("hashed") => Some(SymbolManglingVersion::Hashed),
1642            _ => return false,
1643        };
1644        true
1645    }
1646
1647    pub(crate) fn parse_src_file_hash(
1648        slot: &mut Option<SourceFileHashAlgorithm>,
1649        v: Option<&str>,
1650    ) -> bool {
1651        match v.and_then(|s| SourceFileHashAlgorithm::from_str(s).ok()) {
1652            Some(hash_kind) => *slot = Some(hash_kind),
1653            _ => return false,
1654        }
1655        true
1656    }
1657
1658    pub(crate) fn parse_cargo_src_file_hash(
1659        slot: &mut Option<SourceFileHashAlgorithm>,
1660        v: Option<&str>,
1661    ) -> bool {
1662        match v.and_then(|s| SourceFileHashAlgorithm::from_str(s).ok()) {
1663            Some(hash_kind) => {
1664                *slot = Some(hash_kind);
1665            }
1666            _ => return false,
1667        }
1668        true
1669    }
1670
1671    pub(crate) fn parse_target_feature(slot: &mut String, v: Option<&str>) -> bool {
1672        match v {
1673            Some(s) => {
1674                if !slot.is_empty() {
1675                    slot.push(',');
1676                }
1677                slot.push_str(s);
1678                true
1679            }
1680            None => false,
1681        }
1682    }
1683
1684    pub(crate) fn parse_link_self_contained(slot: &mut LinkSelfContained, v: Option<&str>) -> bool {
1685        // Whenever `-C link-self-contained` is passed without a value, it's an opt-in
1686        // just like `parse_opt_bool`, the historical value of this flag.
1687        //
1688        // 1. Parse historical single bool values
1689        let s = v.unwrap_or("y");
1690        match s {
1691            "y" | "yes" | "on" => {
1692                slot.set_all_explicitly(true);
1693                return true;
1694            }
1695            "n" | "no" | "off" => {
1696                slot.set_all_explicitly(false);
1697                return true;
1698            }
1699            _ => {}
1700        }
1701
1702        // 2. Parse a list of enabled and disabled components.
1703        for comp in s.split(',') {
1704            if slot.handle_cli_component(comp).is_none() {
1705                return false;
1706            }
1707        }
1708
1709        true
1710    }
1711
1712    /// Parse a comma-separated list of enabled and disabled linker features.
1713    pub(crate) fn parse_linker_features(slot: &mut LinkerFeaturesCli, v: Option<&str>) -> bool {
1714        match v {
1715            Some(s) => {
1716                for feature in s.split(',') {
1717                    if slot.handle_cli_feature(feature).is_none() {
1718                        return false;
1719                    }
1720                }
1721
1722                true
1723            }
1724            None => false,
1725        }
1726    }
1727
1728    pub(crate) fn parse_wasi_exec_model(slot: &mut Option<WasiExecModel>, v: Option<&str>) -> bool {
1729        match v {
1730            Some("command") => *slot = Some(WasiExecModel::Command),
1731            Some("reactor") => *slot = Some(WasiExecModel::Reactor),
1732            _ => return false,
1733        }
1734        true
1735    }
1736
1737    pub(crate) fn parse_split_debuginfo(
1738        slot: &mut Option<SplitDebuginfo>,
1739        v: Option<&str>,
1740    ) -> bool {
1741        match v.and_then(|s| SplitDebuginfo::from_str(s).ok()) {
1742            Some(e) => *slot = Some(e),
1743            _ => return false,
1744        }
1745        true
1746    }
1747
1748    pub(crate) fn parse_split_dwarf_kind(slot: &mut SplitDwarfKind, v: Option<&str>) -> bool {
1749        match v.and_then(|s| SplitDwarfKind::from_str(s).ok()) {
1750            Some(e) => *slot = e,
1751            _ => return false,
1752        }
1753        true
1754    }
1755
1756    pub(crate) fn parse_stack_protector(slot: &mut StackProtector, v: Option<&str>) -> bool {
1757        match v.and_then(|s| StackProtector::from_str(s).ok()) {
1758            Some(ssp) => *slot = ssp,
1759            _ => return false,
1760        }
1761        true
1762    }
1763
1764    pub(crate) fn parse_branch_protection(
1765        slot: &mut Option<BranchProtection>,
1766        v: Option<&str>,
1767    ) -> bool {
1768        match v {
1769            Some(s) => {
1770                let slot = slot.get_or_insert_default();
1771                for opt in s.split(',') {
1772                    match opt {
1773                        "bti" => slot.bti = true,
1774                        "pac-ret" if slot.pac_ret.is_none() => {
1775                            slot.pac_ret = Some(PacRet { leaf: false, pc: false, key: PAuthKey::A })
1776                        }
1777                        "leaf" => match slot.pac_ret.as_mut() {
1778                            Some(pac) => pac.leaf = true,
1779                            _ => return false,
1780                        },
1781                        "b-key" => match slot.pac_ret.as_mut() {
1782                            Some(pac) => pac.key = PAuthKey::B,
1783                            _ => return false,
1784                        },
1785                        "pc" => match slot.pac_ret.as_mut() {
1786                            Some(pac) => pac.pc = true,
1787                            _ => return false,
1788                        },
1789                        _ => return false,
1790                    };
1791                }
1792            }
1793            _ => return false,
1794        }
1795        true
1796    }
1797
1798    pub(crate) fn parse_collapse_macro_debuginfo(
1799        slot: &mut CollapseMacroDebuginfo,
1800        v: Option<&str>,
1801    ) -> bool {
1802        if v.is_some() {
1803            let mut bool_arg = None;
1804            if parse_opt_bool(&mut bool_arg, v) {
1805                *slot = if bool_arg.unwrap() {
1806                    CollapseMacroDebuginfo::Yes
1807                } else {
1808                    CollapseMacroDebuginfo::No
1809                };
1810                return true;
1811            }
1812        }
1813
1814        *slot = match v {
1815            Some("external") => CollapseMacroDebuginfo::External,
1816            _ => return false,
1817        };
1818        true
1819    }
1820
1821    pub(crate) fn parse_proc_macro_execution_strategy(
1822        slot: &mut ProcMacroExecutionStrategy,
1823        v: Option<&str>,
1824    ) -> bool {
1825        *slot = match v {
1826            Some("same-thread") => ProcMacroExecutionStrategy::SameThread,
1827            Some("cross-thread") => ProcMacroExecutionStrategy::CrossThread,
1828            _ => return false,
1829        };
1830        true
1831    }
1832
1833    pub(crate) fn parse_inlining_threshold(slot: &mut InliningThreshold, v: Option<&str>) -> bool {
1834        match v {
1835            Some("always" | "yes") => {
1836                *slot = InliningThreshold::Always;
1837            }
1838            Some("never") => {
1839                *slot = InliningThreshold::Never;
1840            }
1841            Some(v) => {
1842                if let Ok(threshold) = v.parse() {
1843                    *slot = InliningThreshold::Sometimes(threshold);
1844                } else {
1845                    return false;
1846                }
1847            }
1848            None => return false,
1849        }
1850        true
1851    }
1852
1853    pub(crate) fn parse_llvm_module_flag(
1854        slot: &mut Vec<(String, u32, String)>,
1855        v: Option<&str>,
1856    ) -> bool {
1857        let elements = v.unwrap_or_default().split(':').collect::<Vec<_>>();
1858        let [key, md_type, value, behavior] = elements.as_slice() else {
1859            return false;
1860        };
1861        if *md_type != "u32" {
1862            // Currently we only support u32 metadata flags, but require the
1863            // type for forward-compatibility.
1864            return false;
1865        }
1866        let Ok(value) = value.parse::<u32>() else {
1867            return false;
1868        };
1869        let behavior = behavior.to_lowercase();
1870        let all_behaviors =
1871            ["error", "warning", "require", "override", "append", "appendunique", "max", "min"];
1872        if !all_behaviors.contains(&behavior.as_str()) {
1873            return false;
1874        }
1875
1876        slot.push((key.to_string(), value, behavior));
1877        true
1878    }
1879
1880    pub(crate) fn parse_function_return(slot: &mut FunctionReturn, v: Option<&str>) -> bool {
1881        match v {
1882            Some("keep") => *slot = FunctionReturn::Keep,
1883            Some("thunk-extern") => *slot = FunctionReturn::ThunkExtern,
1884            _ => return false,
1885        }
1886        true
1887    }
1888
1889    pub(crate) fn parse_wasm_c_abi(slot: &mut WasmCAbi, v: Option<&str>) -> bool {
1890        match v {
1891            Some("spec") => *slot = WasmCAbi::Spec,
1892            Some("legacy") => *slot = WasmCAbi::Legacy,
1893            _ => return false,
1894        }
1895        true
1896    }
1897
1898    pub(crate) fn parse_mir_include_spans(slot: &mut MirIncludeSpans, v: Option<&str>) -> bool {
1899        *slot = match v {
1900            Some("on" | "yes" | "y" | "true") | None => MirIncludeSpans::On,
1901            Some("off" | "no" | "n" | "false") => MirIncludeSpans::Off,
1902            Some("nll") => MirIncludeSpans::Nll,
1903            _ => return false,
1904        };
1905
1906        true
1907    }
1908
1909    pub(crate) fn parse_align(slot: &mut Option<Align>, v: Option<&str>) -> bool {
1910        let mut bytes = 0u64;
1911        if !parse_number(&mut bytes, v) {
1912            return false;
1913        }
1914
1915        let Ok(align) = Align::from_bytes(bytes) else {
1916            return false;
1917        };
1918
1919        *slot = Some(align);
1920
1921        true
1922    }
1923}
1924
1925options! {
1926    CodegenOptions, CodegenOptionsTargetModifiers, CG_OPTIONS, cgopts, "C", "codegen",
1927
1928    // If you add a new option, please update:
1929    // - compiler/rustc_interface/src/tests.rs
1930    // - src/doc/rustc/src/codegen-options/index.md
1931
1932    // tidy-alphabetical-start
1933    #[rustc_lint_opt_deny_field_access("documented to do nothing")]
1934    ar: String = (String::new(), parse_string, [UNTRACKED],
1935        "this option is deprecated and does nothing",
1936        deprecated_do_nothing: true),
1937    #[rustc_lint_opt_deny_field_access("use `Session::code_model` instead of this field")]
1938    code_model: Option<CodeModel> = (None, parse_code_model, [TRACKED],
1939        "choose the code model to use (`rustc --print code-models` for details)"),
1940    codegen_units: Option<usize> = (None, parse_opt_number, [UNTRACKED],
1941        "divide crate into N units to optimize in parallel"),
1942    collapse_macro_debuginfo: CollapseMacroDebuginfo = (CollapseMacroDebuginfo::Unspecified,
1943        parse_collapse_macro_debuginfo, [TRACKED],
1944        "set option to collapse debuginfo for macros"),
1945    control_flow_guard: CFGuard = (CFGuard::Disabled, parse_cfguard, [TRACKED],
1946        "use Windows Control Flow Guard (default: no)"),
1947    debug_assertions: Option<bool> = (None, parse_opt_bool, [TRACKED],
1948        "explicitly enable the `cfg(debug_assertions)` directive"),
1949    debuginfo: DebugInfo = (DebugInfo::None, parse_debuginfo, [TRACKED],
1950        "debug info emission level (0-2, none, line-directives-only, \
1951        line-tables-only, limited, or full; default: 0)"),
1952    default_linker_libraries: bool = (false, parse_bool, [UNTRACKED],
1953        "allow the linker to link its default libraries (default: no)"),
1954    dlltool: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
1955        "import library generation tool (ignored except when targeting windows-gnu)"),
1956    embed_bitcode: bool = (true, parse_bool, [TRACKED],
1957        "emit bitcode in rlibs (default: yes)"),
1958    extra_filename: String = (String::new(), parse_string, [UNTRACKED],
1959        "extra data to put in each output filename"),
1960    force_frame_pointers: FramePointer = (FramePointer::MayOmit, parse_frame_pointer, [TRACKED],
1961        "force use of the frame pointers"),
1962    #[rustc_lint_opt_deny_field_access("use `Session::must_emit_unwind_tables` instead of this field")]
1963    force_unwind_tables: Option<bool> = (None, parse_opt_bool, [TRACKED],
1964        "force use of unwind tables"),
1965    incremental: Option<String> = (None, parse_opt_string, [UNTRACKED],
1966        "enable incremental compilation"),
1967    #[rustc_lint_opt_deny_field_access("documented to do nothing")]
1968    inline_threshold: Option<u32> = (None, parse_opt_number, [UNTRACKED],
1969        "this option is deprecated and does nothing \
1970        (consider using `-Cllvm-args=--inline-threshold=...`)",
1971        deprecated_do_nothing: true),
1972    #[rustc_lint_opt_deny_field_access("use `Session::instrument_coverage` instead of this field")]
1973    instrument_coverage: InstrumentCoverage = (InstrumentCoverage::No, parse_instrument_coverage, [TRACKED],
1974        "instrument the generated code to support LLVM source-based code coverage reports \
1975        (note, the compiler build config must include `profiler = true`); \
1976        implies `-C symbol-mangling-version=v0`"),
1977    link_arg: (/* redirected to link_args */) = ((), parse_string_push, [UNTRACKED],
1978        "a single extra argument to append to the linker invocation (can be used several times)"),
1979    link_args: Vec<String> = (Vec::new(), parse_list, [UNTRACKED],
1980        "extra arguments to append to the linker invocation (space separated)"),
1981    #[rustc_lint_opt_deny_field_access("use `Session::link_dead_code` instead of this field")]
1982    link_dead_code: Option<bool> = (None, parse_opt_bool, [TRACKED],
1983        "try to generate and link dead code (default: no)"),
1984    link_self_contained: LinkSelfContained = (LinkSelfContained::default(), parse_link_self_contained, [UNTRACKED],
1985        "control whether to link Rust provided C objects/libraries or rely \
1986        on a C toolchain or linker installed in the system"),
1987    linker: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
1988        "system linker to link outputs with"),
1989    linker_flavor: Option<LinkerFlavorCli> = (None, parse_linker_flavor, [UNTRACKED],
1990        "linker flavor"),
1991    linker_plugin_lto: LinkerPluginLto = (LinkerPluginLto::Disabled,
1992        parse_linker_plugin_lto, [TRACKED],
1993        "generate build artifacts that are compatible with linker-based LTO"),
1994    llvm_args: Vec<String> = (Vec::new(), parse_list, [TRACKED],
1995        "a list of arguments to pass to LLVM (space separated)"),
1996    #[rustc_lint_opt_deny_field_access("use `Session::lto` instead of this field")]
1997    lto: LtoCli = (LtoCli::Unspecified, parse_lto, [TRACKED],
1998        "perform LLVM link-time optimizations"),
1999    metadata: Vec<String> = (Vec::new(), parse_list, [TRACKED],
2000        "metadata to mangle symbol names with"),
2001    no_prepopulate_passes: bool = (false, parse_no_value, [TRACKED],
2002        "give an empty list of passes to the pass manager"),
2003    no_redzone: Option<bool> = (None, parse_opt_bool, [TRACKED],
2004        "disable the use of the redzone"),
2005    #[rustc_lint_opt_deny_field_access("documented to do nothing")]
2006    no_stack_check: bool = (false, parse_no_value, [UNTRACKED],
2007        "this option is deprecated and does nothing",
2008        deprecated_do_nothing: true),
2009    no_vectorize_loops: bool = (false, parse_no_value, [TRACKED],
2010        "disable loop vectorization optimization passes"),
2011    no_vectorize_slp: bool = (false, parse_no_value, [TRACKED],
2012        "disable LLVM's SLP vectorization pass"),
2013    opt_level: String = ("0".to_string(), parse_string, [TRACKED],
2014        "optimization level (0-3, s, or z; default: 0)"),
2015    #[rustc_lint_opt_deny_field_access("use `Session::overflow_checks` instead of this field")]
2016    overflow_checks: Option<bool> = (None, parse_opt_bool, [TRACKED],
2017        "use overflow checks for integer arithmetic"),
2018    #[rustc_lint_opt_deny_field_access("use `Session::panic_strategy` instead of this field")]
2019    panic: Option<PanicStrategy> = (None, parse_opt_panic_strategy, [TRACKED],
2020        "panic strategy to compile crate with"),
2021    passes: Vec<String> = (Vec::new(), parse_list, [TRACKED],
2022        "a list of extra LLVM passes to run (space separated)"),
2023    prefer_dynamic: bool = (false, parse_bool, [TRACKED],
2024        "prefer dynamic linking to static linking (default: no)"),
2025    profile_generate: SwitchWithOptPath = (SwitchWithOptPath::Disabled,
2026        parse_switch_with_opt_path, [TRACKED],
2027        "compile the program with profiling instrumentation"),
2028    profile_use: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
2029        "use the given `.profdata` file for profile-guided optimization"),
2030    #[rustc_lint_opt_deny_field_access("use `Session::relocation_model` instead of this field")]
2031    relocation_model: Option<RelocModel> = (None, parse_relocation_model, [TRACKED],
2032        "control generation of position-independent code (PIC) \
2033        (`rustc --print relocation-models` for details)"),
2034    relro_level: Option<RelroLevel> = (None, parse_relro_level, [TRACKED],
2035        "choose which RELRO level to use"),
2036    remark: Passes = (Passes::Some(Vec::new()), parse_passes, [UNTRACKED],
2037        "output remarks for these optimization passes (space separated, or \"all\")"),
2038    rpath: bool = (false, parse_bool, [UNTRACKED],
2039        "set rpath values in libs/exes (default: no)"),
2040    save_temps: bool = (false, parse_bool, [UNTRACKED],
2041        "save all temporary output files during compilation (default: no)"),
2042    soft_float: bool = (false, parse_bool, [TRACKED],
2043        "deprecated option: use soft float ABI (*eabihf targets only) (default: no)"),
2044    #[rustc_lint_opt_deny_field_access("use `Session::split_debuginfo` instead of this field")]
2045    split_debuginfo: Option<SplitDebuginfo> = (None, parse_split_debuginfo, [TRACKED],
2046        "how to handle split-debuginfo, a platform-specific option"),
2047    strip: Strip = (Strip::None, parse_strip, [UNTRACKED],
2048        "tell the linker which information to strip (`none` (default), `debuginfo` or `symbols`)"),
2049    symbol_mangling_version: Option<SymbolManglingVersion> = (None,
2050        parse_symbol_mangling_version, [TRACKED],
2051        "which mangling version to use for symbol names ('legacy' (default), 'v0', or 'hashed')"),
2052    target_cpu: Option<String> = (None, parse_opt_string, [TRACKED],
2053        "select target processor (`rustc --print target-cpus` for details)"),
2054    target_feature: String = (String::new(), parse_target_feature, [TRACKED],
2055        "target specific attributes. (`rustc --print target-features` for details). \
2056        This feature is unsafe."),
2057    unsafe_allow_abi_mismatch: Vec<String> = (Vec::new(), parse_comma_list, [UNTRACKED],
2058        "Allow incompatible target modifiers in dependency crates (comma separated list)"),
2059    // tidy-alphabetical-end
2060
2061    // If you add a new option, please update:
2062    // - compiler/rustc_interface/src/tests.rs
2063    // - src/doc/rustc/src/codegen-options/index.md
2064}
2065
2066options! {
2067    UnstableOptions, UnstableOptionsTargetModifiers, Z_OPTIONS, dbopts, "Z", "unstable",
2068
2069    // If you add a new option, please update:
2070    // - compiler/rustc_interface/src/tests.rs
2071    // - src/doc/unstable-book/src/compiler-flags
2072
2073    // tidy-alphabetical-start
2074    allow_features: Option<Vec<String>> = (None, parse_opt_comma_list, [TRACKED],
2075        "only allow the listed language features to be enabled in code (comma separated)"),
2076    always_encode_mir: bool = (false, parse_bool, [TRACKED],
2077        "encode MIR of all functions into the crate metadata (default: no)"),
2078    assert_incr_state: Option<String> = (None, parse_opt_string, [UNTRACKED],
2079        "assert that the incremental cache is in given state: \
2080         either `loaded` or `not-loaded`."),
2081    assume_incomplete_release: bool = (false, parse_bool, [TRACKED],
2082        "make cfg(version) treat the current version as incomplete (default: no)"),
2083    autodiff: Vec<crate::config::AutoDiff> = (Vec::new(), parse_autodiff, [TRACKED],
2084        "a list of optional autodiff flags to enable
2085         Optional extra settings:
2086         `=PrintTA`
2087         `=PrintAA`
2088         `=PrintPerf`
2089         `=Print`
2090         `=PrintModBefore`
2091         `=PrintModAfterOpts`
2092         `=PrintModAfterEnzyme`
2093         `=LooseTypes`
2094         `=NoModOptAfter`
2095         `=EnableFncOpt`
2096         `=NoVecUnroll`
2097         `=Inline`
2098         Multiple options can be combined with commas."),
2099    #[rustc_lint_opt_deny_field_access("use `Session::binary_dep_depinfo` instead of this field")]
2100    binary_dep_depinfo: bool = (false, parse_bool, [TRACKED],
2101        "include artifacts (sysroot, crate dependencies) used during compilation in dep-info \
2102        (default: no)"),
2103    box_noalias: bool = (true, parse_bool, [TRACKED],
2104        "emit noalias metadata for box (default: yes)"),
2105    branch_protection: Option<BranchProtection> = (None, parse_branch_protection, [TRACKED],
2106        "set options for branch target identification and pointer authentication on AArch64"),
2107    cf_protection: CFProtection = (CFProtection::None, parse_cfprotection, [TRACKED],
2108        "instrument control-flow architecture protection"),
2109    check_cfg_all_expected: bool = (false, parse_bool, [UNTRACKED],
2110        "show all expected values in check-cfg diagnostics (default: no)"),
2111    checksum_hash_algorithm: Option<SourceFileHashAlgorithm> = (None, parse_cargo_src_file_hash, [TRACKED],
2112        "hash algorithm of source files used to check freshness in cargo (`blake3` or `sha256`)"),
2113    codegen_backend: Option<String> = (None, parse_opt_string, [TRACKED],
2114        "the backend to use"),
2115    combine_cgu: bool = (false, parse_bool, [TRACKED],
2116        "combine CGUs into a single one"),
2117    contract_checks: Option<bool> = (None, parse_opt_bool, [TRACKED],
2118        "emit runtime checks for contract pre- and post-conditions (default: no)"),
2119    coverage_options: CoverageOptions = (CoverageOptions::default(), parse_coverage_options, [TRACKED],
2120        "control details of coverage instrumentation"),
2121    crate_attr: Vec<String> = (Vec::new(), parse_string_push, [TRACKED],
2122        "inject the given attribute in the crate"),
2123    cross_crate_inline_threshold: InliningThreshold = (InliningThreshold::Sometimes(100), parse_inlining_threshold, [TRACKED],
2124        "threshold to allow cross crate inlining of functions"),
2125    debug_info_for_profiling: bool = (false, parse_bool, [TRACKED],
2126        "emit discriminators and other data necessary for AutoFDO"),
2127    debug_info_type_line_numbers: bool = (false, parse_bool, [TRACKED],
2128        "emit type and line information for additional data types (default: no)"),
2129    debuginfo_compression: DebugInfoCompression = (DebugInfoCompression::None, parse_debuginfo_compression, [TRACKED],
2130        "compress debug info sections (none, zlib, zstd, default: none)"),
2131    deduplicate_diagnostics: bool = (true, parse_bool, [UNTRACKED],
2132        "deduplicate identical diagnostics (default: yes)"),
2133    default_visibility: Option<SymbolVisibility> = (None, parse_opt_symbol_visibility, [TRACKED],
2134        "overrides the `default_visibility` setting of the target"),
2135    dep_info_omit_d_target: bool = (false, parse_bool, [TRACKED],
2136        "in dep-info output, omit targets for tracking dependencies of the dep-info files \
2137        themselves (default: no)"),
2138    direct_access_external_data: Option<bool> = (None, parse_opt_bool, [TRACKED],
2139        "Direct or use GOT indirect to reference external data symbols"),
2140    dual_proc_macros: bool = (false, parse_bool, [TRACKED],
2141        "load proc macros for both target and host, but only link to the target (default: no)"),
2142    dump_dep_graph: bool = (false, parse_bool, [UNTRACKED],
2143        "dump the dependency graph to $RUST_DEP_GRAPH (default: /tmp/dep_graph.gv) \
2144        (default: no)"),
2145    dump_mir: Option<String> = (None, parse_opt_string, [UNTRACKED],
2146        "dump MIR state to file.
2147        `val` is used to select which passes and functions to dump. For example:
2148        `all` matches all passes and functions,
2149        `foo` matches all passes for functions whose name contains 'foo',
2150        `foo & ConstProp` only the 'ConstProp' pass for function names containing 'foo',
2151        `foo | bar` all passes for function names containing 'foo' or 'bar'."),
2152    dump_mir_dataflow: bool = (false, parse_bool, [UNTRACKED],
2153        "in addition to `.mir` files, create graphviz `.dot` files with dataflow results \
2154        (default: no)"),
2155    dump_mir_dir: String = ("mir_dump".to_string(), parse_string, [UNTRACKED],
2156        "the directory the MIR is dumped into (default: `mir_dump`)"),
2157    dump_mir_exclude_alloc_bytes: bool = (false, parse_bool, [UNTRACKED],
2158        "exclude the raw bytes of allocations when dumping MIR (used in tests) (default: no)"),
2159    dump_mir_exclude_pass_number: bool = (false, parse_bool, [UNTRACKED],
2160        "exclude the pass number when dumping MIR (used in tests) (default: no)"),
2161    dump_mir_graphviz: bool = (false, parse_bool, [UNTRACKED],
2162        "in addition to `.mir` files, create graphviz `.dot` files (default: no)"),
2163    dump_mono_stats: SwitchWithOptPath = (SwitchWithOptPath::Disabled,
2164        parse_switch_with_opt_path, [UNTRACKED],
2165        "output statistics about monomorphization collection"),
2166    dump_mono_stats_format: DumpMonoStatsFormat = (DumpMonoStatsFormat::Markdown, parse_dump_mono_stats, [UNTRACKED],
2167        "the format to use for -Z dump-mono-stats (`markdown` (default) or `json`)"),
2168    #[rustc_lint_opt_deny_field_access("use `Session::dwarf_version` instead of this field")]
2169    dwarf_version: Option<u32> = (None, parse_opt_number, [TRACKED],
2170        "version of DWARF debug information to emit (default: 2 or 4, depending on platform)"),
2171    dylib_lto: bool = (false, parse_bool, [UNTRACKED],
2172        "enables LTO for dylib crate type"),
2173    eagerly_emit_delayed_bugs: bool = (false, parse_bool, [UNTRACKED],
2174        "emit delayed bugs eagerly as errors instead of stashing them and emitting \
2175        them only if an error has not been emitted"),
2176    ehcont_guard: bool = (false, parse_bool, [TRACKED],
2177        "generate Windows EHCont Guard tables"),
2178    embed_source: bool = (false, parse_bool, [TRACKED],
2179        "embed source text in DWARF debug sections (default: no)"),
2180    emit_stack_sizes: bool = (false, parse_bool, [UNTRACKED],
2181        "emit a section containing stack size metadata (default: no)"),
2182    emit_thin_lto: bool = (true, parse_bool, [TRACKED],
2183        "emit the bc module with thin LTO info (default: yes)"),
2184    emscripten_wasm_eh: bool = (false, parse_bool, [TRACKED],
2185        "Use WebAssembly error handling for wasm32-unknown-emscripten"),
2186    enforce_type_length_limit: bool = (false, parse_bool, [TRACKED],
2187        "enforce the type length limit when monomorphizing instances in codegen"),
2188    export_executable_symbols: bool = (false, parse_bool, [TRACKED],
2189        "export symbols from executables, as if they were dynamic libraries"),
2190    external_clangrt: bool = (false, parse_bool, [UNTRACKED],
2191        "rely on user specified linker commands to find clangrt"),
2192    extra_const_ub_checks: bool = (false, parse_bool, [TRACKED],
2193        "turns on more checks to detect const UB, which can be slow (default: no)"),
2194    #[rustc_lint_opt_deny_field_access("use `Session::fewer_names` instead of this field")]
2195    fewer_names: Option<bool> = (None, parse_opt_bool, [TRACKED],
2196        "reduce memory use by retaining fewer names within compilation artifacts (LLVM-IR) \
2197        (default: no)"),
2198    fixed_x18: bool = (false, parse_bool, [TRACKED],
2199        "make the x18 register reserved on AArch64 (default: no)"),
2200    flatten_format_args: bool = (true, parse_bool, [TRACKED],
2201        "flatten nested format_args!() and literals into a simplified format_args!() call \
2202        (default: yes)"),
2203    fmt_debug: FmtDebug = (FmtDebug::Full, parse_fmt_debug, [TRACKED],
2204        "how detailed `#[derive(Debug)]` should be. `full` prints types recursively, \
2205        `shallow` prints only type names, `none` prints nothing and disables `{:?}`. (default: `full`)"),
2206    force_unstable_if_unmarked: bool = (false, parse_bool, [TRACKED],
2207        "force all crates to be `rustc_private` unstable (default: no)"),
2208    function_return: FunctionReturn = (FunctionReturn::default(), parse_function_return, [TRACKED],
2209        "replace returns with jumps to `__x86_return_thunk` (default: `keep`)"),
2210    function_sections: Option<bool> = (None, parse_opt_bool, [TRACKED],
2211        "whether each function should go in its own section"),
2212    future_incompat_test: bool = (false, parse_bool, [UNTRACKED],
2213        "forces all lints to be future incompatible, used for internal testing (default: no)"),
2214    graphviz_dark_mode: bool = (false, parse_bool, [UNTRACKED],
2215        "use dark-themed colors in graphviz output (default: no)"),
2216    graphviz_font: String = ("Courier, monospace".to_string(), parse_string, [UNTRACKED],
2217        "use the given `fontname` in graphviz output; can be overridden by setting \
2218        environment variable `RUSTC_GRAPHVIZ_FONT` (default: `Courier, monospace`)"),
2219    has_thread_local: Option<bool> = (None, parse_opt_bool, [TRACKED],
2220        "explicitly enable the `cfg(target_thread_local)` directive"),
2221    human_readable_cgu_names: bool = (false, parse_bool, [TRACKED],
2222        "generate human-readable, predictable names for codegen units (default: no)"),
2223    identify_regions: bool = (false, parse_bool, [UNTRACKED],
2224        "display unnamed regions as `'<id>`, using a non-ident unique id (default: no)"),
2225    ignore_directory_in_diagnostics_source_blocks: Vec<String> = (Vec::new(), parse_string_push, [UNTRACKED],
2226        "do not display the source code block in diagnostics for files in the directory"),
2227    incremental_ignore_spans: bool = (false, parse_bool, [TRACKED],
2228        "ignore spans during ICH computation -- used for testing (default: no)"),
2229    incremental_info: bool = (false, parse_bool, [UNTRACKED],
2230        "print high-level information about incremental reuse (or the lack thereof) \
2231        (default: no)"),
2232    incremental_verify_ich: bool = (false, parse_bool, [UNTRACKED],
2233        "verify extended properties for incr. comp. (default: no):
2234        - hashes of green query instances
2235        - hash collisions of query keys"),
2236    inline_llvm: bool = (true, parse_bool, [TRACKED],
2237        "enable LLVM inlining (default: yes)"),
2238    inline_mir: Option<bool> = (None, parse_opt_bool, [TRACKED],
2239        "enable MIR inlining (default: no)"),
2240    inline_mir_forwarder_threshold: Option<usize> = (None, parse_opt_number, [TRACKED],
2241        "inlining threshold when the caller is a simple forwarding function (default: 30)"),
2242    inline_mir_hint_threshold: Option<usize> = (None, parse_opt_number, [TRACKED],
2243        "inlining threshold for functions with inline hint (default: 100)"),
2244    inline_mir_preserve_debug: Option<bool> = (None, parse_opt_bool, [TRACKED],
2245        "when MIR inlining, whether to preserve debug info for callee variables \
2246        (default: preserve for debuginfo != None, otherwise remove)"),
2247    inline_mir_threshold: Option<usize> = (None, parse_opt_number, [TRACKED],
2248        "a default MIR inlining threshold (default: 50)"),
2249    input_stats: bool = (false, parse_bool, [UNTRACKED],
2250        "print some statistics about AST and HIR (default: no)"),
2251    instrument_mcount: bool = (false, parse_bool, [TRACKED],
2252        "insert function instrument code for mcount-based tracing (default: no)"),
2253    instrument_xray: Option<InstrumentXRay> = (None, parse_instrument_xray, [TRACKED],
2254        "insert function instrument code for XRay-based tracing (default: no)
2255         Optional extra settings:
2256         `=always`
2257         `=never`
2258         `=ignore-loops`
2259         `=instruction-threshold=N`
2260         `=skip-entry`
2261         `=skip-exit`
2262         Multiple options can be combined with commas."),
2263    layout_seed: Option<u64> = (None, parse_opt_number, [TRACKED],
2264        "seed layout randomization"),
2265    link_directives: bool = (true, parse_bool, [TRACKED],
2266        "honor #[link] directives in the compiled crate (default: yes)"),
2267    link_native_libraries: bool = (true, parse_bool, [UNTRACKED],
2268        "link native libraries in the linker invocation (default: yes)"),
2269    link_only: bool = (false, parse_bool, [TRACKED],
2270        "link the `.rlink` file generated by `-Z no-link` (default: no)"),
2271    linker_features: LinkerFeaturesCli = (LinkerFeaturesCli::default(), parse_linker_features, [UNTRACKED],
2272        "a comma-separated list of linker features to enable (+) or disable (-): `lld`"),
2273    lint_llvm_ir: bool = (false, parse_bool, [TRACKED],
2274        "lint LLVM IR (default: no)"),
2275    lint_mir: bool = (false, parse_bool, [UNTRACKED],
2276        "lint MIR before and after each transformation"),
2277    llvm_module_flag: Vec<(String, u32, String)> = (Vec::new(), parse_llvm_module_flag, [TRACKED],
2278        "a list of module flags to pass to LLVM (space separated)"),
2279    llvm_plugins: Vec<String> = (Vec::new(), parse_list, [TRACKED],
2280        "a list LLVM plugins to enable (space separated)"),
2281    llvm_time_trace: bool = (false, parse_bool, [UNTRACKED],
2282        "generate JSON tracing data file from LLVM data (default: no)"),
2283    location_detail: LocationDetail = (LocationDetail::all(), parse_location_detail, [TRACKED],
2284        "what location details should be tracked when using caller_location, either \
2285        `none`, or a comma separated list of location details, for which \
2286        valid options are `file`, `line`, and `column` (default: `file,line,column`)"),
2287    ls: Vec<String> = (Vec::new(), parse_list, [UNTRACKED],
2288        "decode and print various parts of the crate metadata for a library crate \
2289        (space separated)"),
2290    macro_backtrace: bool = (false, parse_bool, [UNTRACKED],
2291        "show macro backtraces (default: no)"),
2292    maximal_hir_to_mir_coverage: bool = (false, parse_bool, [TRACKED],
2293        "save as much information as possible about the correspondence between MIR and HIR \
2294        as source scopes (default: no)"),
2295    merge_functions: Option<MergeFunctions> = (None, parse_merge_functions, [TRACKED],
2296        "control the operation of the MergeFunctions LLVM pass, taking \
2297        the same values as the target option of the same name"),
2298    meta_stats: bool = (false, parse_bool, [UNTRACKED],
2299        "gather metadata statistics (default: no)"),
2300    metrics_dir: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
2301        "the directory metrics emitted by rustc are dumped into (implicitly enables default set of metrics)"),
2302    min_function_alignment: Option<Align> = (None, parse_align, [TRACKED],
2303        "align all functions to at least this many bytes. Must be a power of 2"),
2304    mir_emit_retag: bool = (false, parse_bool, [TRACKED],
2305        "emit Retagging MIR statements, interpreted e.g., by miri; implies -Zmir-opt-level=0 \
2306        (default: no)"),
2307    mir_enable_passes: Vec<(String, bool)> = (Vec::new(), parse_list_with_polarity, [TRACKED],
2308        "use like `-Zmir-enable-passes=+DestinationPropagation,-InstSimplify`. Forces the \
2309        specified passes to be enabled, overriding all other checks. In particular, this will \
2310        enable unsound (known-buggy and hence usually disabled) passes without further warning! \
2311        Passes that are not specified are enabled or disabled by other flags as usual."),
2312    mir_include_spans: MirIncludeSpans = (MirIncludeSpans::default(), parse_mir_include_spans, [UNTRACKED],
2313        "include extra comments in mir pretty printing, like line numbers and statement indices, \
2314         details about types, etc. (boolean for all passes, 'nll' to enable in NLL MIR only, default: 'nll')"),
2315    mir_keep_place_mention: bool = (false, parse_bool, [TRACKED],
2316        "keep place mention MIR statements, interpreted e.g., by miri; implies -Zmir-opt-level=0 \
2317        (default: no)"),
2318    #[rustc_lint_opt_deny_field_access("use `Session::mir_opt_level` instead of this field")]
2319    mir_opt_level: Option<usize> = (None, parse_opt_number, [TRACKED],
2320        "MIR optimization level (0-4; default: 1 in non optimized builds and 2 in optimized builds)"),
2321    mir_strip_debuginfo: MirStripDebugInfo = (MirStripDebugInfo::None, parse_mir_strip_debuginfo, [TRACKED],
2322        "Whether to remove some of the MIR debug info from methods.  Default: None"),
2323    move_size_limit: Option<usize> = (None, parse_opt_number, [TRACKED],
2324        "the size at which the `large_assignments` lint starts to be emitted"),
2325    mutable_noalias: bool = (true, parse_bool, [TRACKED],
2326        "emit noalias metadata for mutable references (default: yes)"),
2327    next_solver: NextSolverConfig = (NextSolverConfig::default(), parse_next_solver_config, [TRACKED],
2328        "enable and configure the next generation trait solver used by rustc"),
2329    nll_facts: bool = (false, parse_bool, [UNTRACKED],
2330        "dump facts from NLL analysis into side files (default: no)"),
2331    nll_facts_dir: String = ("nll-facts".to_string(), parse_string, [UNTRACKED],
2332        "the directory the NLL facts are dumped into (default: `nll-facts`)"),
2333    no_analysis: bool = (false, parse_no_value, [UNTRACKED],
2334        "parse and expand the source, but run no analysis"),
2335    no_codegen: bool = (false, parse_no_value, [TRACKED_NO_CRATE_HASH],
2336        "run all passes except codegen; no output"),
2337    no_generate_arange_section: bool = (false, parse_no_value, [TRACKED],
2338        "omit DWARF address ranges that give faster lookups"),
2339    no_implied_bounds_compat: bool = (false, parse_bool, [TRACKED],
2340        "disable the compatibility version of the `implied_bounds_ty` query"),
2341    no_jump_tables: bool = (false, parse_no_value, [TRACKED],
2342        "disable the jump tables and lookup tables that can be generated from a switch case lowering"),
2343    no_leak_check: bool = (false, parse_no_value, [UNTRACKED],
2344        "disable the 'leak check' for subtyping; unsound, but useful for tests"),
2345    no_link: bool = (false, parse_no_value, [TRACKED],
2346        "compile without linking"),
2347    no_parallel_backend: bool = (false, parse_no_value, [UNTRACKED],
2348        "run LLVM in non-parallel mode (while keeping codegen-units and ThinLTO)"),
2349    no_profiler_runtime: bool = (false, parse_no_value, [TRACKED],
2350        "prevent automatic injection of the profiler_builtins crate"),
2351    no_trait_vptr: bool = (false, parse_no_value, [TRACKED],
2352        "disable generation of trait vptr in vtable for upcasting"),
2353    no_unique_section_names: bool = (false, parse_bool, [TRACKED],
2354        "do not use unique names for text and data sections when -Z function-sections is used"),
2355    normalize_docs: bool = (false, parse_bool, [TRACKED],
2356        "normalize associated items in rustdoc when generating documentation"),
2357    on_broken_pipe: OnBrokenPipe = (OnBrokenPipe::Default, parse_on_broken_pipe, [TRACKED],
2358        "behavior of std::io::ErrorKind::BrokenPipe (SIGPIPE)"),
2359    oom: OomStrategy = (OomStrategy::Abort, parse_oom_strategy, [TRACKED],
2360        "panic strategy for out-of-memory handling"),
2361    osx_rpath_install_name: bool = (false, parse_bool, [TRACKED],
2362        "pass `-install_name @rpath/...` to the macOS linker (default: no)"),
2363    packed_bundled_libs: bool = (false, parse_bool, [TRACKED],
2364        "change rlib format to store native libraries as archives"),
2365    panic_abort_tests: bool = (false, parse_bool, [TRACKED],
2366        "support compiling tests with panic=abort (default: no)"),
2367    panic_in_drop: PanicStrategy = (PanicStrategy::Unwind, parse_panic_strategy, [TRACKED],
2368        "panic strategy for panics in drops"),
2369    parse_crate_root_only: bool = (false, parse_bool, [UNTRACKED],
2370        "parse the crate root file only; do not parse other files, compile, assemble, or link \
2371        (default: no)"),
2372    patchable_function_entry: PatchableFunctionEntry = (PatchableFunctionEntry::default(), parse_patchable_function_entry, [TRACKED],
2373        "nop padding at function entry"),
2374    plt: Option<bool> = (None, parse_opt_bool, [TRACKED],
2375        "whether to use the PLT when calling into shared libraries;
2376        only has effect for PIC code on systems with ELF binaries
2377        (default: PLT is disabled if full relro is enabled on x86_64)"),
2378    polonius: Polonius = (Polonius::default(), parse_polonius, [TRACKED],
2379        "enable polonius-based borrow-checker (default: no)"),
2380    pre_link_arg: (/* redirected to pre_link_args */) = ((), parse_string_push, [UNTRACKED],
2381        "a single extra argument to prepend the linker invocation (can be used several times)"),
2382    pre_link_args: Vec<String> = (Vec::new(), parse_list, [UNTRACKED],
2383        "extra arguments to prepend to the linker invocation (space separated)"),
2384    precise_enum_drop_elaboration: bool = (true, parse_bool, [TRACKED],
2385        "use a more precise version of drop elaboration for matches on enums (default: yes). \
2386        This results in better codegen, but has caused miscompilations on some tier 2 platforms. \
2387        See #77382 and #74551."),
2388    #[rustc_lint_opt_deny_field_access("use `Session::print_codegen_stats` instead of this field")]
2389    print_codegen_stats: bool = (false, parse_bool, [UNTRACKED],
2390        "print codegen statistics (default: no)"),
2391    print_llvm_passes: bool = (false, parse_bool, [UNTRACKED],
2392        "print the LLVM optimization passes being run (default: no)"),
2393    print_mono_items: Option<String> = (None, parse_opt_string, [UNTRACKED],
2394        "print the result of the monomorphization collection pass. \
2395         Value `lazy` means to use normal collection; `eager` means to collect all items.
2396         Note that this overwrites the effect `-Clink-dead-code` has on collection!"),
2397    print_type_sizes: bool = (false, parse_bool, [UNTRACKED],
2398        "print layout information for each type encountered (default: no)"),
2399    proc_macro_backtrace: bool = (false, parse_bool, [UNTRACKED],
2400         "show backtraces for panics during proc-macro execution (default: no)"),
2401    proc_macro_execution_strategy: ProcMacroExecutionStrategy = (ProcMacroExecutionStrategy::SameThread,
2402        parse_proc_macro_execution_strategy, [UNTRACKED],
2403        "how to run proc-macro code (default: same-thread)"),
2404    profile_closures: bool = (false, parse_no_value, [UNTRACKED],
2405        "profile size of closures"),
2406    profile_sample_use: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
2407        "use the given `.prof` file for sampled profile-guided optimization (also known as AutoFDO)"),
2408    profiler_runtime: String = (String::from("profiler_builtins"), parse_string, [TRACKED],
2409        "name of the profiler runtime crate to automatically inject (default: `profiler_builtins`)"),
2410    query_dep_graph: bool = (false, parse_bool, [UNTRACKED],
2411        "enable queries of the dependency graph for regression testing (default: no)"),
2412    randomize_layout: bool = (false, parse_bool, [TRACKED],
2413        "randomize the layout of types (default: no)"),
2414    reg_struct_return: bool = (false, parse_bool, [TRACKED TARGET_MODIFIER],
2415        "On x86-32 targets, it overrides the default ABI to return small structs in registers.
2416        It is UNSOUND to link together crates that use different values for this flag!"),
2417    regparm: Option<u32> = (None, parse_opt_number, [TRACKED TARGET_MODIFIER],
2418        "On x86-32 targets, setting this to N causes the compiler to pass N arguments \
2419        in registers EAX, EDX, and ECX instead of on the stack for\
2420        \"C\", \"cdecl\", and \"stdcall\" fn.\
2421        It is UNSOUND to link together crates that use different values for this flag!"),
2422    relax_elf_relocations: Option<bool> = (None, parse_opt_bool, [TRACKED],
2423        "whether ELF relocations can be relaxed"),
2424    remap_cwd_prefix: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
2425        "remap paths under the current working directory to this path prefix"),
2426    remap_path_scope: RemapPathScopeComponents = (RemapPathScopeComponents::all(), parse_remap_path_scope, [TRACKED],
2427        "remap path scope (default: all)"),
2428    remark_dir: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
2429        "directory into which to write optimization remarks (if not specified, they will be \
2430written to standard error output)"),
2431    sanitizer: SanitizerSet = (SanitizerSet::empty(), parse_sanitizers, [TRACKED],
2432        "use a sanitizer"),
2433    sanitizer_cfi_canonical_jump_tables: Option<bool> = (Some(true), parse_opt_bool, [TRACKED],
2434        "enable canonical jump tables (default: yes)"),
2435    sanitizer_cfi_generalize_pointers: Option<bool> = (None, parse_opt_bool, [TRACKED],
2436        "enable generalizing pointer types (default: no)"),
2437    sanitizer_cfi_normalize_integers: Option<bool> = (None, parse_opt_bool, [TRACKED],
2438        "enable normalizing integer types (default: no)"),
2439    sanitizer_dataflow_abilist: Vec<String> = (Vec::new(), parse_comma_list, [TRACKED],
2440        "additional ABI list files that control how shadow parameters are passed (comma separated)"),
2441    sanitizer_memory_track_origins: usize = (0, parse_sanitizer_memory_track_origins, [TRACKED],
2442        "enable origins tracking in MemorySanitizer"),
2443    sanitizer_recover: SanitizerSet = (SanitizerSet::empty(), parse_sanitizers, [TRACKED],
2444        "enable recovery for selected sanitizers"),
2445    saturating_float_casts: Option<bool> = (None, parse_opt_bool, [TRACKED],
2446        "make float->int casts UB-free: numbers outside the integer type's range are clipped to \
2447        the max/min integer respectively, and NaN is mapped to 0 (default: yes)"),
2448    self_profile: SwitchWithOptPath = (SwitchWithOptPath::Disabled,
2449        parse_switch_with_opt_path, [UNTRACKED],
2450        "run the self profiler and output the raw event data"),
2451    self_profile_counter: String = ("wall-time".to_string(), parse_string, [UNTRACKED],
2452        "counter used by the self profiler (default: `wall-time`), one of:
2453        `wall-time` (monotonic clock, i.e. `std::time::Instant`)
2454        `instructions:u` (retired instructions, userspace-only)
2455        `instructions-minus-irqs:u` (subtracting hardware interrupt counts for extra accuracy)"
2456    ),
2457    /// keep this in sync with the event filter names in librustc_data_structures/profiling.rs
2458    self_profile_events: Option<Vec<String>> = (None, parse_opt_comma_list, [UNTRACKED],
2459        "specify the events recorded by the self profiler;
2460        for example: `-Z self-profile-events=default,query-keys`
2461        all options: none, all, default, generic-activity, query-provider, query-cache-hit
2462                     query-blocked, incr-cache-load, incr-result-hashing, query-keys, function-args, args, llvm, artifact-sizes"),
2463    share_generics: Option<bool> = (None, parse_opt_bool, [TRACKED],
2464        "make the current crate share its generic instantiations"),
2465    shell_argfiles: bool = (false, parse_bool, [UNTRACKED],
2466        "allow argument files to be specified with POSIX \"shell-style\" argument quoting"),
2467    simulate_remapped_rust_src_base: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
2468        "simulate the effect of remap-debuginfo = true at bootstrapping by remapping path \
2469        to rust's source base directory. only meant for testing purposes"),
2470    small_data_threshold: Option<usize> = (None, parse_opt_number, [TRACKED],
2471        "Set the threshold for objects to be stored in a \"small data\" section"),
2472    span_debug: bool = (false, parse_bool, [UNTRACKED],
2473        "forward proc_macro::Span's `Debug` impl to `Span`"),
2474    /// o/w tests have closure@path
2475    span_free_formats: bool = (false, parse_bool, [UNTRACKED],
2476        "exclude spans when debug-printing compiler state (default: no)"),
2477    split_dwarf_inlining: bool = (false, parse_bool, [TRACKED],
2478        "provide minimal debug info in the object/executable to facilitate online \
2479         symbolication/stack traces in the absence of .dwo/.dwp files when using Split DWARF"),
2480    split_dwarf_kind: SplitDwarfKind = (SplitDwarfKind::Split, parse_split_dwarf_kind, [TRACKED],
2481        "split dwarf variant (only if -Csplit-debuginfo is enabled and on relevant platform)
2482        (default: `split`)
2483
2484        `split`: sections which do not require relocation are written into a DWARF object (`.dwo`)
2485                 file which is ignored by the linker
2486        `single`: sections which do not require relocation are written into object file but ignored
2487                  by the linker"),
2488    split_lto_unit: Option<bool> = (None, parse_opt_bool, [TRACKED],
2489        "enable LTO unit splitting (default: no)"),
2490    src_hash_algorithm: Option<SourceFileHashAlgorithm> = (None, parse_src_file_hash, [TRACKED],
2491        "hash algorithm of source files in debug info (`md5`, `sha1`, or `sha256`)"),
2492    #[rustc_lint_opt_deny_field_access("use `Session::stack_protector` instead of this field")]
2493    stack_protector: StackProtector = (StackProtector::None, parse_stack_protector, [TRACKED],
2494        "control stack smash protection strategy (`rustc --print stack-protector-strategies` for details)"),
2495    staticlib_allow_rdylib_deps: bool = (false, parse_bool, [TRACKED],
2496        "allow staticlibs to have rust dylib dependencies"),
2497    staticlib_prefer_dynamic: bool = (false, parse_bool, [TRACKED],
2498        "prefer dynamic linking to static linking for staticlibs (default: no)"),
2499    strict_init_checks: bool = (false, parse_bool, [TRACKED],
2500        "control if mem::uninitialized and mem::zeroed panic on more UB"),
2501    #[rustc_lint_opt_deny_field_access("use `Session::teach` instead of this field")]
2502    teach: bool = (false, parse_bool, [TRACKED],
2503        "show extended diagnostic help (default: no)"),
2504    temps_dir: Option<String> = (None, parse_opt_string, [UNTRACKED],
2505        "the directory the intermediate files are written to"),
2506    terminal_urls: TerminalUrl = (TerminalUrl::No, parse_terminal_url, [UNTRACKED],
2507        "use the OSC 8 hyperlink terminal specification to print hyperlinks in the compiler output"),
2508    #[rustc_lint_opt_deny_field_access("use `Session::lto` instead of this field")]
2509    thinlto: Option<bool> = (None, parse_opt_bool, [TRACKED],
2510        "enable ThinLTO when possible"),
2511    /// We default to 1 here since we want to behave like
2512    /// a sequential compiler for now. This'll likely be adjusted
2513    /// in the future. Note that -Zthreads=0 is the way to get
2514    /// the num_cpus behavior.
2515    #[rustc_lint_opt_deny_field_access("use `Session::threads` instead of this field")]
2516    threads: usize = (1, parse_threads, [UNTRACKED],
2517        "use a thread pool with N threads"),
2518    time_llvm_passes: bool = (false, parse_bool, [UNTRACKED],
2519        "measure time of each LLVM pass (default: no)"),
2520    time_passes: bool = (false, parse_bool, [UNTRACKED],
2521        "measure time of each rustc pass (default: no)"),
2522    time_passes_format: TimePassesFormat = (TimePassesFormat::Text, parse_time_passes_format, [UNTRACKED],
2523        "the format to use for -Z time-passes (`text` (default) or `json`)"),
2524    tiny_const_eval_limit: bool = (false, parse_bool, [TRACKED],
2525        "sets a tiny, non-configurable limit for const eval; useful for compiler tests"),
2526    #[rustc_lint_opt_deny_field_access("use `Session::tls_model` instead of this field")]
2527    tls_model: Option<TlsModel> = (None, parse_tls_model, [TRACKED],
2528        "choose the TLS model to use (`rustc --print tls-models` for details)"),
2529    trace_macros: bool = (false, parse_bool, [UNTRACKED],
2530        "for every macro invocation, print its name and arguments (default: no)"),
2531    track_diagnostics: bool = (false, parse_bool, [UNTRACKED],
2532        "tracks where in rustc a diagnostic was emitted"),
2533    // Diagnostics are considered side-effects of a query (see `QuerySideEffects`) and are saved
2534    // alongside query results and changes to translation options can affect diagnostics - so
2535    // translation options should be tracked.
2536    translate_additional_ftl: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
2537        "additional fluent translation to preferentially use (for testing translation)"),
2538    translate_directionality_markers: bool = (false, parse_bool, [TRACKED],
2539        "emit directionality isolation markers in translated diagnostics"),
2540    translate_lang: Option<LanguageIdentifier> = (None, parse_opt_langid, [TRACKED],
2541        "language identifier for diagnostic output"),
2542    translate_remapped_path_to_local_path: bool = (true, parse_bool, [TRACKED],
2543        "translate remapped paths into local paths when possible (default: yes)"),
2544    trap_unreachable: Option<bool> = (None, parse_opt_bool, [TRACKED],
2545        "generate trap instructions for unreachable intrinsics (default: use target setting, usually yes)"),
2546    treat_err_as_bug: Option<NonZero<usize>> = (None, parse_treat_err_as_bug, [TRACKED],
2547        "treat the `val`th error that occurs as bug (default if not specified: 0 - don't treat errors as bugs. \
2548        default if specified without a value: 1 - treat the first error as bug)"),
2549    trim_diagnostic_paths: bool = (true, parse_bool, [UNTRACKED],
2550        "in diagnostics, use heuristics to shorten paths referring to items"),
2551    tune_cpu: Option<String> = (None, parse_opt_string, [TRACKED],
2552        "select processor to schedule for (`rustc --print target-cpus` for details)"),
2553    #[rustc_lint_opt_deny_field_access("use `Session::ub_checks` instead of this field")]
2554    ub_checks: Option<bool> = (None, parse_opt_bool, [TRACKED],
2555        "emit runtime checks for Undefined Behavior (default: -Cdebug-assertions)"),
2556    ui_testing: bool = (false, parse_bool, [UNTRACKED],
2557        "emit compiler diagnostics in a form suitable for UI testing (default: no)"),
2558    uninit_const_chunk_threshold: usize = (16, parse_number, [TRACKED],
2559        "allow generating const initializers with mixed init/uninit chunks, \
2560        and set the maximum number of chunks for which this is allowed (default: 16)"),
2561    unleash_the_miri_inside_of_you: bool = (false, parse_bool, [TRACKED],
2562        "take the brakes off const evaluation. NOTE: this is unsound (default: no)"),
2563    unpretty: Option<String> = (None, parse_unpretty, [UNTRACKED],
2564        "present the input source, unstable (and less-pretty) variants;
2565        `normal`, `identified`,
2566        `expanded`, `expanded,identified`,
2567        `expanded,hygiene` (with internal representations),
2568        `ast-tree` (raw AST before expansion),
2569        `ast-tree,expanded` (raw AST after expansion),
2570        `hir` (the HIR), `hir,identified`,
2571        `hir,typed` (HIR with types for each node),
2572        `hir-tree` (dump the raw HIR),
2573        `thir-tree`, `thir-flat`,
2574        `mir` (the MIR), or `mir-cfg` (graphviz formatted MIR)"),
2575    unsound_mir_opts: bool = (false, parse_bool, [TRACKED],
2576        "enable unsound and buggy MIR optimizations (default: no)"),
2577    /// This name is kind of confusing: Most unstable options enable something themselves, while
2578    /// this just allows "normal" options to be feature-gated.
2579    ///
2580    /// The main check for `-Zunstable-options` takes place separately from the
2581    /// usual parsing of `-Z` options (see [`crate::config::nightly_options`]),
2582    /// so this boolean value is mostly used for enabling unstable _values_ of
2583    /// stable options. That separate check doesn't handle boolean values, so
2584    /// to avoid an inconsistent state we also forbid them here.
2585    #[rustc_lint_opt_deny_field_access("use `Session::unstable_options` instead of this field")]
2586    unstable_options: bool = (false, parse_no_value, [UNTRACKED],
2587        "adds unstable command line options to rustc interface (default: no)"),
2588    use_ctors_section: Option<bool> = (None, parse_opt_bool, [TRACKED],
2589        "use legacy .ctors section for initializers rather than .init_array"),
2590    use_sync_unwind: Option<bool> = (None, parse_opt_bool, [TRACKED],
2591        "Generate sync unwind tables instead of async unwind tables (default: no)"),
2592    validate_mir: bool = (false, parse_bool, [UNTRACKED],
2593        "validate MIR after each transformation"),
2594    verbose_asm: bool = (false, parse_bool, [TRACKED],
2595        "add descriptive comments from LLVM to the assembly (may change behavior) (default: no)"),
2596    #[rustc_lint_opt_deny_field_access("use `Session::verbose_internals` instead of this field")]
2597    verbose_internals: bool = (false, parse_bool, [TRACKED_NO_CRATE_HASH],
2598        "in general, enable more debug printouts (default: no)"),
2599    #[rustc_lint_opt_deny_field_access("use `Session::verify_llvm_ir` instead of this field")]
2600    verify_llvm_ir: bool = (false, parse_bool, [TRACKED],
2601        "verify LLVM IR (default: no)"),
2602    virtual_function_elimination: bool = (false, parse_bool, [TRACKED],
2603        "enables dead virtual function elimination optimization. \
2604        Requires `-Clto[=[fat,yes]]`"),
2605    wasi_exec_model: Option<WasiExecModel> = (None, parse_wasi_exec_model, [TRACKED],
2606        "whether to build a wasi command or reactor"),
2607    wasm_c_abi: WasmCAbi = (WasmCAbi::Legacy, parse_wasm_c_abi, [TRACKED],
2608        "use spec-compliant C ABI for `wasm32-unknown-unknown` (default: legacy)"),
2609    write_long_types_to_disk: bool = (true, parse_bool, [UNTRACKED],
2610        "whether long type names should be written to files instead of being printed in errors"),
2611    // tidy-alphabetical-end
2612
2613    // If you add a new option, please update:
2614    // - compiler/rustc_interface/src/tests.rs
2615    // - src/doc/unstable-book/src/compiler-flags
2616}