Skip to content

Add missing safety requirement - #25269

Open
yilin0518 wants to merge 1 commit into
bevyengine:mainfrom
yilin0518:fix_write_to
Open

Add missing safety requirement#25269
yilin0518 wants to merge 1 commit into
bevyengine:mainfrom
yilin0518:fix_write_to

Conversation

@yilin0518

Copy link
Copy Markdown
Contributor

Objective

  • Document the complete safety requirements of MovingPtr::write_to.
  • The method uses ptr::copy_nonoverlapping, so callers must ensure that the source and destination memory regions do not overlap.

Solution

  • Update the MovingPtr::write_to safety documentation to require non-overlapping source and destination regions.
  • Clarify the corresponding internal safety comment for the copy_nonoverlapping call.
  • This is a documentation-only change and does not alter runtime behavior.

Testing

  • Not run, since this PR only updates safety documentation and internal comments.
  • Reviewers can verify the changes with:
cargo test -p bevy_ptr
  • No platform-specific testing is required.

@kfc35 kfc35 added C-Docs An addition or correction to our documentation S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Aug 2, 2026
Comment thread crates/bevy_ptr/src/lib.rs Outdated
/// # Safety
/// - `dst` must be valid for writes.
/// - If the `A` type parameter is [`Aligned`] then `dst` must be [properly aligned] for `T`.
/// - The `size_of::<T>()` byte regions beginning at `dst` and at this pointer's

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since this is only for a single element, the requirement could be reduced to self and dst not being the same.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have updated the wording of this requirement. Thank you for your suggestion!

Comment thread crates/bevy_ptr/src/lib.rs Outdated
// - As `A` is `Aligned`, the caller is required to ensure that `dst` is aligned and `src` must
// be aligned by the type's invariants.
// - The caller is required to ensure that the memory region covered by `src`
// and `dst`, fitting up to `count` elements do not overlap.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

count is always 1 here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-Docs An addition or correction to our documentation S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants