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

Don't require T to be AnyBitPattern for MaybeUninit<T> to be AnyBitPattern #249

Closed
wants to merge 1 commit into from

Conversation

tyilo
Copy link

@tyilo tyilo commented Jun 6, 2024

MaybeUninit<T> is always valid for any bit pattern even if T is not.

@zachs18
Copy link
Contributor

zachs18 commented Jun 6, 2024

This was going to be implemented in #152, but was discovered to possibly be unsound in general (#152 (comment)), so a never-unsound-but-more-conservative implementation was implemented instead (#160, require T to be AnyBitPattern so we know it has no interior mutability).If Freeze was stable, then this would be possible (either impl<T: Freeze + Copy + 'static> AnyBitPattern for MaybeUninit<T>, or under #153, impl<T> AnyBitPattern for MaybeUninit<T>).

@tyilo
Copy link
Author

tyilo commented Jun 6, 2024

Ah, so this is only sound if implementing Copy means a type also implements Freeze.

As I understand it, there are currently no !Freeze type that implements Copy so this change would be sound for the current version of Rust.

However this could change in a future version of Rust, where this change would then be unsound.

@Lokathor
Copy link
Owner

Lokathor commented Aug 2, 2024

I've heard occasional rumblings of wanting Freeze to be a a stable trait some day. It wouldn't be any time soon, but more people are coming around to it being quite useful. So, I think that we should wait until that happens.

@Lokathor Lokathor added the The Language Could Change I Guess A change in the language could always potentially invalidate old code label Aug 18, 2024
@Lokathor
Copy link
Owner

I'm going to close this until Rust as a language develops further, and then maybe someday later we can revisit the concept.

@Lokathor Lokathor closed this Aug 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
The Language Could Change I Guess A change in the language could always potentially invalidate old code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants