Skip to content

Commit 4506131

Browse files
committed
Reformat top_level_options! and options! macro declarations
1 parent bd1e7c7 commit 4506131

File tree

1 file changed

+170
-96
lines changed

1 file changed

+170
-96
lines changed

‎compiler/rustc_session/src/options.rs‎

Lines changed: 170 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ macro_rules! hash_substruct {
5151
($opt_name:ident, $opt_expr:expr, $error_format:expr, $for_crate_hash:expr, $hasher:expr, [UNTRACKED]) => {{}};
5252
($opt_name:ident, $opt_expr:expr, $error_format:expr, $for_crate_hash:expr, $hasher:expr, [TRACKED]) => {{}};
5353
($opt_name:ident, $opt_expr:expr, $error_format:expr, $for_crate_hash:expr, $hasher:expr, [TRACKED_NO_CRATE_HASH]) => {{}};
54-
($opt_name:ident, $opt_expr:expr, $error_format:expr, $for_crate_hash:expr, $hasher:expr, [SUBSTRUCT]) => {
54+
($opt_name:ident, $opt_expr:expr, $error_format:expr, $for_crate_hash:expr, $hasher:expr, [SUBSTRUCT]) => {{
5555
use crate::config::dep_tracking::DepTrackingHash;
5656
$opt_expr.dep_tracking_hash($for_crate_hash, $error_format).hash(
5757
$hasher,
5858
$error_format,
5959
$for_crate_hash,
6060
);
61-
};
61+
}};
6262
}
6363

6464
/// Extended target modifier info.
@@ -309,61 +309,85 @@ macro_rules! top_level_tmod_enum {
309309
}
310310

311311
macro_rules! top_level_options {
312-
( $( #[$top_level_attr:meta] )* pub struct Options { $(
313-
$( #[$attr:meta] )*
314-
$opt:ident : $t:ty [$dep_tracking_marker:ident $( $tmod:ident $variant:ident )?],
315-
)* } ) => (
316-
top_level_tmod_enum!( {$([$dep_tracking_marker $($tmod $variant),*])|*} );
312+
(
313+
$(#[$top_level_attr:meta])*
314+
pub struct Options {
315+
$(
316+
$(#[$attr:meta])*
317+
$opt:ident : $t:ty [
318+
$dep_tracking_marker:ident
319+
$( $tmod:ident $variant:ident )?
320+
],
321+
)*
322+
}
323+
) => {
324+
top_level_tmod_enum!(
325+
{
326+
$(
327+
[$dep_tracking_marker $($tmod $variant),*]
328+
)|*
329+
}
330+
);
317331

318332
#[derive(Clone)]
319-
$( #[$top_level_attr] )*
333+
$(#[$top_level_attr])*
320334
pub struct Options {
321335
$(
322-
$( #[$attr] )*
323-
pub $opt: $t
324-
),*,
336+
$(#[$attr])*
337+
pub $opt: $t,
338+
)*
325339
pub target_modifiers: BTreeMap<OptionsTargetModifiers, String>,
326340
pub mitigation_coverage_map: mitigation_coverage::MitigationCoverageMap,
327341
}
328342

329343
impl Options {
330344
pub fn dep_tracking_hash(&self, for_crate_hash: bool) -> Hash64 {
331345
let mut sub_hashes = BTreeMap::new();
332-
$({
333-
hash_opt!($opt,
334-
&self.$opt,
335-
&mut sub_hashes,
336-
for_crate_hash,
337-
[$dep_tracking_marker]);
338-
})*
346+
$(
347+
hash_opt!(
348+
$opt,
349+
&self.$opt,
350+
&mut sub_hashes,
351+
for_crate_hash,
352+
[$dep_tracking_marker]
353+
);
354+
)*
339355
let mut hasher = StableHasher::new();
340-
dep_tracking::stable_hash(sub_hashes,
341-
&mut hasher,
342-
self.error_format,
343-
for_crate_hash);
344-
$({
345-
hash_substruct!($opt,
356+
dep_tracking::stable_hash(
357+
sub_hashes,
358+
&mut hasher,
359+
self.error_format,
360+
for_crate_hash,
361+
);
362+
$(
363+
hash_substruct!(
364+
$opt,
346365
&self.$opt,
347366
self.error_format,
348367
for_crate_hash,
349368
&mut hasher,
350-
[$dep_tracking_marker]);
351-
})*
369+
[$dep_tracking_marker]
370+
);
371+
)*
352372
hasher.finish()
353373
}
354374

355375
pub fn gather_target_modifiers(&self) -> Vec<TargetModifier> {
356376
let mut mods = Vec::<TargetModifier>::new();
357-
$({
358-
gather_tmods_top_level!($opt,
359-
&self.$opt, &mut mods, &self.target_modifiers,
360-
[$dep_tracking_marker $($tmod),*]);
361-
})*
377+
$(
378+
gather_tmods_top_level!(
379+
$opt,
380+
&self.$opt,
381+
&mut mods,
382+
&self.target_modifiers,
383+
[$dep_tracking_marker $($tmod),*]
384+
);
385+
)*
362386
mods.sort_by(|a, b| a.opt.cmp(&b.opt));
363387
mods
364388
}
365389
}
366-
);
390+
}
367391
}
368392

369393
top_level_options!(
@@ -658,80 +682,130 @@ macro_rules! setter_for {
658682
/// generated code to parse an option into its respective field in the struct. There are a few
659683
/// hand-written parsers for parsing specific types of values in this module.
660684
macro_rules! options {
661-
($struct_name:ident, $tmod_enum_name:ident, $stat:ident, $optmod:ident, $prefix:expr, $outputname:expr,
662-
$($( #[$attr:meta] )* $opt:ident : $t:ty = (
663-
$init:expr,
664-
$parse:ident,
665-
[$dep_tracking_marker:ident $( $modifier_kind:ident )?],
666-
$desc:expr
667-
$(, removed: $removed:ident )?)
668-
),* ,) =>
669-
(
670-
#[derive(Clone)]
671-
#[rustc_lint_opt_ty]
672-
pub struct $struct_name { $( $( #[$attr] )* pub $opt: $t),* }
685+
(
686+
$struct_name:ident,
687+
$tmod_enum_name:ident,
688+
$stat:ident,
689+
$optmod:ident,
690+
$prefix:expr,
691+
$outputname:expr,
692+
693+
$(
694+
$(#[$attr:meta])*
695+
$opt:ident : $t:ty = (
696+
$init:expr,
697+
$parse:ident,
698+
[$dep_tracking_marker:ident $( $modifier_kind:ident )?],
699+
$desc:expr
700+
$(, removed: $removed:ident )?
701+
),
702+
)*
703+
) => {
704+
#[derive(Clone)]
705+
#[rustc_lint_opt_ty]
706+
pub struct $struct_name {
707+
$(
708+
$(#[$attr])*
709+
pub $opt: $t,
710+
)*
711+
}
673712

674-
tmod_enum!( $tmod_enum_name, $prefix, {$($opt, $parse, $t, [$($modifier_kind),*])|*} );
713+
tmod_enum!(
714+
$tmod_enum_name,
715+
$prefix,
716+
{
717+
$(
718+
$opt, $parse, $t, [$($modifier_kind),*]
719+
)|*
720+
}
721+
);
675722

676-
impl Default for $struct_name {
677-
fn default() -> $struct_name {
678-
$struct_name { $($opt: $init),* }
723+
impl Default for $struct_name {
724+
fn default() -> $struct_name {
725+
$struct_name {
726+
$(
727+
$opt: $init,
728+
)*
729+
}
730+
}
679731
}
680-
}
681732

682-
impl $struct_name {
683-
pub fn build(
684-
early_dcx: &EarlyDiagCtxt,
685-
matches: &getopts::Matches,
686-
target_modifiers: &mut CollectedOptions,
687-
) -> $struct_name {
688-
build_options(early_dcx, matches, target_modifiers, $stat, $prefix, $outputname)
689-
}
733+
impl $struct_name {
734+
pub fn build(
735+
early_dcx: &EarlyDiagCtxt,
736+
matches: &getopts::Matches,
737+
target_modifiers: &mut CollectedOptions,
738+
) -> $struct_name {
739+
build_options(early_dcx, matches, target_modifiers, $stat, $prefix, $outputname)
740+
}
690741

691-
fn dep_tracking_hash(&self, for_crate_hash: bool, error_format: ErrorOutputType) -> Hash64 {
692-
let mut sub_hashes = BTreeMap::new();
693-
$({
694-
hash_opt!($opt,
695-
&self.$opt,
696-
&mut sub_hashes,
697-
for_crate_hash,
698-
[$dep_tracking_marker]);
699-
})*
700-
let mut hasher = StableHasher::new();
701-
dep_tracking::stable_hash(sub_hashes,
702-
&mut hasher,
703-
error_format,
704-
for_crate_hash
705-
);
706-
hasher.finish()
707-
}
742+
fn dep_tracking_hash(
743+
&self,
744+
for_crate_hash: bool,
745+
error_format: ErrorOutputType,
746+
) -> Hash64 {
747+
let mut sub_hashes = BTreeMap::new();
748+
$(
749+
hash_opt!(
750+
$opt,
751+
&self.$opt,
752+
&mut sub_hashes,
753+
for_crate_hash,
754+
[$dep_tracking_marker]
755+
);
756+
)*
757+
let mut hasher = StableHasher::new();
758+
dep_tracking::stable_hash(
759+
sub_hashes,
760+
&mut hasher,
761+
error_format,
762+
for_crate_hash,
763+
);
764+
hasher.finish()
765+
}
708766

709-
pub fn gather_target_modifiers(
710-
&self,
711-
_mods: &mut Vec<TargetModifier>,
712-
_tmod_vals: &BTreeMap<OptionsTargetModifiers, String>,
713-
) {
714-
$({
715-
gather_tmods!($struct_name, $tmod_enum_name, $opt, &self.$opt, $init, _mods, _tmod_vals,
716-
[$dep_tracking_marker], [$($modifier_kind),*]);
717-
})*
767+
pub fn gather_target_modifiers(
768+
&self,
769+
_mods: &mut Vec<TargetModifier>,
770+
_tmod_vals: &BTreeMap<OptionsTargetModifiers, String>,
771+
) {
772+
$(
773+
gather_tmods!(
774+
$struct_name,
775+
$tmod_enum_name,
776+
$opt,
777+
&self.$opt,
778+
$init,
779+
_mods,
780+
_tmod_vals,
781+
[$dep_tracking_marker],
782+
[$($modifier_kind),*]
783+
);
784+
)*
785+
}
718786
}
719-
}
720787

721-
pub const $stat: OptionDescrs<$struct_name> =
722-
&[ $( OptionDesc{ name: stringify!($opt), setter: $optmod::$opt,
723-
type_desc: desc::$parse, desc: $desc, removed: None $( .or(Some(RemovedOption::$removed)) )?,
724-
tmod: tmod_enum_opt!($struct_name, $tmod_enum_name, $opt, $($modifier_kind),*),
725-
mitigation: mitigation_enum_opt!($opt, $($modifier_kind),*),
726-
} ),* ];
788+
pub const $stat: OptionDescrs<$struct_name> = &[
789+
$(
790+
OptionDesc {
791+
name: stringify!($opt),
792+
setter: $optmod::$opt,
793+
type_desc: desc::$parse,
794+
desc: $desc,
795+
removed: None $( .or(Some(RemovedOption::$removed)) )?,
796+
tmod: tmod_enum_opt!($struct_name, $tmod_enum_name, $opt, $($modifier_kind),*),
797+
mitigation: mitigation_enum_opt!($opt, $($modifier_kind),*),
798+
},
799+
)*
800+
];
727801

728-
mod $optmod {
729-
$(
730-
setter_for!($opt, $struct_name, $parse);
731-
)*
802+
mod $optmod {
803+
$(
804+
setter_for!($opt, $struct_name, $parse);
805+
)*
806+
}
732807
}
733-
734-
) }
808+
}
735809

736810
impl CodegenOptions {
737811
// JUSTIFICATION: defn of the suggested wrapper fn

0 commit comments

Comments
 (0)