Skip to content

Commit

Permalink
more test ref-to-packed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed May 25, 2020
1 parent c79535e commit 061773f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/test/ui/lint/packed_reference.rs
Expand Up @@ -12,6 +12,8 @@ fn main() {
let good = Good { data: &0, data2: [&0, &0], aligned: [0; 32] };

let _ = &good.data; //~ ERROR reference to packed field
let _ = &good.data as *const _; //~ ERROR reference to packed field
let _: *const _ = &good.data; //~ ERROR reference to packed field
let _ = &good.data2[0]; //~ ERROR reference to packed field
let _ = &*good.data; // ok, behind a pointer
let _ = &good.aligned; // ok, has align 1
Expand Down
18 changes: 17 additions & 1 deletion src/test/ui/lint/packed_reference.stderr
Expand Up @@ -14,10 +14,26 @@ LL | #![deny(packed_references)]
error: reference to packed field is not allowed
--> $DIR/packed_reference.rs:15:17
|
LL | let _ = &good.data as *const _;
| ^^^^^^^^^^
|
= note: fields of packed structs might be misaligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)

error: reference to packed field is not allowed
--> $DIR/packed_reference.rs:16:27
|
LL | let _: *const _ = &good.data;
| ^^^^^^^^^^
|
= note: fields of packed structs might be misaligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)

error: reference to packed field is not allowed
--> $DIR/packed_reference.rs:17:17
|
LL | let _ = &good.data2[0];
| ^^^^^^^^^^^^^^
|
= note: fields of packed structs might be misaligned, and creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)

error: aborting due to 2 previous errors
error: aborting due to 4 previous errors

0 comments on commit 061773f

Please sign in to comment.