Files
rust/tests/ui/pattern/deref-patterns/usefulness/mixed-constructors.rs
dianne fb261a179d error early when mixing deref patterns with normal constructors
Without adding proper support for mixed exhaustiveness, mixing deref
patterns with normal constructors would either violate
`ConstructorSet::split`'s invariant 4 or 7. We'd either be ignoring rows
with normal constructors or we'd have problems in unspecialization from
non-disjoint constructors. Checking mixed exhaustivenss similarly to how
unions are currently checked should work, but the diagnostics for unions
are confusing. Since mixing deref patterns with normal constructors is
pretty niche (currently it only makes sense for `Cow`), emitting an
error lets us avoid committing to supporting mixed exhaustiveness
without a good answer for the diagnostics.
2025-05-06 18:53:55 -07:00

49 lines
1.3 KiB
Rust

//! Test matches with a mix of ADT constructors and deref patterns. Currently, usefulness analysis
//! doesn't support this, so make sure we catch it beforehand. As a consequence, it takes priority
//! over non-exhaustive match and unreachable pattern errors.
#![feature(deref_patterns)]
#![expect(incomplete_features)]
#![deny(unreachable_patterns)]
use std::borrow::Cow;
fn main() {
let cow: Cow<'static, bool> = Cow::Borrowed(&false);
match cow {
true => {}
//~v ERROR mix of deref patterns and normal constructors
false => {}
Cow::Borrowed(_) => {}
}
match cow {
Cow::Owned(_) => {}
Cow::Borrowed(_) => {}
true => {}
//~^ ERROR mix of deref patterns and normal constructors
}
match cow {
_ => {}
Cow::Owned(_) => {}
false => {}
//~^ ERROR mix of deref patterns and normal constructors
}
match (cow, 0) {
(Cow::Owned(_), 0) => {}
(Cow::Borrowed(_), 0) => {}
(true, 0) => {}
//~^ ERROR mix of deref patterns and normal constructors
}
match (0, cow) {
(0, Cow::Owned(_)) => {}
(0, Cow::Borrowed(_)) => {}
_ => {}
(1, true) => {}
//~^ ERROR mix of deref patterns and normal constructors
}
}