]> git.proxmox.com Git - rustc.git/blob - src/test/ui/rfc1445/phantom-data-is-structurally-matchable.rs
New upstream version 1.44.1+dfsg1
[rustc.git] / src / test / ui / rfc1445 / phantom-data-is-structurally-matchable.rs
1 // run-pass
2
3 // This file checks that `PhantomData` is considered structurally matchable.
4
5 use std::marker::PhantomData;
6
7 fn main() {
8 let mut count = 0;
9
10 // A type which is not structurally matchable:
11 struct NotSM;
12
13 // And one that is:
14 #[derive(PartialEq, Eq)]
15 struct SM;
16
17 // Check that SM is structural-match:
18 const CSM: SM = SM;
19 match SM {
20 CSM => count += 1,
21 };
22
23 // Check that PhantomData<T> is structural-match even if T is not.
24 const CPD1: PhantomData<NotSM> = PhantomData;
25 match PhantomData {
26 CPD1 => count += 1,
27 };
28
29 // Check that PhantomData<T> is structural-match when T is.
30 const CPD2: PhantomData<SM> = PhantomData;
31 match PhantomData {
32 CPD2 => count += 1,
33 };
34
35 // Check that a type which has a PhantomData is structural-match.
36 #[derive(PartialEq, Eq, Default)]
37 struct Foo {
38 alpha: PhantomData<NotSM>,
39 beta: PhantomData<SM>,
40 }
41
42 const CFOO: Foo = Foo {
43 alpha: PhantomData,
44 beta: PhantomData,
45 };
46
47 match Foo::default() {
48 CFOO => count += 1,
49 };
50
51 // Final count must be 4 now if all
52 assert_eq!(count, 4);
53 }