Skip to content

RFC: "don't omit me!" attribute for variants #2388

Closed
@catamorphism

Description

@catamorphism

I just ran into a variation on the following problem: Suppose I have a data type

enum A { B, C}

and some code somewhere else like:

alt check foo {
A {...}
B {...}
}

This says "I know that foo can't be in variant C". But what if I add a new variant D to A? Perhaps I really should add a case to the alt for D (since foo could now be in variant D), but the compiler gives me zero help in this case.

I propose an attribute called no_omit (actually, I don't really care what it's called) to be used like:

enum A { B, C, #[no_omit] D}

which has the effect of generating a warning if any alt check expressions omit the case for D. (I'm not too opinionated about whether it should be a lint warning or an error, so long as there's some way to enable it.) I expect the attribute would be used temporarily, during development, and then removed once the refactor that introduces D is completed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-frontendArea: Compiler frontend (errors, parsing and HIR)A-type-systemArea: Type system

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions