You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Bytes documentation describes reference-counted backing storage such as Arc<[u8]>, but Bytes had no From<Arc<[u8]>> implementation. The documented conversion therefore failed to compile.
Cause
Bytes::from_owner already supports owning any AsRef<[u8]> + Send + 'static value, but the standard Arc<[u8]> conversion was missing from the From implementations.
Fix
Add a target_has_atomic = "ptr"-gated From<alloc::sync::Arc<[u8]>> for Bytes implementation that delegates to Bytes::from_owner. Add a regression test that drops the original Arc, verifies the bytes remain usable, and checks that the data pointer is preserved.
Tests
cargo fmt --all -- --check
cargo test --test test_bytes from_arc -- --nocapture
cargo test --all-features
cargo check --no-default-features
cargo clippy --all-features --lib (passes with existing warnings)
git diff --check
Independent pre-fix reproduction failed with the missing From<Arc<[u8]>> trait implementation; the same reproduction compiles after the fix.
Limitations
The checks ran on Windows. Linux/macOS, cross-target, no-atomic-target, nightly/Miri, and the full CI platform matrix were not run locally.
cargo clippy --all-features --all-targets -- -D warnings remains red on clean HEAD because of pre-existing diagnostics in unrelated code; the same baseline failure was reproduced before this change.
The conversion is gated on pointer-width atomics because alloc::sync::Arc is unavailable on targets without atomic pointers.
AI assistance
This pull request was prepared with AI assistance. AI was used for repository and issue triage, reproduction, implementation, and test planning; the behavior, patch, and test results were independently checked on the remote host.
Added the requested #[cfg(target_has_atomic = "ptr")] guard to the new Arc conversion test. cargo test --test test_bytes passes all 120 tests on both the G drive Windows clone and macOS; cargo fmt --all -- --check and git diff --check pass. The CI run for this head is action_required, and my account cannot approve fork PR runs. Could a repository maintainer approve it?
The minrust run exposed that cfg(target_has_atomic = "ptr") is not stable on this crate's declared Rust 1.57 MSRV, including the new test gate. I replaced it with a tiny build.rs that reads Cargo's CARGO_CFG_TARGET_HAS_ATOMIC and emits a bytes_has_atomic_ptr cfg; the library import, impl, and test now share that gate, so the API remains disabled on targets without pointer atomics without raising MSRV.
Validation on Windows with RUSTFLAGS=-Dwarnings: cargo check --no-default-features passes, cargo test --test test_bytes passes (120 tests), and cargo fmt --all -- --check plus git diff --check pass. The new upstream CI run is action_required and has not started (run); could you approve it and review the update when convenient?
This branch has not been deployed
No deployments
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
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 #685
Problem
The
Bytesdocumentation describes reference-counted backing storage such asArc<[u8]>, butByteshad noFrom<Arc<[u8]>>implementation. The documented conversion therefore failed to compile.Cause
Bytes::from_owneralready supports owning anyAsRef<[u8]> + Send + 'staticvalue, but the standardArc<[u8]>conversion was missing from theFromimplementations.Fix
Add a
target_has_atomic = "ptr"-gatedFrom<alloc::sync::Arc<[u8]>> for Bytesimplementation that delegates toBytes::from_owner. Add a regression test that drops the originalArc, verifies the bytes remain usable, and checks that the data pointer is preserved.Tests
cargo fmt --all -- --checkcargo test --test test_bytes from_arc -- --nocapturecargo test --all-featurescargo check --no-default-featurescargo clippy --all-features --lib(passes with existing warnings)git diff --checkFrom<Arc<[u8]>>trait implementation; the same reproduction compiles after the fix.Limitations
cargo clippy --all-features --all-targets -- -D warningsremains red on clean HEAD because of pre-existing diagnostics in unrelated code; the same baseline failure was reproduced before this change.alloc::sync::Arcis unavailable on targets without atomic pointers.AI assistance
This pull request was prepared with AI assistance. AI was used for repository and issue triage, reproduction, implementation, and test planning; the behavior, patch, and test results were independently checked on the remote host.