You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixing this is, erm, complicated. I suppose the ideal solution would be to make Sid an unsized type ([u8]) instead of an opaque type. This would cause mem::replace to become a compile time error, I believe, but would turn pointers to Sid into fat pointers.
EDIT: I think what we'd need is rust-lang/rust#43467. If Sid was an Opaque Type, it'd be !Sized, and thus mem::replace wouldn't work, but a reference to it would still be only a single pointer.
The text was updated successfully, but these errors were encountered:
I think that's correct. I don't know of any way to explicitly mark a type as !Sized, but the goal is that it should only be accessible through a pointer.
For what it's worth, swapping does work with std::mem::swap(&mut sid1, &mut sid2). This is definitely a bug until there is a way to mark a struct !Sized.
Also, the example uses mem_swap and I think that's the main issue. mem_replace should be fine because you need a raw Sid (not behind a pointer) to call it, and there should never be a way to get hold of one of those.
Because Sid is an opaque type, it is impossible to
std::mem::replace
it. Example test:Fixing this is, erm, complicated. I suppose the ideal solution would be to make Sid an unsized type (
[u8]
) instead of an opaque type. This would causemem::replace
to become a compile time error, I believe, but would turn pointers to Sid into fat pointers.EDIT: I think what we'd need is rust-lang/rust#43467. If Sid was an Opaque Type, it'd be !Sized, and thus
mem::replace
wouldn't work, but a reference to it would still be only a single pointer.The text was updated successfully, but these errors were encountered: