But from my understanding, this is not directly related to the borrow checker, which tracks who owns a reference and is allowed to modify it or not.
(That being said if you had a "default" case earlier, the compiler won't complain)
But from my understanding, this is not directly related to the borrow checker, which tracks who owns a reference and is allowed to modify it or not.
(That being said if you had a "default" case earlier, the compiler won't complain)
(I don't remember the specific underlying feature flag name, sorry).
EDIT: It's called `-Wswitch`
> Warn whenever a switch statement has an index of enumerated type and lacks a case for one or more of the named codes of that enumeration. (The presence of a default label prevents this warning.) case labels outside the enumeration range also provoke warnings when this option is used (even if there is a default label). This warning is enabled by -Wall.
The real problems with C enums aren't about matching completion, they are that:
- There is no guarantee that a variable value is in the enum range;
- A C (or Java, or C#) enum is a very poor type and can not represent all the data that a Rust enum carries. Developers usually use them with union types to solve that problem, but then there aren't any warnings for most problems anymore.
In Rust, enums are a core data structure with completely equal status to structs, and are used pervasively throughout the language including the standard library.
Notably, both Option (which is used instead of null) and Result (which is used for error handling) are enums, which means that you thse correctness checks for every null and every error condition, on by default. Thats a huge deal as these are often the source of unexpected runtime errors.
C++ had boost.variant which did exhaustiveness checking since ... 2002 (and an std version since C++17).
This is just basic type safety stuff.
Edit: typo