3 // This test is checking our logic for structural match checking by enumerating
4 // the different kinds of const expressions. This test is collecting cases where
5 // we have accepted the const expression as a pattern in the past but we want
6 // to begin warning the user that a future version of Rust may start rejecting
7 // such const expressions.
9 // The specific corner cases we are exploring here are instances where the
10 // const-evaluator computes a value that *does* meet the conditions for
11 // structural-match, but the const expression itself has abstractions (like
12 // calls to const functions) that may fit better with a type-based analysis
13 // rather than a commitment to a specific value.
15 #![warn(indirect_structural_match)]
17 #[derive(Copy, Clone, Debug)]
20 // This impl makes `NoDerive` irreflexive.
21 impl PartialEq for NoDerive { fn eq(&self, _: &Self) -> bool { false } }
22 impl Eq for NoDerive { }
25 const INDEX: Option<NoDerive> = [None, Some(NoDerive(10))][0];
26 match None { Some(_) => panic!("whoops"), INDEX => dbg!(INDEX), };
27 //~^ WARN must be annotated with `#[derive(PartialEq, Eq)]`
28 //~| WARN this was previously accepted
30 const fn build() -> Option<NoDerive> { None }
31 const CALL: Option<NoDerive> = build();
32 match None { Some(_) => panic!("whoops"), CALL => dbg!(CALL), };
33 //~^ WARN must be annotated with `#[derive(PartialEq, Eq)]`
34 //~| WARN this was previously accepted
36 impl NoDerive { const fn none() -> Option<NoDerive> { None } }
37 const METHOD_CALL: Option<NoDerive> = NoDerive::none();
38 match None { Some(_) => panic!("whoops"), METHOD_CALL => dbg!(METHOD_CALL), };
39 //~^ WARN must be annotated with `#[derive(PartialEq, Eq)]`
40 //~| WARN this was previously accepted