Skip to content

Commit 7921572

Browse files
committedNov 13, 2018
Rollup merge of rust-lang#55722 - RalfJung:impl-stable-hash, r=varkor
impl_stable_hash_for: support enums and tuple structs with generic parameters Port a bunch of implementations over to the macro, now that that is possible.

File tree

3 files changed

+192
-377
lines changed

3 files changed

+192
-377
lines changed
 

‎src/librustc/ich/impls_mir.rs

+17-54
Original file line numberDiff line numberDiff line change
@@ -37,68 +37,31 @@ impl_stable_hash_for!(struct mir::BasicBlockData<'tcx> { statements, terminator,
3737
impl_stable_hash_for!(struct mir::UnsafetyViolation { source_info, description, details, kind });
3838
impl_stable_hash_for!(struct mir::UnsafetyCheckResult { violations, unsafe_blocks });
3939

40-
impl<'a> HashStable<StableHashingContext<'a>>
41-
for mir::BorrowKind {
42-
#[inline]
43-
fn hash_stable<W: StableHasherResult>(&self,
44-
hcx: &mut StableHashingContext<'a>,
45-
hasher: &mut StableHasher<W>) {
46-
mem::discriminant(self).hash_stable(hcx, hasher);
47-
48-
match *self {
49-
mir::BorrowKind::Shared |
50-
mir::BorrowKind::Shallow |
51-
mir::BorrowKind::Unique => {}
52-
mir::BorrowKind::Mut { allow_two_phase_borrow } => {
53-
allow_two_phase_borrow.hash_stable(hcx, hasher);
54-
}
55-
}
56-
}
57-
}
58-
59-
60-
impl<'a> HashStable<StableHashingContext<'a>>
61-
for mir::UnsafetyViolationKind {
62-
#[inline]
63-
fn hash_stable<W: StableHasherResult>(&self,
64-
hcx: &mut StableHashingContext<'a>,
65-
hasher: &mut StableHasher<W>) {
66-
67-
mem::discriminant(self).hash_stable(hcx, hasher);
68-
69-
match *self {
70-
mir::UnsafetyViolationKind::General => {}
71-
mir::UnsafetyViolationKind::MinConstFn => {}
72-
mir::UnsafetyViolationKind::ExternStatic(lint_node_id) |
73-
mir::UnsafetyViolationKind::BorrowPacked(lint_node_id) => {
74-
lint_node_id.hash_stable(hcx, hasher);
75-
}
40+
impl_stable_hash_for!(enum mir::BorrowKind {
41+
Shared,
42+
Shallow,
43+
Unique,
44+
Mut { allow_two_phase_borrow },
45+
});
7646

77-
}
78-
}
79-
}
47+
impl_stable_hash_for!(enum mir::UnsafetyViolationKind {
48+
General,
49+
MinConstFn,
50+
ExternStatic(lint_node_id),
51+
BorrowPacked(lint_node_id),
52+
});
8053

8154
impl_stable_hash_for!(struct mir::Terminator<'tcx> {
8255
kind,
8356
source_info
8457
});
8558

86-
impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>> for mir::ClearCrossCrate<T>
87-
where T: HashStable<StableHashingContext<'a>>
88-
{
89-
#[inline]
90-
fn hash_stable<W: StableHasherResult>(&self,
91-
hcx: &mut StableHashingContext<'a>,
92-
hasher: &mut StableHasher<W>) {
93-
mem::discriminant(self).hash_stable(hcx, hasher);
94-
match *self {
95-
mir::ClearCrossCrate::Clear => {}
96-
mir::ClearCrossCrate::Set(ref value) => {
97-
value.hash_stable(hcx, hasher);
98-
}
99-
}
59+
impl_stable_hash_for!(
60+
impl<T> for enum mir::ClearCrossCrate<T> [ mir::ClearCrossCrate ] {
61+
Clear,
62+
Set(value),
10063
}
101-
}
64+
);
10265

10366
impl<'a> HashStable<StableHashingContext<'a>> for mir::Local {
10467
#[inline]

‎src/librustc/ich/impls_ty.rs

+125-301
Original file line numberDiff line numberDiff line change
@@ -224,20 +224,10 @@ impl_stable_hash_for!(enum ty::BorrowKind {
224224
MutBorrow
225225
});
226226

227-
impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
228-
for ty::UpvarCapture<'gcx> {
229-
fn hash_stable<W: StableHasherResult>(&self,
230-
hcx: &mut StableHashingContext<'a>,
231-
hasher: &mut StableHasher<W>) {
232-
mem::discriminant(self).hash_stable(hcx, hasher);
233-
match *self {
234-
ty::UpvarCapture::ByValue => {}
235-
ty::UpvarCapture::ByRef(ref up_var_borrow) => {
236-
up_var_borrow.hash_stable(hcx, hasher);
237-
}
238-
}
239-
}
240-
}
227+
impl_stable_hash_for!(impl<'gcx> for enum ty::UpvarCapture<'gcx> [ ty::UpvarCapture ] {
228+
ByValue,
229+
ByRef(up_var_borrow),
230+
});
241231

242232
impl_stable_hash_for!(struct ty::GenSig<'tcx> {
243233
yield_ty,
@@ -272,64 +262,23 @@ impl_stable_hash_for!(enum ty::Visibility {
272262
impl_stable_hash_for!(struct ty::TraitRef<'tcx> { def_id, substs });
273263
impl_stable_hash_for!(struct ty::TraitPredicate<'tcx> { trait_ref });
274264
impl_stable_hash_for!(struct ty::SubtypePredicate<'tcx> { a_is_expected, a, b });
275-
276-
impl<'a, 'gcx, A, B> HashStable<StableHashingContext<'a>>
277-
for ty::OutlivesPredicate<A, B>
278-
where A: HashStable<StableHashingContext<'a>>,
279-
B: HashStable<StableHashingContext<'a>>,
280-
{
281-
fn hash_stable<W: StableHasherResult>(&self,
282-
hcx: &mut StableHashingContext<'a>,
283-
hasher: &mut StableHasher<W>) {
284-
let ty::OutlivesPredicate(ref a, ref b) = *self;
285-
a.hash_stable(hcx, hasher);
286-
b.hash_stable(hcx, hasher);
287-
}
288-
}
289-
265+
impl_stable_hash_for!(impl<A, B> for tuple_struct ty::OutlivesPredicate<A, B> { a, b });
290266
impl_stable_hash_for!(struct ty::ProjectionPredicate<'tcx> { projection_ty, ty });
291267
impl_stable_hash_for!(struct ty::ProjectionTy<'tcx> { substs, item_def_id });
292268

293-
294-
impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::Predicate<'gcx> {
295-
fn hash_stable<W: StableHasherResult>(&self,
296-
hcx: &mut StableHashingContext<'a>,
297-
hasher: &mut StableHasher<W>) {
298-
mem::discriminant(self).hash_stable(hcx, hasher);
299-
match *self {
300-
ty::Predicate::Trait(ref pred) => {
301-
pred.hash_stable(hcx, hasher);
302-
}
303-
ty::Predicate::Subtype(ref pred) => {
304-
pred.hash_stable(hcx, hasher);
305-
}
306-
ty::Predicate::RegionOutlives(ref pred) => {
307-
pred.hash_stable(hcx, hasher);
308-
}
309-
ty::Predicate::TypeOutlives(ref pred) => {
310-
pred.hash_stable(hcx, hasher);
311-
}
312-
ty::Predicate::Projection(ref pred) => {
313-
pred.hash_stable(hcx, hasher);
314-
}
315-
ty::Predicate::WellFormed(ty) => {
316-
ty.hash_stable(hcx, hasher);
317-
}
318-
ty::Predicate::ObjectSafe(def_id) => {
319-
def_id.hash_stable(hcx, hasher);
320-
}
321-
ty::Predicate::ClosureKind(def_id, closure_substs, closure_kind) => {
322-
def_id.hash_stable(hcx, hasher);
323-
closure_substs.hash_stable(hcx, hasher);
324-
closure_kind.hash_stable(hcx, hasher);
325-
}
326-
ty::Predicate::ConstEvaluatable(def_id, substs) => {
327-
def_id.hash_stable(hcx, hasher);
328-
substs.hash_stable(hcx, hasher);
329-
}
330-
}
269+
impl_stable_hash_for!(
270+
impl<'tcx> for enum ty::Predicate<'tcx> [ ty::Predicate ] {
271+
Trait(pred),
272+
Subtype(pred),
273+
RegionOutlives(pred),
274+
TypeOutlives(pred),
275+
Projection(pred),
276+
WellFormed(ty),
277+
ObjectSafe(def_id),
278+
ClosureKind(def_id, closure_substs, closure_kind),
279+
ConstEvaluatable(def_id, substs),
331280
}
332-
}
281+
);
333282

334283
impl<'a> HashStable<StableHashingContext<'a>> for ty::AdtFlags {
335284
fn hash_stable<W: StableHasherResult>(&self,
@@ -358,70 +307,39 @@ impl_stable_hash_for!(struct ty::FieldDef {
358307
vis,
359308
});
360309

361-
impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
362-
for ::mir::interpret::ConstValue<'gcx> {
363-
fn hash_stable<W: StableHasherResult>(&self,
364-
hcx: &mut StableHashingContext<'a>,
365-
hasher: &mut StableHasher<W>) {
366-
use mir::interpret::ConstValue::*;
367-
368-
mem::discriminant(self).hash_stable(hcx, hasher);
369-
370-
match *self {
371-
Unevaluated(def_id, substs) => {
372-
def_id.hash_stable(hcx, hasher);
373-
substs.hash_stable(hcx, hasher);
374-
}
375-
Scalar(val) => {
376-
val.hash_stable(hcx, hasher);
377-
}
378-
ScalarPair(a, b) => {
379-
a.hash_stable(hcx, hasher);
380-
b.hash_stable(hcx, hasher);
381-
}
382-
ByRef(id, alloc, offset) => {
383-
id.hash_stable(hcx, hasher);
384-
alloc.hash_stable(hcx, hasher);
385-
offset.hash_stable(hcx, hasher);
386-
}
387-
}
310+
impl_stable_hash_for!(
311+
impl<'tcx> for enum mir::interpret::ConstValue<'tcx> [ mir::interpret::ConstValue ] {
312+
Unevaluated(def_id, substs),
313+
Scalar(val),
314+
ScalarPair(a, b),
315+
ByRef(id, alloc, offset),
388316
}
389-
}
317+
);
390318

391-
impl<'a, Tag> HashStable<StableHashingContext<'a>>
392-
for ::mir::interpret::Pointer<Tag>
393-
where Tag: HashStable<StableHashingContext<'a>>
394-
{
395-
fn hash_stable<W: StableHasherResult>(&self,
396-
hcx: &mut StableHashingContext<'a>,
397-
hasher: &mut StableHasher<W>) {
398-
let ::mir::interpret::Pointer { alloc_id, offset, tag } = self;
399-
alloc_id.hash_stable(hcx, hasher);
400-
offset.hash_stable(hcx, hasher);
401-
tag.hash_stable(hcx, hasher);
319+
impl_stable_hash_for! {
320+
impl<Tag> for struct mir::interpret::Pointer<Tag> {
321+
alloc_id,
322+
offset,
323+
tag,
402324
}
403325
}
404326

405-
impl<'a, Tag> HashStable<StableHashingContext<'a>>
406-
for ::mir::interpret::Scalar<Tag>
407-
where Tag: HashStable<StableHashingContext<'a>>
408-
{
409-
fn hash_stable<W: StableHasherResult>(&self,
410-
hcx: &mut StableHashingContext<'a>,
411-
hasher: &mut StableHasher<W>) {
412-
use mir::interpret::Scalar::*;
327+
impl_stable_hash_for!(
328+
impl<Tag> for enum mir::interpret::Scalar<Tag> [ mir::interpret::Scalar ] {
329+
Bits { bits, size },
330+
Ptr(ptr),
331+
}
332+
);
413333

414-
mem::discriminant(self).hash_stable(hcx, hasher);
415-
match self {
416-
Bits { bits, size } => {
417-
bits.hash_stable(hcx, hasher);
418-
size.hash_stable(hcx, hasher);
419-
},
420-
Ptr(ptr) => ptr.hash_stable(hcx, hasher),
421-
}
334+
impl_stable_hash_for!(
335+
impl<'tcx, M> for enum mir::interpret::AllocType<'tcx, M> [ mir::interpret::AllocType ] {
336+
Function(instance),
337+
Static(def_id),
338+
Memory(mem),
422339
}
423-
}
340+
);
424341

342+
// AllocIds get resolved to whatever they point to (to be stable)
425343
impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::AllocId {
426344
fn hash_stable<W: StableHasherResult>(
427345
&self,
@@ -437,23 +355,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::AllocId {
437355
}
438356
}
439357

440-
impl<'a, 'gcx, M: HashStable<StableHashingContext<'a>>> HashStable<StableHashingContext<'a>>
441-
for mir::interpret::AllocType<'gcx, M> {
442-
fn hash_stable<W: StableHasherResult>(&self,
443-
hcx: &mut StableHashingContext<'a>,
444-
hasher: &mut StableHasher<W>) {
445-
use mir::interpret::AllocType::*;
446-
447-
mem::discriminant(self).hash_stable(hcx, hasher);
448-
449-
match *self {
450-
Function(instance) => instance.hash_stable(hcx, hasher),
451-
Static(def_id) => def_id.hash_stable(hcx, hasher),
452-
Memory(ref mem) => mem.hash_stable(hcx, hasher),
453-
}
454-
}
455-
}
456-
358+
// Allocations treat their relocations specially
457359
impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::Allocation {
458360
fn hash_stable<W: StableHasherResult>(
459361
&self,
@@ -485,7 +387,7 @@ impl_stable_hash_for!(enum mir::interpret::ErrorHandled {
485387
TooGeneric
486388
});
487389

488-
impl_stable_hash_for!(struct ::mir::interpret::FrameInfo {
390+
impl_stable_hash_for!(struct mir::interpret::FrameInfo {
489391
span,
490392
lint_root,
491393
location
@@ -499,124 +401,75 @@ impl_stable_hash_for!(struct ty::GenericPredicates<'tcx> {
499401
predicates
500402
});
501403

502-
impl<'a, 'gcx, O: HashStable<StableHashingContext<'a>>> HashStable<StableHashingContext<'a>>
503-
for ::mir::interpret::EvalErrorKind<'gcx, O> {
504-
fn hash_stable<W: StableHasherResult>(&self,
505-
hcx: &mut StableHashingContext<'a>,
506-
hasher: &mut StableHasher<W>) {
507-
use mir::interpret::EvalErrorKind::*;
508-
509-
mem::discriminant(&self).hash_stable(hcx, hasher);
510-
511-
match *self {
512-
FunctionArgCountMismatch |
513-
DanglingPointerDeref |
514-
DoubleFree |
515-
InvalidMemoryAccess |
516-
InvalidFunctionPointer |
517-
InvalidBool |
518-
InvalidNullPointerUsage |
519-
ReadPointerAsBytes |
520-
ReadBytesAsPointer |
521-
ReadForeignStatic |
522-
InvalidPointerMath |
523-
DeadLocal |
524-
StackFrameLimitReached |
525-
OutOfTls |
526-
TlsOutOfBounds |
527-
CalledClosureAsFunction |
528-
VtableForArgumentlessMethod |
529-
ModifiedConstantMemory |
530-
AssumptionNotHeld |
531-
InlineAsm |
532-
ReallocateNonBasePtr |
533-
DeallocateNonBasePtr |
534-
HeapAllocZeroBytes |
535-
Unreachable |
536-
ReadFromReturnPointer |
537-
UnimplementedTraitSelection |
538-
TypeckError |
539-
TooGeneric |
540-
DerefFunctionPointer |
541-
ExecuteMemory |
542-
OverflowNeg |
543-
RemainderByZero |
544-
DivisionByZero |
545-
GeneratorResumedAfterReturn |
546-
GeneratorResumedAfterPanic |
547-
ReferencedConstant |
548-
InfiniteLoop => {}
549-
ReadUndefBytes(offset) => offset.hash_stable(hcx, hasher),
550-
InvalidDiscriminant(val) => val.hash_stable(hcx, hasher),
551-
Panic { ref msg, ref file, line, col } => {
552-
msg.hash_stable(hcx, hasher);
553-
file.hash_stable(hcx, hasher);
554-
line.hash_stable(hcx, hasher);
555-
col.hash_stable(hcx, hasher);
556-
},
557-
MachineError(ref err) => err.hash_stable(hcx, hasher),
558-
FunctionAbiMismatch(a, b) => {
559-
a.hash_stable(hcx, hasher);
560-
b.hash_stable(hcx, hasher)
561-
},
562-
FunctionArgMismatch(a, b) => {
563-
a.hash_stable(hcx, hasher);
564-
b.hash_stable(hcx, hasher)
565-
},
566-
FunctionRetMismatch(a, b) => {
567-
a.hash_stable(hcx, hasher);
568-
b.hash_stable(hcx, hasher)
569-
},
570-
NoMirFor(ref s) => s.hash_stable(hcx, hasher),
571-
UnterminatedCString(ptr) => ptr.hash_stable(hcx, hasher),
572-
PointerOutOfBounds {
573-
ptr,
574-
access,
575-
allocation_size,
576-
} => {
577-
ptr.hash_stable(hcx, hasher);
578-
access.hash_stable(hcx, hasher);
579-
allocation_size.hash_stable(hcx, hasher)
580-
},
581-
InvalidBoolOp(bop) => bop.hash_stable(hcx, hasher),
582-
Unimplemented(ref s) => s.hash_stable(hcx, hasher),
583-
BoundsCheck { ref len, ref index } => {
584-
len.hash_stable(hcx, hasher);
585-
index.hash_stable(hcx, hasher)
586-
},
587-
Intrinsic(ref s) => s.hash_stable(hcx, hasher),
588-
InvalidChar(c) => c.hash_stable(hcx, hasher),
589-
AbiViolation(ref s) => s.hash_stable(hcx, hasher),
590-
AlignmentCheckFailed {
591-
required,
592-
has,
593-
} => {
594-
required.hash_stable(hcx, hasher);
595-
has.hash_stable(hcx, hasher)
596-
},
597-
ValidationFailure(ref s) => s.hash_stable(hcx, hasher),
598-
TypeNotPrimitive(ty) => ty.hash_stable(hcx, hasher),
599-
ReallocatedWrongMemoryKind(ref a, ref b) => {
600-
a.hash_stable(hcx, hasher);
601-
b.hash_stable(hcx, hasher)
602-
},
603-
DeallocatedWrongMemoryKind(ref a, ref b) => {
604-
a.hash_stable(hcx, hasher);
605-
b.hash_stable(hcx, hasher)
606-
},
607-
IncorrectAllocationInformation(a, b, c, d) => {
608-
a.hash_stable(hcx, hasher);
609-
b.hash_stable(hcx, hasher);
610-
c.hash_stable(hcx, hasher);
611-
d.hash_stable(hcx, hasher)
612-
},
613-
Layout(lay) => lay.hash_stable(hcx, hasher),
614-
HeapAllocNonPowerOfTwoAlignment(n) => n.hash_stable(hcx, hasher),
615-
PathNotFound(ref v) => v.hash_stable(hcx, hasher),
616-
Overflow(op) => op.hash_stable(hcx, hasher),
617-
}
404+
impl_stable_hash_for!(
405+
impl<'tcx, O> for enum mir::interpret::EvalErrorKind<'tcx, O>
406+
[ mir::interpret::EvalErrorKind ]
407+
{
408+
FunctionArgCountMismatch,
409+
DanglingPointerDeref,
410+
DoubleFree,
411+
InvalidMemoryAccess,
412+
InvalidFunctionPointer,
413+
InvalidBool,
414+
InvalidNullPointerUsage,
415+
ReadPointerAsBytes,
416+
ReadBytesAsPointer,
417+
ReadForeignStatic,
418+
InvalidPointerMath,
419+
DeadLocal,
420+
StackFrameLimitReached,
421+
OutOfTls,
422+
TlsOutOfBounds,
423+
CalledClosureAsFunction,
424+
VtableForArgumentlessMethod,
425+
ModifiedConstantMemory,
426+
AssumptionNotHeld,
427+
InlineAsm,
428+
ReallocateNonBasePtr,
429+
DeallocateNonBasePtr,
430+
HeapAllocZeroBytes,
431+
Unreachable,
432+
ReadFromReturnPointer,
433+
UnimplementedTraitSelection,
434+
TypeckError,
435+
TooGeneric,
436+
DerefFunctionPointer,
437+
ExecuteMemory,
438+
OverflowNeg,
439+
RemainderByZero,
440+
DivisionByZero,
441+
GeneratorResumedAfterReturn,
442+
GeneratorResumedAfterPanic,
443+
ReferencedConstant,
444+
InfiniteLoop,
445+
ReadUndefBytes(offset),
446+
InvalidDiscriminant(val),
447+
Panic { msg, file, line, col },
448+
MachineError(err),
449+
FunctionAbiMismatch(a, b),
450+
FunctionArgMismatch(a, b),
451+
FunctionRetMismatch(a, b),
452+
NoMirFor(s),
453+
UnterminatedCString(ptr),
454+
PointerOutOfBounds { ptr, access, allocation_size },
455+
InvalidBoolOp(bop),
456+
Unimplemented(s),
457+
BoundsCheck { len, index },
458+
Intrinsic(s),
459+
InvalidChar(c),
460+
AbiViolation(s),
461+
AlignmentCheckFailed { required, has },
462+
ValidationFailure(s),
463+
TypeNotPrimitive(ty),
464+
ReallocatedWrongMemoryKind(a, b),
465+
DeallocatedWrongMemoryKind(a, b),
466+
IncorrectAllocationInformation(a, b, c, d),
467+
Layout(lay),
468+
HeapAllocNonPowerOfTwoAlignment(n),
469+
PathNotFound(v),
470+
Overflow(op),
618471
}
619-
}
472+
);
620473

621474
impl_stable_hash_for!(enum mir::interpret::Lock {
622475
NoLock,
@@ -663,47 +516,18 @@ impl_stable_hash_for!(struct ty::GenericParamDef {
663516
kind
664517
});
665518

666-
impl<'a> HashStable<StableHashingContext<'a>> for ty::GenericParamDefKind {
667-
fn hash_stable<W: StableHasherResult>(&self,
668-
hcx: &mut StableHashingContext<'a>,
669-
hasher: &mut StableHasher<W>) {
670-
mem::discriminant(self).hash_stable(hcx, hasher);
671-
match *self {
672-
ty::GenericParamDefKind::Lifetime => {}
673-
ty::GenericParamDefKind::Type {
674-
has_default,
675-
ref object_lifetime_default,
676-
ref synthetic,
677-
} => {
678-
has_default.hash_stable(hcx, hasher);
679-
object_lifetime_default.hash_stable(hcx, hasher);
680-
synthetic.hash_stable(hcx, hasher);
681-
}
682-
}
683-
}
684-
}
685-
686-
impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>>
687-
for ::middle::resolve_lifetime::Set1<T>
688-
where T: HashStable<StableHashingContext<'a>>
689-
{
690-
fn hash_stable<W: StableHasherResult>(&self,
691-
hcx: &mut StableHashingContext<'a>,
692-
hasher: &mut StableHasher<W>) {
693-
use middle::resolve_lifetime::Set1;
519+
impl_stable_hash_for!(enum ty::GenericParamDefKind {
520+
Lifetime,
521+
Type { has_default, object_lifetime_default, synthetic },
522+
});
694523

695-
mem::discriminant(self).hash_stable(hcx, hasher);
696-
match *self {
697-
Set1::Empty |
698-
Set1::Many => {
699-
// Nothing to do.
700-
}
701-
Set1::One(ref value) => {
702-
value.hash_stable(hcx, hasher);
703-
}
704-
}
524+
impl_stable_hash_for!(
525+
impl<T> for enum ::middle::resolve_lifetime::Set1<T> [ ::middle::resolve_lifetime::Set1 ] {
526+
Empty,
527+
Many,
528+
One(value),
705529
}
706-
}
530+
);
707531

708532
impl_stable_hash_for!(enum ::middle::resolve_lifetime::LifetimeDefOrigin {
709533
ExplicitOrElided,
@@ -1250,7 +1074,7 @@ impl_stable_hash_for!(
12501074
);
12511075

12521076
impl_stable_hash_for!(
1253-
impl<'tcx> for struct infer::canonical::CanonicalVarValues<'tcx> {
1077+
struct infer::canonical::CanonicalVarValues<'tcx> {
12541078
var_values
12551079
}
12561080
);
@@ -1369,7 +1193,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::Goal<'tcx> {
13691193
}
13701194

13711195
impl_stable_hash_for!(
1372-
impl<'tcx> for struct traits::ProgramClause<'tcx> {
1196+
struct traits::ProgramClause<'tcx> {
13731197
goal, hypotheses, category
13741198
}
13751199
);
@@ -1404,7 +1228,7 @@ impl_stable_hash_for!(struct ty::subst::UserSubsts<'tcx> { substs, user_self_ty
14041228
impl_stable_hash_for!(struct ty::subst::UserSelfTy<'tcx> { impl_def_id, self_ty });
14051229

14061230
impl_stable_hash_for!(
1407-
impl<'tcx> for struct traits::Environment<'tcx> {
1231+
struct traits::Environment<'tcx> {
14081232
clauses,
14091233
}
14101234
);

‎src/librustc/macros.rs

+50-22
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ macro_rules! __impl_stable_hash_field {
7171

7272
#[macro_export]
7373
macro_rules! impl_stable_hash_for {
74+
// Enums
7475
// FIXME(mark-i-m): Some of these should be `?` rather than `*`. See the git blame and change
7576
// them back when `?` is supported again.
7677
(enum $enum_name:path {
@@ -81,12 +82,37 @@ macro_rules! impl_stable_hash_for {
8182
$( { $($named_field:ident $(-> $named_delegate:tt)*),* } )*
8283
),* $(,)*
8384
}) => {
84-
impl<'a, 'tcx> ::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>> for $enum_name {
85+
impl_stable_hash_for!(
86+
impl<> for enum $enum_name [ $enum_name ] { $( $variant
87+
$( ( $($field $(-> $delegate)*),* ) )*
88+
$( { $($named_field $(-> $named_delegate)*),* } )*
89+
),* }
90+
);
91+
};
92+
// We want to use the enum name both in the `impl ... for $enum_name` as well as for
93+
// importing all the variants. Unfortunately it seems we have to take the name
94+
// twice for this purpose
95+
(impl<$($lt:lifetime $(: $lt_bound:lifetime)* ),* $(,)* $($T:ident),* $(,)*>
96+
for enum $enum_name:path
97+
[ $enum_path:path ]
98+
{
99+
$( $variant:ident
100+
// this incorrectly allows specifying both tuple-like and struct-like fields, as in `Variant(a,b){c,d}`,
101+
// when it should be only one or the other
102+
$( ( $($field:ident $(-> $delegate:tt)*),* ) )*
103+
$( { $($named_field:ident $(-> $named_delegate:tt)*),* } )*
104+
),* $(,)*
105+
}) => {
106+
impl<'a, $($lt $(: $lt_bound)*,)* $($T,)*>
107+
::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>>
108+
for $enum_name
109+
where $($T: ::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>>),*
110+
{
85111
#[inline]
86112
fn hash_stable<W: ::rustc_data_structures::stable_hasher::StableHasherResult>(&self,
87113
__ctx: &mut $crate::ich::StableHashingContext<'a>,
88114
__hasher: &mut ::rustc_data_structures::stable_hasher::StableHasher<W>) {
89-
use $enum_name::*;
115+
use $enum_path::*;
90116
::std::mem::discriminant(self).hash_stable(__ctx, __hasher);
91117

92118
match *self {
@@ -100,9 +126,20 @@ macro_rules! impl_stable_hash_for {
100126
}
101127
}
102128
};
129+
// Structs
103130
// FIXME(mark-i-m): same here.
104131
(struct $struct_name:path { $($field:ident $(-> $delegate:tt)*),* $(,)* }) => {
105-
impl<'a, 'tcx> ::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>> for $struct_name {
132+
impl_stable_hash_for!(
133+
impl<'tcx> for struct $struct_name { $($field $(-> $delegate)*),* }
134+
);
135+
};
136+
(impl<$($lt:lifetime $(: $lt_bound:lifetime)* ),* $(,)* $($T:ident),* $(,)*> for struct $struct_name:path {
137+
$($field:ident $(-> $delegate:tt)*),* $(,)*
138+
}) => {
139+
impl<'a, $($lt $(: $lt_bound)*,)* $($T,)*>
140+
::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>> for $struct_name
141+
where $($T: ::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>>),*
142+
{
106143
#[inline]
107144
fn hash_stable<W: ::rustc_data_structures::stable_hasher::StableHasherResult>(&self,
108145
__ctx: &mut $crate::ich::StableHashingContext<'a>,
@@ -115,36 +152,27 @@ macro_rules! impl_stable_hash_for {
115152
}
116153
}
117154
};
155+
// Tuple structs
156+
// We cannot use normale parentheses here, the parser won't allow it
118157
// FIXME(mark-i-m): same here.
119158
(tuple_struct $struct_name:path { $($field:ident $(-> $delegate:tt)*),* $(,)* }) => {
120-
impl<'a, 'tcx> ::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>> for $struct_name {
121-
#[inline]
122-
fn hash_stable<W: ::rustc_data_structures::stable_hasher::StableHasherResult>(&self,
123-
__ctx: &mut $crate::ich::StableHashingContext<'a>,
124-
__hasher: &mut ::rustc_data_structures::stable_hasher::StableHasher<W>) {
125-
let $struct_name (
126-
$(ref $field),*
127-
) = *self;
128-
129-
$( __impl_stable_hash_field!($field, __ctx, __hasher $(, $delegate)*) );*
130-
}
131-
}
159+
impl_stable_hash_for!(
160+
impl<'tcx> for tuple_struct $struct_name { $($field $(-> $delegate)*),* }
161+
);
132162
};
133-
134-
(impl<$tcx:lifetime $(, $lt:lifetime $(: $lt_bound:lifetime)*)* $(, $T:ident)*> for struct $struct_name:path {
135-
$($field:ident $(-> $delegate:tt)*),* $(,)*
136-
}) => {
137-
impl<'a, $tcx, $($lt $(: $lt_bound)*,)* $($T,)*>
163+
(impl<$($lt:lifetime $(: $lt_bound:lifetime)* ),* $(,)* $($T:ident),* $(,)*>
164+
for tuple_struct $struct_name:path { $($field:ident $(-> $delegate:tt)*),* $(,)* }) => {
165+
impl<'a, $($lt $(: $lt_bound)*,)* $($T,)*>
138166
::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>> for $struct_name
139167
where $($T: ::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>>),*
140168
{
141169
#[inline]
142170
fn hash_stable<W: ::rustc_data_structures::stable_hasher::StableHasherResult>(&self,
143171
__ctx: &mut $crate::ich::StableHashingContext<'a>,
144172
__hasher: &mut ::rustc_data_structures::stable_hasher::StableHasher<W>) {
145-
let $struct_name {
173+
let $struct_name (
146174
$(ref $field),*
147-
} = *self;
175+
) = *self;
148176

149177
$( __impl_stable_hash_field!($field, __ctx, __hasher $(, $delegate)*) );*
150178
}

0 commit comments

Comments
 (0)
Please sign in to comment.