Spawned off of investigation of issue #62307 and PR #55837
We currently allow constants that are empty arrays of any type to be used as patterns in match. We allow this regardless of whether they are an array of an ADT that does not derive PartialEq/Eq
This may be a feature or a bug depending on one's perspective.
Here is an example of the behavior in question (play):
struct B(i32);
const B0: [B; 0] = [];
//#[derive(PartialEq, Eq)] // can't uncomment b/c B doesn't impl PartialEq+Eq.
struct UhOh([B; 0]);
const _UH_OH: UhOh = UhOh(B0);
fn main() {
match [] {
B0 => { println!("B0 matched []"); }
}
match UhOh([]) {
UhOh(B0) => { println!("UhOh(B0) matched UhOh([])"); }
}
#[cfg(this_wont_compile_without_derive_of_partial_eq_and_eq)]
match UhOh([]) {
_UH_OH => { println!("_UH_OH matched UhOh([]])"); }
}
}
To be clear: This behavior might be fine.
It is just a little weird, because on other uses of consts in patterns, we do tend to require that their types derive PartialEq and Eq
But we can treat an empty array as an exceptional case here, if that's what people want.
Spawned off of investigation of issue #62307 and PR #55837
We currently allow constants that are empty arrays of any type to be used as patterns in
match. We allow this regardless of whether they are an array of an ADT that does not derivePartialEq/EqThis may be a feature or a bug depending on one's perspective.
Here is an example of the behavior in question (play):
To be clear: This behavior might be fine.
It is just a little weird, because on other uses of consts in patterns, we do tend to require that their types derive
PartialEqandEq#[structural_match]; see Restrict constants in patterns rfcs#1445).PartialEqis not required for a const in a pattern, namely forfor <'a> fn(&'a T); see Function pointer docs may need updating #46989 (comment) )But we can treat an empty array as an exceptional case here, if that's what people want.
& &Bleak use of PartialEq #62307).