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