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

ZST's layout leaks #114391

Open
joshlf opened this issue Aug 2, 2023 · 1 comment
Open

ZST's layout leaks #114391

joshlf opened this issue Aug 2, 2023 · 1 comment
Labels
A-crate-compat Area: Impacting SemVer compatibility of crates in the ecosystem A-repr Area: the `#[repr(stuff)]` attribute C-bug Category: This is a bug. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@joshlf
Copy link
Contributor

joshlf commented Aug 2, 2023

I have the following code:

#[repr(transparent)]
struct Foo(Zst, [u8]);

struct Zst(());

I would expect this code to be rejected - since Zst doesn't have a repr, it isn't guaranteed to be a ZST. As a result, repr(transparent) should consider Foo to have two non-ZST fields, which is illegal. Instead, it compiles successfully.

One practical consequence is that, if I were to publish Zst in a crate, downstream crates could write code whose correctness depends on Zst's layout even though I didn't intend to expose it anywhere.

Rust version: 1.71.0

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 2, 2023
@Noratrieb Noratrieb added T-lang Relevant to the language team, which will review and decide on the PR/issue. C-bug Category: This is a bug. A-crate-compat Area: Impacting SemVer compatibility of crates in the ecosystem and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Aug 3, 2023
@scottmcm
Copy link
Member

scottmcm commented Aug 4, 2023

This is a stronger version of #78586

(It's probably worth tracking separately, because this is is likely harder to fix.)

@workingjubilee workingjubilee added the A-repr Area: the `#[repr(stuff)]` attribute label Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-crate-compat Area: Impacting SemVer compatibility of crates in the ecosystem A-repr Area: the `#[repr(stuff)]` attribute C-bug Category: This is a bug. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants