Skip to content

Regression in lint for non-exhaustive ZST in repr(Transparent) #115922

Closed
@compiler-errors

Description

@compiler-errors

Lifted from #78586


I believe this future compatibility warning was badly affected by #115334. Minimal repro:

// src/lib.rs

#[non_exhaustive]
pub struct ZeroSizedNonExhaustive {}
// src/main.rs

#![deny(warnings)]

#[repr(transparent)]
pub struct Transparent(repro::ZeroSizedNonExhaustive);

fn main() {}

As far as I understand what this issue is about, this code should be 100% fine. This issue is about preventing a previously-accepted repr(transparent) struct from ending up with contents which a transparent struct is not allowed to have, after a permissible size increase of a non-exhaustive formerly-ZST from a different crate.

That's not possible in the code above. Transparent continues to be a valid repr(transparent) struct if ZeroSizedNonExhaustive increases in size.

Regression in nightly-2023-09-18:

error: zero-sized fields in `repr(transparent)` cannot contain external non-exhaustive types
 --> src/main.rs:6:24
  |
6 | pub struct Transparent(repro::ZeroSizedNonExhaustive);
  |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  = note: for more information, see issue #78586 <https://github.com/rust-lang/rust/issues/78586>
  = note: this struct contains `ZeroSizedNonExhaustive`, which is marked with `#[non_exhaustive]`, and makes it not a breaking change to become non-zero-sized in the future.

@RalfJung @compiler-errors

Originally posted by @dtolnay in #78586 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions