Skip to content

Commit

Permalink
Rollup merge of rust-lang#84803 - jyn514:duplicate-macros, r=petroche…
Browse files Browse the repository at this point in the history
…nkov

Reduce duplication in `impl_dep_tracking_hash` macros

Cherry-picked from rust-lang#84234 since it will be a while until it lands.
  • Loading branch information
RalfJung authored May 5, 2021
2 parents c7b4c80 + dd43d13 commit 04c3e94
Showing 1 changed file with 61 additions and 57 deletions.
118 changes: 61 additions & 57 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2332,17 +2332,17 @@ crate mod dep_tracking {
}

macro_rules! impl_dep_tracking_hash_via_hash {
($t:ty) => {
($($t:ty),+ $(,)?) => {$(
impl DepTrackingHash for $t {
fn hash(&self, hasher: &mut DefaultHasher, _: ErrorOutputType) {
Hash::hash(self, hasher);
}
}
};
)+};
}

macro_rules! impl_dep_tracking_hash_for_sortable_vec_of {
($t:ty) => {
($($t:ty),+ $(,)?) => {$(
impl DepTrackingHash for Vec<$t> {
fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType) {
let mut elems: Vec<&$t> = self.iter().collect();
Expand All @@ -2354,61 +2354,65 @@ crate mod dep_tracking {
}
}
}
};
}
)+};
}

impl_dep_tracking_hash_via_hash!(
bool,
usize,
u64,
String,
PathBuf,
lint::Level,
Option<bool>,
Option<u32>,
Option<usize>,
Option<NonZeroUsize>,
Option<String>,
Option<(String, u64)>,
Option<Vec<String>>,
Option<MergeFunctions>,
Option<RelocModel>,
Option<CodeModel>,
Option<TlsModel>,
Option<WasiExecModel>,
Option<PanicStrategy>,
Option<RelroLevel>,
Option<InstrumentCoverage>,
Option<lint::Level>,
Option<PathBuf>,
CrateType,
MergeFunctions,
PanicStrategy,
RelroLevel,
Passes,
OptLevel,
LtoCli,
DebugInfo,
UnstableFeatures,
OutputTypes,
NativeLibKind,
SanitizerSet,
CFGuard,
TargetTriple,
Edition,
LinkerPluginLto,
Option<SplitDebuginfo>,
SwitchWithOptPath,
Option<SymbolManglingVersion>,
Option<SourceFileHashAlgorithm>,
TrimmedDefPaths,
);

impl_dep_tracking_hash_via_hash!(bool);
impl_dep_tracking_hash_via_hash!(usize);
impl_dep_tracking_hash_via_hash!(u64);
impl_dep_tracking_hash_via_hash!(String);
impl_dep_tracking_hash_via_hash!(PathBuf);
impl_dep_tracking_hash_via_hash!(lint::Level);
impl_dep_tracking_hash_via_hash!(Option<bool>);
impl_dep_tracking_hash_via_hash!(Option<u32>);
impl_dep_tracking_hash_via_hash!(Option<usize>);
impl_dep_tracking_hash_via_hash!(Option<NonZeroUsize>);
impl_dep_tracking_hash_via_hash!(Option<String>);
impl_dep_tracking_hash_via_hash!(Option<(String, u64)>);
impl_dep_tracking_hash_via_hash!(Option<Vec<String>>);
impl_dep_tracking_hash_via_hash!(Option<MergeFunctions>);
impl_dep_tracking_hash_via_hash!(Option<RelocModel>);
impl_dep_tracking_hash_via_hash!(Option<CodeModel>);
impl_dep_tracking_hash_via_hash!(Option<TlsModel>);
impl_dep_tracking_hash_via_hash!(Option<WasiExecModel>);
impl_dep_tracking_hash_via_hash!(Option<PanicStrategy>);
impl_dep_tracking_hash_via_hash!(Option<RelroLevel>);
impl_dep_tracking_hash_via_hash!(Option<InstrumentCoverage>);
impl_dep_tracking_hash_via_hash!(Option<lint::Level>);
impl_dep_tracking_hash_via_hash!(Option<PathBuf>);
impl_dep_tracking_hash_via_hash!(CrateType);
impl_dep_tracking_hash_via_hash!(MergeFunctions);
impl_dep_tracking_hash_via_hash!(PanicStrategy);
impl_dep_tracking_hash_via_hash!(RelroLevel);
impl_dep_tracking_hash_via_hash!(Passes);
impl_dep_tracking_hash_via_hash!(OptLevel);
impl_dep_tracking_hash_via_hash!(LtoCli);
impl_dep_tracking_hash_via_hash!(DebugInfo);
impl_dep_tracking_hash_via_hash!(UnstableFeatures);
impl_dep_tracking_hash_via_hash!(OutputTypes);
impl_dep_tracking_hash_via_hash!(NativeLibKind);
impl_dep_tracking_hash_via_hash!(SanitizerSet);
impl_dep_tracking_hash_via_hash!(CFGuard);
impl_dep_tracking_hash_via_hash!(TargetTriple);
impl_dep_tracking_hash_via_hash!(Edition);
impl_dep_tracking_hash_via_hash!(LinkerPluginLto);
impl_dep_tracking_hash_via_hash!(Option<SplitDebuginfo>);
impl_dep_tracking_hash_via_hash!(SwitchWithOptPath);
impl_dep_tracking_hash_via_hash!(Option<SymbolManglingVersion>);
impl_dep_tracking_hash_via_hash!(Option<SourceFileHashAlgorithm>);
impl_dep_tracking_hash_via_hash!(TrimmedDefPaths);

impl_dep_tracking_hash_for_sortable_vec_of!(String);
impl_dep_tracking_hash_for_sortable_vec_of!(PathBuf);
impl_dep_tracking_hash_for_sortable_vec_of!((PathBuf, PathBuf));
impl_dep_tracking_hash_for_sortable_vec_of!(CrateType);
impl_dep_tracking_hash_for_sortable_vec_of!((String, lint::Level));
impl_dep_tracking_hash_for_sortable_vec_of!((String, Option<String>, NativeLibKind));
impl_dep_tracking_hash_for_sortable_vec_of!((String, u64));
impl_dep_tracking_hash_for_sortable_vec_of!(
String,
PathBuf,
(PathBuf, PathBuf),
CrateType,
(String, lint::Level),
(String, Option<String>, NativeLibKind),
(String, u64)
);

impl<T1, T2> DepTrackingHash for (T1, T2)
where
Expand Down

0 comments on commit 04c3e94

Please sign in to comment.