From df0ceaab6fe52038b372a881d450fe3b672726d1 Mon Sep 17 00:00:00 2001 From: Chris Tsang Date: Sat, 1 Jun 2024 18:45:34 +0100 Subject: [PATCH] recursive enum --- tests/hash_enum.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/hash_enum.rs b/tests/hash_enum.rs index c7fd056..bf3494c 100644 --- a/tests/hash_enum.rs +++ b/tests/hash_enum.rs @@ -405,3 +405,42 @@ fn bound_3() { assert_ne!(unit_hash, struct_hash); assert_ne!(struct_hash, tuple_hash); } + +#[test] +fn recursive_1() { + #[derive(Educe)] + #[educe(Hash)] + enum Enum { + Unit, + Unit2, + Boxed(Box), + } + + let unit_hash = { + let mut hasher = DefaultHasher::new(); + + Enum::Unit.hash(&mut hasher); + + hasher.finish() + }; + + let unit2_hash = { + let mut hasher = DefaultHasher::new(); + + Enum::Unit2.hash(&mut hasher); + + hasher.finish() + }; + + let unit3_hash = { + let mut hasher = DefaultHasher::new(); + + Enum::Boxed(Box::new(Enum::Unit)).hash(&mut hasher); + + hasher.finish() + }; + + assert_ne!(unit_hash, unit2_hash); + assert_ne!(unit_hash, unit3_hash); + assert_ne!(unit2_hash, unit3_hash); +} \ No newline at end of file