]> git.lizzy.rs Git - rust.git/blob - src/test/ui/rfc-1445-restrict-constants-in-patterns/cant-hide-behind-direct-struct-embedded.rs
Rollup merge of #99064 - lyming2007:issue-97687-fix, r=estebank
[rust.git] / src / test / ui / rfc-1445-restrict-constants-in-patterns / cant-hide-behind-direct-struct-embedded.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
8 struct NoDerive(#[allow(unused_tuple_struct_fields)] 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 WrapInline(NoDerive);
17
18 const WRAP_DIRECT_INLINE: WrapInline = WrapInline(NoDerive(0));
19
20 fn main() {
21     match WRAP_DIRECT_INLINE {
22         WRAP_DIRECT_INLINE => { panic!("WRAP_DIRECT_INLINE matched itself"); }
23         //~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
24         _ => { println!("WRAP_DIRECT_INLINE did not match itself"); }
25     }
26 }