]> git.lizzy.rs Git - rust.git/blob - src/test/ui/rfc-1445-restrict-constants-in-patterns/cant-hide-behind-doubly-indirect-param.rs
Rollup merge of #97317 - GuillaumeGomez:gui-settings-text-click, r=jsha
[rust.git] / src / test / ui / rfc-1445-restrict-constants-in-patterns / cant-hide-behind-doubly-indirect-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 // run-pass
9
10 struct NoDerive(i32);
11
12 // This impl makes NoDerive irreflexive.
13 impl PartialEq for NoDerive { fn eq(&self, _: &Self) -> bool { false } }
14
15 impl Eq for NoDerive { }
16
17 #[derive(PartialEq, Eq)]
18 struct WrapParam<'a, T>(&'a &'a T);
19
20 const WRAP_DOUBLY_INDIRECT_PARAM: & &WrapParam<NoDerive> = & &WrapParam(& & NoDerive(0));
21
22 fn main() {
23     match WRAP_DOUBLY_INDIRECT_PARAM {
24         WRAP_DOUBLY_INDIRECT_PARAM => { panic!("WRAP_DOUBLY_INDIRECT_PARAM matched itself"); }
25         //~^ WARN must be annotated with `#[derive(PartialEq, Eq)]`
26         //~| WARN this was previously accepted
27         _ => { println!("WRAP_DOUBLY_INDIRECT_PARAM correctly did not match itself"); }
28     }
29 }