Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce Src: FromBytes in try_transmute_mut! #2229

Merged
merged 1 commit into from
Feb 4, 2025
Merged

Conversation

jswrenn
Copy link
Collaborator

@jswrenn jswrenn commented Jan 12, 2025

Ensures that the source reference remains valid after the transmuted (and possibly mutated) destination is dropped.

Makes progress on #2226

@jswrenn jswrenn requested a review from joshlf January 12, 2025 00:34
@jswrenn jswrenn force-pushed the fix-try_transmute_mut branch from 69ad562 to 2bf3099 Compare January 12, 2025 00:39
@jswrenn
Copy link
Collaborator Author

jswrenn commented Jan 12, 2025

(Have a killer headache tonight; I'll finish this up first thing tomorrow.)

@jswrenn jswrenn force-pushed the fix-try_transmute_mut branch from 2bf3099 to 4fdd646 Compare January 12, 2025 12:53
@codecov-commenter
Copy link

codecov-commenter commented Jan 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.46%. Comparing base (2c8ef74) to head (018a552).
Report is 10 commits behind head on v0.8.x.

Additional details and impacted files
@@            Coverage Diff             @@
##           v0.8.x    #2229      +/-   ##
==========================================
+ Coverage   87.42%   87.46%   +0.04%     
==========================================
  Files          16       16              
  Lines        6115     6136      +21     
==========================================
+ Hits         5346     5367      +21     
  Misses        769      769              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jswrenn jswrenn force-pushed the fix-try_transmute_mut branch from 4fdd646 to cc95f58 Compare January 27, 2025 22:41
src/macros.rs Outdated
@@ -577,7 +577,7 @@ macro_rules! try_transmute_ref {
/// ```ignore
/// fn try_transmute_mut<Src, Dst>(src: &mut Src) -> Result<&mut Dst, ValidityError<&mut Src, Dst>>
/// where
/// Src: IntoBytes,
/// Src: FromByte + IntoBytes,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// Src: FromByte + IntoBytes,
/// Src: FromBytes + IntoBytes,

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

src/macros.rs Outdated
Comment on lines 891 to 894
let array_of_bools = &mut [false, true, false, true, false, true, false, true];
let array_of_arrays = &mut [[0u8, 1], [0, 1], [0, 1], [0, 1]];
let x: Result<&mut [[u8; 2]; 4], _> = try_transmute_mut!(array_of_bools);
assert_eq!(x, Ok(array_of_arrays));
Copy link
Member

Choose a reason for hiding this comment

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

Can we keep this test and use u8 instead of bool?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ensures that the source reference remains valid after the
transmuted (and possibly mutated)  destination is dropped.

Makes progress on #2226
@jswrenn jswrenn force-pushed the fix-try_transmute_mut branch from cc95f58 to 018a552 Compare February 4, 2025 16:53
@jswrenn jswrenn requested a review from joshlf February 4, 2025 16:55
@jswrenn jswrenn enabled auto-merge February 4, 2025 16:55
@jswrenn jswrenn added this pull request to the merge queue Feb 4, 2025
Merged via the queue into v0.8.x with commit 118b6f3 Feb 4, 2025
87 checks passed
@jswrenn jswrenn deleted the fix-try_transmute_mut branch February 4, 2025 17:58
@joshlf joshlf mentioned this pull request Feb 4, 2025
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants