Skip to content

Commit 562d602

Browse files
committed
Auto merge of #1343 - RalfJung:derive-packed, r=RalfJung
test #[derive] on packed struct
2 parents 9b4af73 + 6a81014 commit 562d602

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/run-pass/packed_struct.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![feature(unsize, coerce_unsized)]
22

3+
use std::collections::hash_map::DefaultHasher;
4+
use std::hash::Hash;
35

46
fn test_basic() {
57
#[repr(packed)]
@@ -114,10 +116,31 @@ fn test_static() {
114116
assert_eq!({FOO.i}, 42);
115117
}
116118

119+
fn test_derive() {
120+
#[repr(packed)]
121+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Debug)]
122+
struct P {
123+
a: usize,
124+
b: u8,
125+
c: usize,
126+
}
127+
128+
let x = P {a: 1usize, b: 2u8, c: 3usize};
129+
let y = P {a: 1usize, b: 2u8, c: 4usize};
130+
131+
let _clone = x.clone();
132+
assert!(x != y);
133+
assert_eq!(x.partial_cmp(&y).unwrap(), x.cmp(&y));
134+
x.hash(&mut DefaultHasher::new());
135+
P::default();
136+
format!("{:?}", x);
137+
}
138+
117139
fn main() {
118140
test_basic();
119141
test_unsizing();
120142
test_drop();
121143
test_inner_packed();
122144
test_static();
145+
test_derive();
123146
}

0 commit comments

Comments
 (0)