Automatically implement `Unaligned` without custom derive
- Dominant language
- Rust
- Stars
- 2.6k
- Forks
- 179
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 29
Description
Once the [associated_const_equality](https://github.com/rust-lang/rust/issues/92827) feature is stabilized, we ought to be able to automatically implement `Unaligned` without needing a custom derive:
```rust
#![feature(associated_const_equality)]
unsafe trait Align {
const ALIGN: usize;
}
unsafe impl Align for T {
const ALIGN: usize = core::mem::align_of::();
}
unsafe trait Unaligned {}
unsafe impl> Unaligned for T {}
```
Note that we may not want to do this - it would mean that types would no longer need to opt-in to implementing `Unaligned` as they do today. This probably isn't a huge deal since you can't do anything with `Unaligned` on its own (`FromBytes` and `AsBytes` are the traits that really unlock the ability to muck with a type's internal state), but at a minimum it would make the API inconsistent. One option would be to just make `Align` a bound so that `Unaligned` could become a safe trait that just represents the fact of opting-in:
```rust
trait Unaligned: Align {}
```
Contributor guide
Assessment
This issue has not been assessed yet.