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

transmute_mut! documents looser requirements than what is implemented #1046

Closed
Tracked by #671
kupiakos opened this issue Mar 14, 2024 · 2 comments
Closed
Tracked by #671
Labels
documentation Improvements or additions to documentation

Comments

@kupiakos
Copy link
Contributor

transmute_mut! documents the requirements that:

  • T: Sized + IntoBytes
  • U: Sized + FromBytes
  • align_of::<T>() >= align_of::<U>()

However, this is less strict that what is actually required:

  • T: FromBytes + IntoBytes + NoCell
  • U: FromBytes + IntoBytes + NoCell
  • size_of::<T>() == size_of::<U>()
  • align_of::<T>() >= align_of::<U>()

The size and NoCell requirements are also similarly missing from transmute_ref!.

@kupiakos kupiakos added the documentation Improvements or additions to documentation label Mar 14, 2024
jswrenn added a commit that referenced this issue Mar 15, 2024
jswrenn added a commit that referenced this issue Mar 15, 2024
jswrenn added a commit that referenced this issue Mar 17, 2024
@joshlf joshlf mentioned this issue Mar 19, 2024
65 tasks
@joshlf
Copy link
Member

joshlf commented Mar 19, 2024

Good catch! We'll block releasing 0.8 on this.

github-merge-queue bot pushed a commit that referenced this issue Mar 19, 2024
jswrenn added a commit that referenced this issue Mar 19, 2024
jswrenn added a commit that referenced this issue Mar 19, 2024
jswrenn added a commit that referenced this issue Mar 19, 2024
github-merge-queue bot pushed a commit that referenced this issue Mar 19, 2024
@jswrenn
Copy link
Collaborator

jswrenn commented Apr 17, 2024

This was completed in #1050 and #1058. We now use the following pseudocode to document the bounds of our transmute macros:

const fn transmute<Src, Dst>(src: Src) -> Dst
where
    Src: IntoBytes,
    Dst: FromBytes,
    size_of::<Src>() == size_of::<Dst>();

const fn transmute_ref<'src, 'dst, Src, Dst>(src: &'src Src) -> &'dst Dst
where
    'src: 'dst,
    Src: IntoBytes + NoCell,
    Dst: FromBytes + NoCell,
    size_of::<Src>() == size_of::<Dst>(),
    align_of::<Src>() >= align_of::<Dst>();

const fn transmute_mut<'src, 'dst, Src, Dst>(src: &'src mut Src) -> &'dst mut Dst
where
    'src: 'dst,
    Src: FromBytes + IntoBytes + NoCell,
    Dst: FromBytes + IntoBytes + NoCell,
    size_of::<Src>() == size_of::<Dst>(),
    align_of::<Src>() >= align_of::<Dst>();

@jswrenn jswrenn closed this as completed Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants