File tree Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Original file line number Diff line number Diff line change 129129#![ feature( const_transmute) ]
130130#![ feature( reverse_bits) ]
131131#![ feature( non_exhaustive) ]
132+ #![ feature( structural_match) ]
132133
133134#[ prelude_import]
134135#[ allow( unused) ]
Original file line number Diff line number Diff line change @@ -578,6 +578,7 @@ macro_rules! impls{
578578///
579579/// [drop check]: ../../nomicon/dropck.html
580580#[ lang = "phantom_data" ]
581+ #[ structural_match]
581582#[ stable( feature = "rust1" , since = "1.0.0" ) ]
582583pub struct PhantomData < T : ?Sized > ;
583584
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments