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

Even more ?Sized bounds #22

Merged
merged 3 commits into from Oct 27, 2022
Merged

Even more ?Sized bounds #22

merged 3 commits into from Oct 27, 2022

Conversation

wackbyte
Copy link
Contributor

Overview:

  • GhostBorrow/GhostBorrowMut for &(GhostCell<T>, ...): The last type is ?Sized.
    • The extra macro I wrote to help with this is duplicated between the two modules since it's really small. I can move it to a new module if needed, though.
  • GhostBorrowMut for (&GhostCell<T>, ...): Each type is ?Sized.
    • Didn't require any other changes.
  • GhostBorrowMut for [&GhostCell<T>; N]: T is ?Sized.
    • I think I've found a solution to the problems discussed in your previous comment.
    • I made check_distinct generic over a type T and made it take [*const T; N] instead of [*const (); N].
      Each pointer is cast to *const () during comparison (I made sure and checked, and std recommends this for by-address equality of fat pointers; see the last example here).
      [&GhostCell<T>; N] and [*const T; N] definitely have the same layout, so no strange pointer casting issues here.
    • It doesn't require the pointer metadata API!
  • I made a few basic positive and negative tests.

src/ghost_borrow_mut.rs Outdated Show resolved Hide resolved
@matthieu-m
Copy link
Owner

This is looking really good. I just think it would be worth being a little more explicit on the assumptions making check_distinct safe in the presence of fat pointers; I suggested one, but if you can think of others please do add them.

As far as I know, the assumptions hold at the moment, so we're in the clear for now, but I find it better to document them should the lay of the land change in the future.

@matthieu-m matthieu-m merged commit e4f8d0e into matthieu-m:master Oct 27, 2022
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.

None yet

2 participants