Skip to content

Commit 56d5be1

Browse files
committed
Update hdf5-derive tests re: #[repr(packed)
1 parent ed97be6 commit 56d5be1

File tree

7 files changed

+54
-16
lines changed

7 files changed

+54
-16
lines changed

hdf5-derive/tests/compile-fail/struct-c-repr.stderr

Lines changed: 0 additions & 7 deletions
This file was deleted.

hdf5-derive/tests/compile-fail/struct-c-repr.rs renamed to hdf5-derive/tests/compile-fail/struct-no-repr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use hdf5_derive::H5Type;
33

44
#[derive(H5Type)]
55
//~^ ERROR proc-macro derive
6-
//~^^ HELP H5Type requires #[repr(C)] for structs
6+
//~^^ HELP H5Type requires #[repr(C)] or #[repr(packed)] for structs
77
struct Foo {
88
bar: i64,
99
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
error: proc-macro derive panicked
2+
--> $DIR/struct-no-repr.rs:4:10
3+
|
4+
4 | #[derive(H5Type)]
5+
| ^^^^^^
6+
|
7+
= help: message: H5Type requires #[repr(C)] or #[repr(packed)] for structs

hdf5-derive/tests/compile-fail/tuple-struct-c-repr.stderr

Lines changed: 0 additions & 7 deletions
This file was deleted.

hdf5-derive/tests/compile-fail/tuple-struct-c-repr.rs renamed to hdf5-derive/tests/compile-fail/tuple-struct-no-repr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use hdf5_derive::H5Type;
33

44
#[derive(H5Type)]
55
//~^ ERROR proc-macro derive
6-
//~^^ HELP H5Type requires #[repr(C)] for structs
6+
//~^^ HELP H5Type requires #[repr(C)] or #[repr(packed)] for structs
77
struct Foo(i64);
88

99
fn main() {}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
error: proc-macro derive panicked
2+
--> $DIR/tuple-struct-no-repr.rs:4:10
3+
|
4+
4 | #[derive(H5Type)]
5+
| ^^^^^^
6+
|
7+
= help: message: H5Type requires #[repr(C)] or #[repr(packed)] for structs

hdf5-derive/tests/test.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// due to compiler wrongfully complaining re: Copy impl missing for packed struct
2+
#![allow(unaligned_references)]
3+
14
#[macro_use]
25
extern crate hdf5_derive;
36

@@ -30,6 +33,41 @@ struct B {
3033
#[repr(C)]
3134
struct T(i64, pub u64);
3235

36+
#[derive(H5Type, Copy, Clone)]
37+
#[repr(packed)]
38+
struct P1 {
39+
x: u8,
40+
y: u64,
41+
}
42+
43+
#[derive(H5Type, Copy, Clone)]
44+
#[repr(packed)]
45+
struct P2(i8, u32);
46+
47+
#[test]
48+
fn test_compound_packed() {
49+
assert_eq!(
50+
P1::type_descriptor(),
51+
TD::Compound(CompoundType {
52+
fields: vec![
53+
CompoundField::typed::<u8>("x", 0, 0),
54+
CompoundField::typed::<u64>("y", 1, 1),
55+
],
56+
size: 9,
57+
})
58+
);
59+
assert_eq!(
60+
P2::type_descriptor(),
61+
TD::Compound(CompoundType {
62+
fields: vec![
63+
CompoundField::typed::<i8>("0", 0, 0),
64+
CompoundField::typed::<u32>("1", 1, 1),
65+
],
66+
size: 5,
67+
})
68+
);
69+
}
70+
3371
#[test]
3472
fn test_compound_simple() {
3573
assert_eq!(

0 commit comments

Comments
 (0)