Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use core::mem::align_of to determine proper type aligment #57

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jamessan
Copy link

@jamessan jamessan commented May 7, 2024

On i686, the u64 test sometimes fails because the required alignment is
4-bytes, not 8-bytes.

Closes #56
Co-authored-by: Peter Michael Green [email protected]

On i686, the u64 test sometimes fails because the required alignment is
4-bytes, not 8-bytes.

Closes Gankra#56
Co-authored-by: Peter Michael Green <[email protected]>
@@ -2657,13 +2657,13 @@ mod tests {
#[test]
fn test_data_ptr_alignment() {
let v = ThinVec::<u16>::new();
assert!(v.data_raw() as usize % 2 == 0);
assert!(v.data_raw() as usize % core::mem::align_of::<u16>() == 0);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is prelude now:

Suggested change
assert!(v.data_raw() as usize % core::mem::align_of::<u16>() == 0);
assert!(v.data_raw() as usize % align_of::<u16>() == 0);


let v = ThinVec::<u32>::new();
assert!(v.data_raw() as usize % 4 == 0);
assert!(v.data_raw() as usize % core::mem::align_of::<u32>() == 0);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert!(v.data_raw() as usize % core::mem::align_of::<u32>() == 0);
assert!(v.data_raw() as usize % align_of::<u32>() == 0);


let v = ThinVec::<u64>::new();
assert!(v.data_raw() as usize % 8 == 0);
assert!(v.data_raw() as usize % core::mem::align_of::<u64>() == 0);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert!(v.data_raw() as usize % core::mem::align_of::<u64>() == 0);
assert!(v.data_raw() as usize % align_of::<u64>() == 0);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"cargo test --features=serde" fails on i686
2 participants