Skip to content

Commit 0b79fac

Browse files
committed
tests: track the diagnostics of packed structs and field accessors
Signed-off-by: Benno Lossin <lossin@kernel.org>
1 parent 8109ffe commit 0b79fac

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
use pin_init::*;
2+
3+
#[repr(C, packed)]
4+
struct Foo {
5+
a: i8,
6+
b: i32,
7+
}
8+
9+
fn main() {
10+
let _ = init!(Foo { a: -42, b: 42 });
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error[E0793]: reference to field of packed struct is unaligned
2+
--> tests/ui/compile-fail/init/packed_struct.rs:10:13
3+
|
4+
10 | let _ = init!(Foo { a: -42, b: 42 });
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: this struct is 1-byte aligned, but the type of this field may require higher alignment
8+
= note: creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
9+
= help: copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)
10+
= note: this error originates in the macro `init` (in Nightly builds, run with -Z macro-backtrace for more info)

0 commit comments

Comments
 (0)