Skip to content

fix(vsimd): fix debug_assert lint error in transmute_copy#69

Merged
Nugine merged 4 commits into
mainfrom
copilot/fix-failing-github-actions-job
Jun 8, 2026
Merged

fix(vsimd): fix debug_assert lint error in transmute_copy#69
Nugine merged 4 commits into
mainfrom
copilot/fix-failing-github-actions-job

Conversation

Copilot AI commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Fixes a clippy lint error and addresses an alignment safety issue in the transmute_copy() function.

Changes

  • Replaced debug_assert! with debug_assert_eq! for size comparison in transmute_copy()
  • Added alignment assertion to prevent UB when B has stricter alignment than A

Before

debug_assert!(core::mem::size_of::<A>() == core::mem::size_of::<B>());
*(core::ptr::from_ref::<A>(a) as *const B)

After

debug_assert_eq!(core::mem::size_of::<A>(), core::mem::size_of::<B>());
debug_assert!(core::mem::align_of::<B>() <= core::mem::align_of::<A>());
*(core::ptr::from_ref::<A>(a) as *const B)

The alignment assertion ensures that the pointer cast is safe by verifying B's alignment requirement does not exceed A's. Since a reference to A is guaranteed to be aligned for A, if B has equal or weaker alignment, the cast is safe.

Copilot AI requested a review from Nugine June 8, 2026 04:08
Copilot finished work on behalf of Nugine June 8, 2026 04:08
@Nugine Nugine marked this pull request as ready for review June 8, 2026 04:10
Copilot AI review requested due to automatic review settings June 8, 2026 04:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a Clippy lint failure in vsimd by switching a size equality check from debug_assert! to the more appropriate debug_assert_eq! within an unsafe transmute helper.

Changes:

  • Replaced debug_assert!(size_of::<A>() == size_of::<B>()) with debug_assert_eq!(size_of::<A>(), size_of::<B>()) in transmute_copy<A, B>().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/vsimd/src/tools.rs
Copilot AI changed the title Fix debug_assert lint error in vsimd Fix alignment UB and debug_assert lint error in transmute_copy Jun 8, 2026
Copilot finished work on behalf of Nugine June 8, 2026 04:19
@Nugine Nugine changed the title Fix alignment UB and debug_assert lint error in transmute_copy fix(vsimd): fix debug_assert lint error in transmute_copy Jun 8, 2026
@Nugine Nugine merged commit 5ba5d15 into main Jun 8, 2026
9 checks passed
@Nugine Nugine deleted the copilot/fix-failing-github-actions-job branch June 8, 2026 04:28
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.

3 participants