Skip to content

Conversation

@jswrenn
Copy link
Collaborator

@jswrenn jswrenn commented Jun 5, 2023

As a consequence of this change, the phase in which some invalid transmutes are detected differs. The transmute! macro depended internally on mem::transmute, which cannot be used in generic contexts but provides pre-monomorphization errors if the source and destination types have different sizes. By contrast, the transmute function can be used in generic contexts, but does not report size errors until monomorphization.

This increase in expressivity comes at the cost of some usability: size errors are currently only reported by invocations of cargo build; not cargo check.

@jswrenn jswrenn mentioned this pull request Jun 5, 2023
@jswrenn jswrenn force-pushed the more-transmute-ui-tests branch 4 times, most recently from 665ddc1 to 59917e3 Compare June 6, 2023 14:36
As a consequence of this change, the phase in which some invalid
transmutes are detected differs. The `transmute!` macro depended
internally on `mem::transmute`, which cannot be used in generic
contexts but provides pre-monomorphization errors if the source
and destination types have different sizes. By contrast, the
`transmute` function can be used in generic contexts, but does
not report size errors until monomorphization.

This increase in expressivity comes at the cost of some usability:
size errors are currently only reported by invocations of
`cargo build`; not `cargo check`.
// Used in `transmute!` below.
#[doc(hidden)]
pub use core::mem::transmute as __real_transmute;
pub trait TransmuteFrom<Src>: Sized {
Copy link
Contributor

@kupiakos kupiakos Jul 21, 2023

Choose a reason for hiding this comment

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

This trait does not need to be (and shouldn't be) pub, because it has a blanket implementation on T: Sized that transmute can use without declaring it in its where bounds.

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