Aryan PrajapatKnowledge Contributor
What happens if you add a new variant to a Rust enum without changing any other code?
What happens if you add a new variant to a Rust enum without changing any other code?
Adding a new variant to an enum without changing any other code may trigger compiler errors elsewhere in the program.
When using match on an enum, all variants must get checked.
Adding a new variant to the enum, without updating the match blocks which use the enum, will trigger compiler errors. This is because the match expression no longer handles all possible variants, but this applies solely when the match block does not have a “catch-all” match arm.