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