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

Use Rust union types #1020

Open
asomers opened this issue Jun 8, 2018 · 3 comments
Open

Use Rust union types #1020

asomers opened this issue Jun 8, 2018 · 3 comments

Comments

@asomers
Copy link
Contributor

asomers commented Jun 8, 2018

Rust gained a union type in 1.19.0. libc wraps many C unions poorly, usually by pretending they're structs and ignoring some fields. For example, https://github.com/rust-lang/libc/blob/master/src/unix/mod.rs#L156 . libc should update all of these to use the correct union types before release 1.0. It should be fairly easy to find them all, because all of them are listed as exclusions in libc-test/build.rs.

@alexcrichton
Copy link
Member

For new types we can start using unions but we unfortunately can't redefine existing types to use unions because accessing their fields are unsafe. It'd be good to get an idea of what changes could actually be made (backwards compatibly) before resolving the question of whether we're ready for a new version requirement or not.

@faern
Copy link
Contributor

faern commented Jul 15, 2018

I guess we can replace existing structs with real unions. Just that it would be a breaking change, needing a major version bump?

I hope all types that represent unions are going to be implemented as unions before libc 1.0? The current representations feels like hacks that were basically just waiting for Rust 1.19?

@alexcrichton
Copy link
Member

@faern yes new types can probably use union as necessary, and if/when libc 1.0 happens we can switch to unions for existing types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants