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_ref! and transmute_mut! macros #159

Closed
joshlf opened this issue Feb 16, 2023 · 1 comment
Closed

Add transmute_ref! and transmute_mut! macros #159

joshlf opened this issue Feb 16, 2023 · 1 comment
Labels
compatibility-nonbreaking Changes that are (likely to be) non-breaking

Comments

@joshlf
Copy link
Member

joshlf commented Feb 16, 2023

We currently have a transmute! macro which safely transmutes an AsBytes type into a FromBytes type. We should add macros which do the same for mutable and immutable references.

A candidate implementation of transmute_ref! is in #183. We may also want to ditch it in favor of something based on this approach suggested by @gootorov, but we'd need to first confirm that invalid uses are guaranteed to generate compile-time rather than runtime errors (rust-lang/rust#112090). EDIT: Based on the discussion there, it seems that there is such a guarantee, but we'd need to be careful about how we structure things to make sure that we actually write code that benefits from that guarantee.

Note that rust-lang/rust#112301 will likely make @gootorov's technique a bit annoying for users (although the error messages are way better than the existing technique, and the implementation is way simpler, so IMO it's still worth it on balance).

EDIT: Another issue with this approach is that generic APIs might never fail until they're used by a downstream crate since monomorphization only happens at that point. One potential solution would be to keep the functions #[doc(hidden)] and provide macros to invoke them which also call mem::transmute in order to ensure that they can only be called from type-concrete contexts. This would artificially hamstring the API, but the footgun is big enough that it might be worth it.

joshlf added a commit that referenced this issue May 25, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Issue #159
joshlf added a commit that referenced this issue May 25, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Issue #159
joshlf added a commit that referenced this issue May 25, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Issue #159
joshlf added a commit that referenced this issue May 25, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Issue #159
joshlf added a commit that referenced this issue May 25, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Issue #159
joshlf added a commit that referenced this issue May 25, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Issue #159
joshlf added a commit that referenced this issue May 25, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Issue #159
joshlf added a commit that referenced this issue May 25, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Issue #159
joshlf added a commit that referenced this issue May 25, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Issue #159
joshlf added a commit that referenced this issue May 26, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Issue #159
joshlf added a commit that referenced this issue May 26, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Issue #159
joshlf added a commit that referenced this issue May 26, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Issue #159
joshlf added a commit that referenced this issue May 26, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Issue #159
joshlf added a commit that referenced this issue May 26, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Issue #159
joshlf added a commit that referenced this issue May 26, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Issue #159
joshlf added a commit that referenced this issue May 26, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Issue #159
joshlf added a commit that referenced this issue May 26, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Issue #159
joshlf added a commit that referenced this issue May 26, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Issue #159
joshlf added a commit that referenced this issue May 26, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Issue #159
joshlf added a commit that referenced this issue May 26, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Issue #159
joshlf added a commit that referenced this issue May 26, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Issue #159
joshlf added a commit that referenced this issue May 27, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Issue #159

Co-authored-by: Jack Wrenn <jswrenn@amazon.com>
@joshlf joshlf added the compatibility-nonbreaking Changes that are (likely to be) non-breaking label Aug 12, 2023
@joshlf joshlf mentioned this issue Aug 20, 2023
joshlf added a commit that referenced this issue Oct 4, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Issue #159
joshlf added a commit that referenced this issue Oct 4, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Issue #159
joshlf added a commit that referenced this issue Oct 4, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Issue #159
joshlf added a commit that referenced this issue Oct 4, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Issue #159
joshlf added a commit that referenced this issue Oct 4, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Issue #159
joshlf added a commit that referenced this issue Oct 4, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Release 0.7.8.

Issue #159
joshlf added a commit that referenced this issue Oct 4, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Release 0.7.8.

Issue #159
joshlf added a commit that referenced this issue Oct 4, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Release 0.7.8.

Issue #159
joshlf added a commit that referenced this issue Oct 4, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Release 0.7.8.

Issue #159
joshlf added a commit that referenced this issue Oct 4, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Release 0.7.8.

Issue #159
joshlf added a commit that referenced this issue Oct 4, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Note that, during development, we encountered a bug in either Rust or
trybuild, reported at rust-lang/rust#116433.
This PR works around this issue by manually copying the expected output
as reported in CI. This is a temporary fix, and will need to be
addressed soon, as it has the effect of making local development a
slightly more manual process.

Release 0.7.8.

Issue #159
joshlf added a commit that referenced this issue Oct 4, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Note that, during development, we encountered a bug in either Rust or
trybuild, reported at rust-lang/rust#116433.
This PR works around this issue by manually copying the expected output
as reported in CI. This is a temporary fix, and will need to be
addressed soon, as it has the effect of making local development a
slightly more manual process.

Release 0.7.8.

Issue #159
joshlf added a commit that referenced this issue Oct 4, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Note that, during development, we encountered a bug in either Rust or
trybuild, reported at rust-lang/rust#116433.
This PR works around this issue by manually copying the expected output
as reported in CI. This is a temporary fix, and will need to be
addressed soon, as it has the effect of making local development a
slightly more manual process.

Release 0.7.8.

Issue #159
joshlf added a commit that referenced this issue Oct 4, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Release 0.7.8.

Issue #159
github-merge-queue bot pushed a commit that referenced this issue Oct 4, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Release 0.7.8.

Issue #159
samuelselleck pushed a commit to samuelselleck/zerocopy that referenced this issue Oct 13, 2023
This macro is like the existing `transmute!`, but it transmutes
immutable references rather than values.

Release 0.7.8.

Issue google#159
jswrenn added a commit that referenced this issue Oct 26, 2023
This macro is like the existing `transmute!`, but it transmutes
mutable references rather than values.

Issue #159
jswrenn added a commit that referenced this issue Oct 26, 2023
This macro is like the existing `transmute!`, but it transmutes
mutable references rather than values.

Issue #159
jswrenn added a commit that referenced this issue Oct 26, 2023
This macro is like the existing `transmute!`, but it transmutes
mutable references rather than values.

Issue #159
jswrenn added a commit that referenced this issue Oct 26, 2023
This macro is like the existing `transmute!`, but it transmutes
mutable references rather than values.

Issue #159
jswrenn added a commit that referenced this issue Oct 27, 2023
This macro is like the existing `transmute!`, but it transmutes
mutable references rather than values.

Issue #159
jswrenn added a commit that referenced this issue Oct 27, 2023
This macro is like the existing `transmute!`, but it transmutes
mutable references rather than values.

Issue #159
jswrenn added a commit that referenced this issue Oct 27, 2023
This macro is like the existing `transmute!`, but it transmutes
mutable references rather than values.

Issue #159
jswrenn added a commit that referenced this issue Oct 27, 2023
This macro is like the existing `transmute!`, but it transmutes
mutable references rather than values.

Issue #159
jswrenn added a commit that referenced this issue Oct 27, 2023
This macro is like the existing `transmute!`, but it transmutes
mutable references rather than values.

Issue #159
jswrenn added a commit that referenced this issue Oct 27, 2023
This macro is like the existing `transmute!`, but it transmutes
mutable references rather than values.

Releasing 0.7.17

Issue #159
github-merge-queue bot pushed a commit that referenced this issue 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
Copy link
Member Author

joshlf commented Nov 1, 2023

Closed in #183 and #550.

@joshlf joshlf closed this as completed Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility-nonbreaking Changes that are (likely to be) non-breaking
Projects
None yet
Development

No branches or pull requests

1 participant