Bebop on Rust - "reference to packed field is unaligned" - ENTIRE CRATE BROKEN ON LATEST RUST
See original GitHub issueDescribe the bug Using a unaligned references to packed fields seems to be an issue in the Rust compiler. It generates warnings or even a compile error.
To Reproduce I used the following Bebop code:
struct IntVector {
int32 x;
int32 y;
}```
And it generated the following lines (among others):
#[allow(unaligned_references)]
fn _serialize_chained<W: ::std::io::Write>(&self, dest: &mut W) -> ::bebop::SeResult<usize> {
Ok(self.x._serialize_chained(dest)? + self.y._serialize_chained(dest)?)
}```
This generates the following warnings:
On the most recent nightly, the warnings turn into hard errors. This means using Bebop on Nightly is currently impossible.
Expected behavior No compile issues.
Bebop info:
- Version: 2.4.9
- Runtime: Rust
Desktop (please complete the following information):
- OS: Arch Linux
Issue Analytics
- State:
- Created 7 months ago
- Comments:11 (8 by maintainers)
Top Results From Across the Web
Tracking Issue for future-incompatibility warning ...
Fields of packed structs are not necessarily properly aligned. Hence creating a reference to a field of a packed struct can cause UB,...
Read more >My Rust project is broken all of the sudden
error[E0793 ]: reference to packed field is unaligned --> C:\Users\u\.cargo\registry\src\github.com-1eccb9ec823\ntapi-0.3.6\src\ntexapi.rs ...
Read more >Pointer to reference alignment : r/rust
a structure whose repr(align) is modified to be more tolerant than its fields can have a reference to it created with a more...
Read more >1240-repr-packed-unsafe-ref - The Rust RFC Book
Taking a reference into a struct marked repr(packed) should become unsafe , because it can lead to undefined behaviour. repr(packed) structs need to...
Read more >E0793 - Error codes index
Creating a reference to an insufficiently aligned packed field is undefined behavior and therefore disallowed. Using an unsafe block does not change ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Looks like they finally removed that feature. There is a recommended solution that should work: https://github.com/rust-lang/rust/issues/82523
I think we just need to generate the pointer and copy to a temporary, aligned place in memory. Basically every field after the first one in the struct needs to be copied so it can be read from aligned memory. If we want to be really fancy that only needs to be done for unaligned fields. But it would be a bit of work to code in only copying if needed and the compiler might already get rid of the extra copy for us.
Released. Give it a go @Yaron-Ha