Skip to content

Commit d5e9dff

Browse files
committed
Support delegation in stable hashing macros
1 parent f0622df commit d5e9dff

File tree

4 files changed

+115
-280
lines changed

4 files changed

+115
-280
lines changed

src/librustc/ich/impls_hir.rs

+71-182
Original file line numberDiff line numberDiff line change
@@ -357,20 +357,11 @@ impl_stable_hash_for!(enum hir::FunctionRetTy {
357357
Return(t)
358358
});
359359

360-
impl<'a> HashStable<StableHashingContext<'a>> for hir::TraitRef {
361-
fn hash_stable<W: StableHasherResult>(&self,
362-
hcx: &mut StableHashingContext<'a>,
363-
hasher: &mut StableHasher<W>) {
364-
let hir::TraitRef {
365-
ref path,
366-
// Don't hash the ref_id. It is tracked via the thing it is used to access
367-
ref_id: _,
368-
} = *self;
369-
370-
path.hash_stable(hcx, hasher);
371-
}
372-
}
373-
360+
impl_stable_hash_for!(struct hir::TraitRef {
361+
// Don't hash the ref_id. It is tracked via the thing it is used to access
362+
ref_id -> _,
363+
path,
364+
});
374365

375366
impl_stable_hash_for!(struct hir::PolyTraitRef {
376367
bound_generic_params,
@@ -393,66 +384,32 @@ impl_stable_hash_for!(struct hir::MacroDef {
393384
body
394385
});
395386

387+
impl_stable_hash_for!(struct hir::Block {
388+
stmts,
389+
expr,
390+
id -> _,
391+
hir_id -> _,
392+
rules,
393+
span,
394+
targeted_by_break,
395+
recovered,
396+
});
396397

397-
impl<'a> HashStable<StableHashingContext<'a>> for hir::Block {
398-
fn hash_stable<W: StableHasherResult>(&self,
399-
hcx: &mut StableHashingContext<'a>,
400-
hasher: &mut StableHasher<W>) {
401-
let hir::Block {
402-
ref stmts,
403-
ref expr,
404-
id: _,
405-
hir_id: _,
406-
rules,
407-
span,
408-
targeted_by_break,
409-
recovered,
410-
} = *self;
411-
412-
stmts.hash_stable(hcx, hasher);
413-
expr.hash_stable(hcx, hasher);
414-
rules.hash_stable(hcx, hasher);
415-
span.hash_stable(hcx, hasher);
416-
recovered.hash_stable(hcx, hasher);
417-
targeted_by_break.hash_stable(hcx, hasher);
418-
}
419-
}
420-
421-
impl<'a> HashStable<StableHashingContext<'a>> for hir::Pat {
422-
fn hash_stable<W: StableHasherResult>(&self,
423-
hcx: &mut StableHashingContext<'a>,
424-
hasher: &mut StableHasher<W>) {
425-
let hir::Pat {
426-
id: _,
427-
hir_id: _,
428-
ref node,
429-
ref span
430-
} = *self;
431-
432-
433-
node.hash_stable(hcx, hasher);
434-
span.hash_stable(hcx, hasher);
435-
}
436-
}
398+
impl_stable_hash_for!(struct hir::Pat {
399+
id -> _,
400+
hir_id -> _,
401+
node,
402+
span,
403+
});
437404

438405
impl_stable_hash_for_spanned!(hir::FieldPat);
439406

440-
impl<'a> HashStable<StableHashingContext<'a>> for hir::FieldPat {
441-
fn hash_stable<W: StableHasherResult>(&self,
442-
hcx: &mut StableHashingContext<'a>,
443-
hasher: &mut StableHasher<W>) {
444-
let hir::FieldPat {
445-
id: _,
446-
ident,
447-
ref pat,
448-
is_shorthand,
449-
} = *self;
450-
451-
ident.hash_stable(hcx, hasher);
452-
pat.hash_stable(hcx, hasher);
453-
is_shorthand.hash_stable(hcx, hasher);
454-
}
455-
}
407+
impl_stable_hash_for!(struct hir::FieldPat {
408+
id -> _,
409+
ident,
410+
pat,
411+
is_shorthand,
412+
});
456413

457414
impl_stable_hash_for!(enum hir::BindingAnnotation {
458415
Unannotated,
@@ -535,24 +492,13 @@ impl_stable_hash_for!(struct hir::Arm {
535492
body
536493
});
537494

538-
impl<'a> HashStable<StableHashingContext<'a>> for hir::Field {
539-
fn hash_stable<W: StableHasherResult>(&self,
540-
hcx: &mut StableHashingContext<'a>,
541-
hasher: &mut StableHasher<W>) {
542-
let hir::Field {
543-
id: _,
544-
ident,
545-
ref expr,
546-
span,
547-
is_shorthand,
548-
} = *self;
549-
550-
ident.hash_stable(hcx, hasher);
551-
expr.hash_stable(hcx, hasher);
552-
span.hash_stable(hcx, hasher);
553-
is_shorthand.hash_stable(hcx, hasher);
554-
}
555-
}
495+
impl_stable_hash_for!(struct hir::Field {
496+
id -> _,
497+
ident,
498+
expr,
499+
span,
500+
is_shorthand,
501+
});
556502

557503
impl_stable_hash_for_spanned!(ast::Name);
558504

@@ -684,19 +630,10 @@ impl_stable_hash_for!(enum hir::LoopIdError {
684630
UnresolvedLabel
685631
});
686632

687-
impl<'a> HashStable<StableHashingContext<'a>> for ast::Ident {
688-
fn hash_stable<W: StableHasherResult>(&self,
689-
hcx: &mut StableHashingContext<'a>,
690-
hasher: &mut StableHasher<W>) {
691-
let ast::Ident {
692-
name,
693-
span,
694-
} = *self;
695-
696-
name.hash_stable(hcx, hasher);
697-
span.hash_stable(hcx, hasher);
698-
}
699-
}
633+
impl_stable_hash_for!(struct ast::Ident {
634+
name,
635+
span,
636+
});
700637

701638
impl<'a> HashStable<StableHashingContext<'a>> for hir::TraitItem {
702639
fn hash_stable<W: StableHasherResult>(&self,
@@ -816,21 +753,13 @@ impl_stable_hash_for!(enum hir::ImplPolarity {
816753
Negative
817754
});
818755

819-
impl<'a> HashStable<StableHashingContext<'a>> for hir::Mod {
820-
fn hash_stable<W: StableHasherResult>(&self,
821-
hcx: &mut StableHashingContext<'a>,
822-
hasher: &mut StableHasher<W>) {
823-
let hir::Mod {
824-
inner,
825-
// We are not hashing the IDs of the items contained in the module.
826-
// This is harmless and matches the current behavior but it's not
827-
// actually correct. See issue #40876.
828-
item_ids: _,
829-
} = *self;
830-
831-
inner.hash_stable(hcx, hasher);
832-
}
833-
}
756+
impl_stable_hash_for!(struct hir::Mod {
757+
inner,
758+
// We are not hashing the IDs of the items contained in the module.
759+
// This is harmless and matches the current behavior but it's not
760+
// actually correct. See issue #40876.
761+
item_ids -> _,
762+
});
834763

835764
impl_stable_hash_for!(struct hir::ForeignMod {
836765
abi,
@@ -931,8 +860,7 @@ impl_stable_hash_for!(struct hir::ImplItemRef {
931860
defaultness
932861
});
933862

934-
impl<'a> HashStable<StableHashingContext<'a>>
935-
for hir::AssociatedItemKind {
863+
impl<'a> HashStable<StableHashingContext<'a>> for hir::AssociatedItemKind {
936864
fn hash_stable<W: StableHasherResult>(&self,
937865
hcx: &mut StableHashingContext<'a>,
938866
hasher: &mut StableHasher<W>) {
@@ -1012,45 +940,22 @@ impl_stable_hash_for!(struct hir::InlineAsmOutput {
1012940
is_indirect
1013941
});
1014942

1015-
impl<'a> HashStable<StableHashingContext<'a>> for hir::GlobalAsm {
1016-
fn hash_stable<W: StableHasherResult>(&self,
1017-
hcx: &mut StableHashingContext<'a>,
1018-
hasher: &mut StableHasher<W>) {
1019-
let hir::GlobalAsm {
1020-
asm,
1021-
ctxt: _
1022-
} = *self;
1023-
1024-
asm.hash_stable(hcx, hasher);
1025-
}
1026-
}
1027-
1028-
impl<'a> HashStable<StableHashingContext<'a>> for hir::InlineAsm {
1029-
fn hash_stable<W: StableHasherResult>(&self,
1030-
hcx: &mut StableHashingContext<'a>,
1031-
hasher: &mut StableHasher<W>) {
1032-
let hir::InlineAsm {
1033-
asm,
1034-
asm_str_style,
1035-
ref outputs,
1036-
ref inputs,
1037-
ref clobbers,
1038-
volatile,
1039-
alignstack,
1040-
dialect,
1041-
ctxt: _, // This is used for error reporting
1042-
} = *self;
943+
impl_stable_hash_for!(struct hir::GlobalAsm {
944+
asm,
945+
ctxt -> _, // This is used for error reporting
946+
});
1043947

1044-
asm.hash_stable(hcx, hasher);
1045-
asm_str_style.hash_stable(hcx, hasher);
1046-
outputs.hash_stable(hcx, hasher);
1047-
inputs.hash_stable(hcx, hasher);
1048-
clobbers.hash_stable(hcx, hasher);
1049-
volatile.hash_stable(hcx, hasher);
1050-
alignstack.hash_stable(hcx, hasher);
1051-
dialect.hash_stable(hcx, hasher);
1052-
}
1053-
}
948+
impl_stable_hash_for!(struct hir::InlineAsm {
949+
asm,
950+
asm_str_style,
951+
outputs,
952+
inputs,
953+
clobbers,
954+
volatile,
955+
alignstack,
956+
dialect,
957+
ctxt -> _, // This is used for error reporting
958+
});
1054959

1055960
impl_stable_hash_for!(enum hir::def::CtorKind {
1056961
Fn,
@@ -1113,8 +1018,7 @@ impl_stable_hash_for!(enum hir::Constness {
11131018
NotConst
11141019
});
11151020

1116-
impl<'a> HashStable<StableHashingContext<'a>>
1117-
for hir::def_id::DefIndex {
1021+
impl<'a> HashStable<StableHashingContext<'a>> for hir::def_id::DefIndex {
11181022

11191023
fn hash_stable<W: StableHasherResult>(&self,
11201024
hcx: &mut StableHashingContext<'a>,
@@ -1140,8 +1044,7 @@ impl_stable_hash_for!(struct hir::def::Export {
11401044
span
11411045
});
11421046

1143-
impl<'a> HashStable<StableHashingContext<'a>>
1144-
for ::middle::lang_items::LangItem {
1047+
impl<'a> HashStable<StableHashingContext<'a>> for ::middle::lang_items::LangItem {
11451048
fn hash_stable<W: StableHasherResult>(&self,
11461049
_: &mut StableHashingContext<'a>,
11471050
hasher: &mut StableHasher<W>) {
@@ -1154,8 +1057,7 @@ impl_stable_hash_for!(struct ::middle::lang_items::LanguageItems {
11541057
missing
11551058
});
11561059

1157-
impl<'a> HashStable<StableHashingContext<'a>>
1158-
for hir::TraitCandidate {
1060+
impl<'a> HashStable<StableHashingContext<'a>> for hir::TraitCandidate {
11591061
fn hash_stable<W: StableHasherResult>(&self,
11601062
hcx: &mut StableHashingContext<'a>,
11611063
hasher: &mut StableHasher<W>) {
@@ -1189,26 +1091,13 @@ impl<'a> ToStableHashKey<StableHashingContext<'a>> for hir::TraitCandidate {
11891091
}
11901092
}
11911093

1192-
impl<'hir> HashStable<StableHashingContext<'hir>> for hir::CodegenFnAttrs
1193-
{
1194-
fn hash_stable<W: StableHasherResult>(&self,
1195-
hcx: &mut StableHashingContext<'hir>,
1196-
hasher: &mut StableHasher<W>) {
1197-
let hir::CodegenFnAttrs {
1198-
flags,
1199-
inline,
1200-
export_name,
1201-
ref target_features,
1202-
linkage,
1203-
} = *self;
1204-
1205-
flags.hash_stable(hcx, hasher);
1206-
inline.hash_stable(hcx, hasher);
1207-
export_name.hash_stable(hcx, hasher);
1208-
target_features.hash_stable(hcx, hasher);
1209-
linkage.hash_stable(hcx, hasher);
1210-
}
1211-
}
1094+
impl_stable_hash_for!(struct hir::CodegenFnAttrs {
1095+
flags,
1096+
inline,
1097+
export_name,
1098+
target_features,
1099+
linkage,
1100+
});
12121101

12131102
impl<'hir> HashStable<StableHashingContext<'hir>> for hir::CodegenFnAttrFlags
12141103
{

0 commit comments

Comments
 (0)