From 6a81014ae9f169b4b6277b76052ea0a032049477 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 17 Apr 2020 11:03:20 +0200 Subject: [PATCH] test #[derive] on packed struct --- tests/run-pass/packed_struct.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/run-pass/packed_struct.rs b/tests/run-pass/packed_struct.rs index cb0bc985934..7aa53ef568f 100644 --- a/tests/run-pass/packed_struct.rs +++ b/tests/run-pass/packed_struct.rs @@ -1,5 +1,7 @@ #![feature(unsize, coerce_unsized)] +use std::collections::hash_map::DefaultHasher; +use std::hash::Hash; fn test_basic() { #[repr(packed)] @@ -114,10 +116,31 @@ fn test_static() { assert_eq!({FOO.i}, 42); } +fn test_derive() { + #[repr(packed)] + #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug)] + struct P { + a: usize, + b: u8, + c: usize, + } + + let x = P {a: 1usize, b: 2u8, c: 3usize}; + let y = P {a: 1usize, b: 2u8, c: 4usize}; + + let _clone = x.clone(); + assert!(x != y); + assert_eq!(x.partial_cmp(&y).unwrap(), x.cmp(&y)); + x.hash(&mut DefaultHasher::new()); + P::default(); + format!("{:?}", x); +} + fn main() { test_basic(); test_unsizing(); test_drop(); test_inner_packed(); test_static(); + test_derive(); }