Skip to content

Don't use repr(C)#42

Merged
dtolnay merged 1 commit into
dtolnay:masterfrom
Jules-Bertholet:no-C
May 1, 2026
Merged

Don't use repr(C)#42
dtolnay merged 1 commit into
dtolnay:masterfrom
Jules-Bertholet:no-C

Conversation

@Jules-Bertholet

Copy link
Copy Markdown
Contributor

Fixes #41.

@dtolnay dtolnay left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks!

@dtolnay dtolnay merged commit 1554153 into dtolnay:master May 1, 2026
11 checks passed
@Jules-Bertholet Jules-Bertholet deleted the no-C branch May 1, 2026 11:10
@afeistel

Copy link
Copy Markdown

this seems to set off some clippy warnings (#[warn(clippy::repr_packed_without_abi)]); maybe #[repr(Rust, packed)] instead?

@afeistel afeistel mentioned this pull request May 22, 2026
@RalfJung

RalfJung commented Jul 2, 2026

Copy link
Copy Markdown

What is the reason why this uses a 0-length array to begin with, rather than core::marker::PhantomData?

I'm considering to ban arrays from being ignored in repr(transparent) since that is an ABI promise that I am not sure we can hold (rust-lang/rust#156114). With that change, ghost's phantom types would no longer be ignored by repr(transparent). No regression showed up on crater so that does not seem to be a pattern that's very widely used, though it'd be nice to keep it working.

@RalfJung

RalfJung commented Jul 2, 2026

Copy link
Copy Markdown

Never mind, @Jules-Bertholet found a wording in rust-lang/rust#157973 that will keep this crate working.

However I am still curious why you are using a 0-lement array instead of PhantomData.

@dtolnay

dtolnay commented Jul 2, 2026

Copy link
Copy Markdown
Owner

It is a demonstration that a PhantomData-like can be built from primitives without using an existing PhantomData.

@Jules-Bertholet

Copy link
Copy Markdown
Contributor Author

Note that rust-lang/rust#157973 doesn't really answer all the issues here. That PR describes what types have trivial ABI on any specific target, but for deciding what to allow in repr(transparent) we will (IMO) want to ensure target independence.

@RalfJung

RalfJung commented Jul 2, 2026

Copy link
Copy Markdown

Yeah, that's why rust-lang/rust#155984 is so complicated -- and the code explains basically none of that reasoning (especially not the high-level goals that the logic is trying to achieve) which is why I was so confused when trying to review it.^^

It is a demonstration that a PhantomData-like can be built from primitives without using an existing PhantomData.

That is a cute trick, but IMO not a great argument for actually putting this in production. This will cause a whole bunch of extra work in rust-lang/rust#155984...

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.

Phantom types use repr(C), making them not "trivial" for repr(transparent) purposes

4 participants