runtime: clone_from_slice accepts array operands (#39) - #43
Closed
shuaimu wants to merge 1 commit into
Closed
Conversation
Fixes #39. Rust arrays coerce to slices, so 'raw.copy_from_slice( &buf[..4])' has a [u8; 4] destination; the emitted call passes the std::array (and often a std::array rvalue source from the to_le_bytes bit_cast lowering) directly, which cannot deduce the span-span core overload. Add boundary adapters viewing array operands through spans (dst array + src array/span, span dst + array src) and dispatching to the core. A span over an rvalue source array is consumed within the same full-expression, so it cannot dangle. Real-world case: srpc.wire.frame (mako crates/srpc) write_header / peek_header -- the module compiles under clang 22 with this change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This was referenced Jul 29, 2026
Owner
Author
|
Full-stack verification: with #41 + #42 + #43 + #45 merged locally (verify-stack), the srpc crate (mako |
Owner
Author
|
Closing — PRs should not have been opened without explicit instruction. The fix remains on this branch for review whenever wanted. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #39. Rust arrays coerce to slices, so
raw.copy_from_slice(&buf[..4])has a[u8; N]destination; the emitted call passes thestd::array(and often astd::arrayrvalue source, produced by theto_le_bytesbit_cast lowering) directly, which cannot deduce the span-span core overload.Fix: boundary adapters in
array.hppviewing array operands through spans (array dst + array/span src, span dst + array src) and dispatching to the existing core. A span over an rvalue source array is consumed within the same full-expression, so it cannot dangle.Verified:
srpc.wire.frame(makocrates/srpc) — previously failing atwrite_header'srusty::clone_from_slice(out_buf, <bit_cast array>)— compiles under clang 22 with this change (no transpiler change needed).🤖 Generated with Claude Code
https://claude.ai/code/session_01N9DLY5SDRooowERihphNQ1