]> git.lizzy.rs Git - rust.git/blob - src/test/ui/rfc-1445-restrict-constants-in-patterns/cant-hide-behind-direct-struct-param.rs
Auto merge of #86155 - alexcrichton:abort-on-unwind, r=nikomatsakis
[rust.git] / src / test / ui / rfc-1445-restrict-constants-in-patterns / cant-hide-behind-direct-struct-param.rs
1 // This is part of a set of tests exploring the different ways a
2 // structural-match ADT might try to hold a
3 // non-structural-match in hidden manner that lets matches
4 // through that we had intended to reject.
5 //
6 // See discussion on rust-lang/rust#62307 and rust-lang/rust#62339
7 #![warn(indirect_structural_match)]
8 struct NoDerive(i32);
9
10 // This impl makes NoDerive irreflexive.
11 impl PartialEq for NoDerive { fn eq(&self, _: &Self) -> bool { false } }
12
13 impl Eq for NoDerive { }
14
15 #[derive(PartialEq, Eq)]
16 struct WrapParam<T>(T);
17
18 const WRAP_DIRECT_PARAM: WrapParam<NoDerive> = WrapParam(NoDerive(0));
19
20 fn main() {
21     match WRAP_DIRECT_PARAM {
22         WRAP_DIRECT_PARAM => { panic!("WRAP_DIRECT_PARAM matched itself"); }
23         //~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
24         _ => { println!("WRAP_DIRECT_PARAM did not match itself"); }
25     }
26 }