Skip to content

Clarify whether #[repr(C)] can be used on tuple structs or not. #29526

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

Closed
nwin opened this issue Nov 2, 2015 · 6 comments
Closed

Clarify whether #[repr(C)] can be used on tuple structs or not. #29526

nwin opened this issue Nov 2, 2015 · 6 comments

Comments

@nwin
Copy link
Contributor

nwin commented Nov 2, 2015

Until now I had the impression that it would be undefined how this construct would behave. The Rustonomicon implies that this is still the case, as tuple-structs are just like “named tuples”. On the other hand, the reference implies that it should be safe to use #[repr(C)] since tuple structs behave like normal structs with anonymous fields.

I would appreciate if this would be clarified in the docs. If it is still undefined behavior #[repr(C)] on a tuple struct should cause an compiler error.

@eefriedman
Copy link
Contributor

It's well-defined; perhaps the docs aren't as clear as they could be.

@Aatch
Copy link
Contributor

Aatch commented Nov 3, 2015

Just to be clear, tuples and structs are handled pretty much identically. There are two properties, named type and named fields that distinguish the 3 options:

Type Named? Field Named?
struct Foo { a: i32 } Yes Yes
struct Foo(i32) Yes No
N/A (Would be "record" or similar) No Yes
(i32, i32) No No

In theory, there is no reason you couldn't apply #[repr(C)] to tuples, except that there's no source-code definition for them.

@steveklabnik steveklabnik added A-docs and removed A-docs labels Nov 3, 2015
@steveklabnik
Copy link
Member

/cc @rust-lang/lang, is this well-defined? I'm guessing so, but I'd like to be sure before I document it.

@nikomatsakis
Copy link
Contributor

I see no reason to disallow it. I vote "not a bug".

@nrc
Copy link
Member

nrc commented Nov 5, 2015

Agree. Change to a docs bug?

@steveklabnik steveklabnik added A-docs and removed A-lang labels Nov 5, 2015
@steveklabnik
Copy link
Member

Sounds good, I'll document it.

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

No branches or pull requests

6 participants