I don't know the name of this feature, but it allows you to use any name instead of a case, it's like a worse _ =>. The problem is that this feature allows the introduction of silent bugs, causing typos when comparing constants to go unnoticed, which has happened to me a few times when writing FFI code.
Is there any way to force an error in these cases without using #![deny(unused_variables)], which is extremely broad? Something like #![deny(unused_variables_in_match_arms)] would be ideal.
Edit: I'm looking for a way to force an error when match arm has a case that is a simple binding that was probably introduced by a typo, I intend to expose the module constants in the function scope to avoid typing the path every time I write a case.
Currently, I avoid introducing these bugs by using partial paths for FFI constants.
Even though using constants without path can be considered a problem, I believe that match working this way is another problem apart from bad programming practices.
The code is illustrative so please don't pay attention to the dumb ways used to show the match problem.
THIS CODE IS A DUMB EXAMPLE, DO NOT USE IT TO REPLY TO THE POST
#[test]
fn awful() {
enum Metal {
Iron, Gold, Silver,
}
use Metal::*;
let metal = Silver;
let is_gold = match metal {
Iron => false,
God => true, //<-typo, warning: unused variables
Awful => false, //warning: unreachable patterns
_ => false, //useless, warning: unreachable patterns
};
assert!(!is_gold); //panic: is_gold == true
}