rustc_session/
options.rs

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