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

Add transmute_mut! macro #550

Merged
merged 1 commit into from
Oct 27, 2023
Merged

Add transmute_mut! macro #550

merged 1 commit into from
Oct 27, 2023

Conversation

jswrenn
Copy link
Collaborator

@jswrenn jswrenn commented Oct 26, 2023

This macro is like the existing transmute!, but it transmutes mutable references rather than values.

Issue #159

Copy link
Member

@joshlf joshlf left a comment

Choose a reason for hiding this comment

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

Just skimming; I'll take more of a look later once it's ready for review.

src/macro_util.rs Show resolved Hide resolved
@jswrenn jswrenn force-pushed the transmute_mut branch 2 times, most recently from 0662549 to a6e0d10 Compare October 26, 2023 18:00
@jswrenn jswrenn requested a review from joshlf October 26, 2023 18:16
src/lib.rs Outdated
Comment on lines 2023 to 2027
let u;

$crate::assert_size_eq!(t, u);

&u
Copy link
Member

Choose a reason for hiding this comment

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

Slight stylistic preference for grouping these together, but feel free to ignore this.

Same in the next branch.

Suggested change
let u;
$crate::assert_size_eq!(t, u);
&u
let u;
$crate::assert_size_eq!(t, u);
&u

src/lib.rs Outdated
Comment on lines 2121 to 2111
// Reborrow so that mutable references are supported too.
//
// In the rest of the comments, we refer only to `&T` since this
// reborrow ensures that `e` is an immutable reference.
let e = &mut *$e;
Copy link
Member

Choose a reason for hiding this comment

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

Is this necessary for transmute_mut!?

src/lib.rs Outdated
{
loop {}
}
transmute(&mut *e)
Copy link
Member

Choose a reason for hiding this comment

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

Can this not just be transmute(e)?

src/lib.rs Outdated
Comment on lines 2152 to 2156
let u;

$crate::assert_size_eq!(t, u);

&mut u
Copy link
Member

Choose a reason for hiding this comment

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

Same here, also optional.

Suggested change
let u;
$crate::assert_size_eq!(t, u);
&mut u
let u;
$crate::assert_size_eq!(t, u);
&mut u

src/lib.rs Outdated
Comment on lines 2168 to 2140
let mut u = unreachable!();

$crate::assert_align_gt_eq!(t, u);

&mut u
Copy link
Member

Choose a reason for hiding this comment

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

Same here, also optional.

Suggested change
let mut u = unreachable!();
$crate::assert_align_gt_eq!(t, u);
&mut u
let mut u = unreachable!();
$crate::assert_align_gt_eq!(t, u);
&mut u

src/lib.rs Outdated Show resolved Hide resolved
@jswrenn jswrenn force-pushed the transmute_mut branch 3 times, most recently from 4661929 to 9a6ec7a Compare October 27, 2023 16:44
joshlf
joshlf previously approved these changes Oct 27, 2023
joshlf
joshlf previously approved these changes Oct 27, 2023
This macro is like the existing `transmute!`, but it transmutes
mutable references rather than values.

Releasing 0.7.17

Issue #159
@joshlf joshlf added this pull request to the merge queue Oct 27, 2023
Merged via the queue into main with commit affe723 Oct 27, 2023
126 checks passed
@joshlf joshlf deleted the transmute_mut branch October 27, 2023 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants