-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
RFC: Unsafe enums #724
RFC: Unsafe enums #724
Conversation
If you already require |
unsafe { | ||
let Variant1(bar) = foo; | ||
} | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be kind of annoying for when you want to only put the minimum number of non-unsafe things inside the unsafe
block; you’d have to write something like this:
let x;
unsafe {
let Variant1(bar) = foo;
x = bar;
}
// use `x`
because unsafe
creates its own scope. I don’t really have a better suggestion, but it’s good Rust style to put only actually unsafe stuff inside unsafe
blocks, and this would make that a little harder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps something like let unsafe { Variant1(bar) } = foo;
? I'm not sure how feasible that would be to implement though.
If we went with the fancy restrictive trait as suggested by @eddyb then we'd be able to remove the unsafe
blocks entirely making the resulting code much more concise.
@eddyb That is similar to http://discuss.rust-lang.org/t/new-type-kind-rawdata/996. However, I think this is too restrictive as an unsafe enum may need to contain:
|
You can't call |
@eddyb: I think you have mixed with So ok an |
A somewhat more minimalistic idea for addressing the same problem. |
Although there's definitely a missing feature here, I think it's something we can hold off on for a while. I've opened #877 to keep track of it. |
I started a discussion on internals to get a push going for this again |
Unsafe enums are effectively untagged unions, useful for FFI.
Rendered