rust/tests/ui/consts/const_in_pattern/custom-eq-branch-pass.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

43 lines
766 B
Rust
Raw Normal View History

2020-04-07 19:11:29 +00:00
//@ run-pass
struct CustomEq;
impl Eq for CustomEq {}
impl PartialEq for CustomEq {
fn eq(&self, _: &Self) -> bool {
false
}
}
#[derive(PartialEq, Eq)]
#[allow(unused)]
2020-04-07 19:11:29 +00:00
enum Foo {
Bar,
Baz,
Qux(CustomEq),
}
const BAR_BAZ: Foo = if 42 == 42 {
Foo::Bar
} else {
Foo::Qux(CustomEq) // dead arm
2020-04-07 19:11:29 +00:00
};
const EMPTY: &[CustomEq] = &[];
2020-04-07 19:11:29 +00:00
fn main() {
// BAR_BAZ itself is fine but the enum has other variants
// that are non-structural. Still, this should be accepted.
2020-04-07 19:11:29 +00:00
match Foo::Qux(CustomEq) {
BAR_BAZ => panic!(),
_ => {}
}
// Similarly, an empty slice of a type that is non-structural
// is accepted.
match &[CustomEq] as &[CustomEq] {
EMPTY => panic!(),
_ => {},
}
2020-04-07 19:11:29 +00:00
}