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

Support C-style enums #170

Merged
merged 2 commits into from
May 1, 2020
Merged

Support C-style enums #170

merged 2 commits into from
May 1, 2020

Conversation

jgalenson
Copy link
Contributor

This adds support for passing C-style enums between Rust and C++.

We use the Rust representation for enums suggested by dtolnay in #132.
Note that as this does not use real enums, Rust code cannot treat them
as normal enums, e.g., by converting them to integers. But common
uses such as pattern matching remain unchanged.

This adds support for passing C-style enums between Rust and C++.

We use the Rust representation for enums suggested by dtolnay in dtolnay#132.
Note that as this does not use real enums, Rust code cannot treat them
as normal enums, e.g., by converting them to integers.  But common
uses such as pattern matching remain unchanged.
@jgalenson
Copy link
Contributor Author

Note that I decided to duplicate the logic for computing discriminants in check.rs and expand and check.rs to keep parsing close to the original syntax. But we could of course compute discriminants there to avoid the duplication.

And as an aside the logic for parsing a variant is slightly ugly; I don't know if we prefer more nested matches instead.

@jgalenson
Copy link
Contributor Author

It looks like the tests are failing because nightly rustc gives a different error message. Is there a way to configure it to change that test based on the compiler, maybe by modifying .travis.yml, or should we just delete that one test for now?

@dtolnay
Copy link
Owner

dtolnay commented May 1, 2020

Because of this line, we only run ui tests on nightly, so the expected error message files should match what is emitted by current nightly. I don't think maintaining additional expected outputs for different compilers would be productive.

#[rustversion::attr(not(nightly), ignore)]

Copy link
Owner

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is great work.

I filed #175, #176, #177 as possible followups.

@dtolnay dtolnay merged commit 02d58bb into dtolnay:master May 1, 2020
This was referenced May 1, 2020
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.

2 participants