Skip to content

#[non_exhaustive] on variant should block cross-crate as casts #91161

Closed
@scottmcm

Description

@scottmcm

This currently compiles

// in crate 1
#[repr(u8)]
enum Foo {
    A,
    #[non_exhaustive]
    B,
}
// in crate 2
fn demo(f: Foo) -> u8 {
    f as u8
}

However, that as cast would be an erroneous "non-primitive cast" if the variant ever got any fields, as it's allowed to do by the #[non_exhaustive].

Thus we need to fix the compiler so that the cast is rejected outside the crate that owns Foo.

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.E-help-wantedCall for participation: Help is requested to fix this issue.F-non_exhaustive`#![feature(non_exhaustive)]`T-langRelevant to the language team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions