3 #![warn(indirect_structural_match)]
5 // This test is checking our logic for structural match checking by enumerating
6 // the different kinds of const expressions. This test is collecting cases where
7 // we have accepted the const expression as a pattern in the past and wish to
10 // Even if a non-structural-match type is part of an expression in a const's
11 // definition, that does not necessarily disqualify the const from being a match
12 // pattern: in principle, we just need the types involved in the final value to
13 // be structurally matchable.
17 #![feature(type_ascription)]
19 #[derive(Copy, Clone, Debug)]
20 struct NoPartialEq(u32);
22 #[derive(Copy, Clone, Debug)]
25 // This impl makes `NoDerive` irreflexive.
26 impl PartialEq for NoDerive { fn eq(&self, _: &Self) -> bool { false } }
27 impl Eq for NoDerive { }
29 type OND = Option<NoDerive>;
32 const FIELD1: u32 = NoPartialEq(1).0;
33 match 1 { FIELD1 => dbg!(FIELD1), _ => panic!("whoops"), };
34 const FIELD2: u32 = NoDerive(1).0;
35 match 1 { FIELD2 => dbg!(FIELD2), _ => panic!("whoops"), };
37 enum CLike { One = 1, #[allow(dead_code)] Two = 2, }
38 const ONE_CAST: u32 = CLike::One as u32;
39 match 1 { ONE_CAST => dbg!(ONE_CAST), _ => panic!("whoops"), };
41 const NO_DERIVE_NONE: OND = None;
42 const INDIRECT: OND = NO_DERIVE_NONE;
43 match None { INDIRECT => dbg!(INDIRECT), _ => panic!("whoops"), };
45 const TUPLE: (OND, OND) = (None, None);
46 match (None, None) { TUPLE => dbg!(TUPLE), _ => panic!("whoops"), };
48 const TYPE_ASCRIPTION: OND = None: OND;
49 match None { TYPE_ASCRIPTION => dbg!(TYPE_ASCRIPTION), _ => panic!("whoops"), };
51 const ARRAY: [OND; 2] = [None, None];
52 match [None; 2] { ARRAY => dbg!(ARRAY), _ => panic!("whoops"), };
54 const REPEAT: [OND; 2] = [None; 2];
55 match [None, None] { REPEAT => dbg!(REPEAT), _ => panic!("whoops"), };
57 trait Trait: Sized { const ASSOC: Option<Self>; }
58 impl Trait for NoDerive { const ASSOC: Option<NoDerive> = None; }
59 match None { NoDerive::ASSOC => dbg!(NoDerive::ASSOC), _ => panic!("whoops"), };
61 const BLOCK: OND = { NoDerive(10); None };
62 match None { BLOCK => dbg!(BLOCK), _ => panic!("whoops"), };
64 const ADDR_OF: &OND = &None;
65 match &None { ADDR_OF => dbg!(ADDR_OF), _ => panic!("whoops"), };