Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

hns1971
Copy link

@hns1971 hns1971 commented Aug 27, 2025

Document borrowing rules for repr(packed) fields (E0793).

This documents the behavior implemented in rust-lang/rust#145419:

  • Disallow borrowing when the target’s ABI alignment exceeds the packed alignment (hard error E0793).
  • Allow borrowing when ABI alignment is ≤ the packed alignment.
  • For [T; N]/[T], alignment equals that of T, independent of N.

Includes examples for the allowed [u8; N] case and the disallowed [u16; N] case.

… arrays

- Add detailed explanation of alignment requirements when borrowing from packed structs
- Document that array/slice ABI alignment equals element type alignment
- Provide concrete examples showing allowed and forbidden borrowing patterns
- Clarify that E0793 error prevents creation of misaligned references
- Explain the conservative nature of alignment checks in generic contexts

This documentation helps developers understand the safety constraints
when working with packed structs containing arrays of different types.
@rustbot rustbot added the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label Aug 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: The marked PR is awaiting review from a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.