@@ -2,11 +2,15 @@ use super::Tree;
22
33#[ derive( Debug , Hash , Eq , PartialEq , Clone , Copy ) ]
44pub enum Def {
5- Visible ,
6- Invisible ,
5+ NoSafetyInvariants ,
6+ HasSafetyInvariants ,
77}
88
9- impl super :: Def for Def { }
9+ impl super :: Def for Def {
10+ fn has_safety_invariants ( & self ) -> bool {
11+ self == & Self :: HasSafetyInvariants
12+ }
13+ }
1014
1115mod prune {
1216 use super :: * ;
@@ -16,17 +20,22 @@ mod prune {
1620
1721 #[ test]
1822 fn seq_1 ( ) {
19- let layout: Tree < Def , !> = Tree :: def ( Def :: Visible ) . then ( Tree :: from_bits ( 0x00 ) ) ;
20- assert_eq ! ( layout. prune( & |d| matches!( d, Def :: Visible ) ) , Tree :: from_bits( 0x00 ) ) ;
23+ let layout: Tree < Def , !> =
24+ Tree :: def ( Def :: NoSafetyInvariants ) . then ( Tree :: from_bits ( 0x00 ) ) ;
25+ assert_eq ! (
26+ layout. prune( & |d| matches!( d, Def :: HasSafetyInvariants ) ) ,
27+ Tree :: from_bits( 0x00 )
28+ ) ;
2129 }
2230
2331 #[ test]
2432 fn seq_2 ( ) {
25- let layout: Tree < Def , !> =
26- Tree :: from_bits ( 0x00 ) . then ( Tree :: def ( Def :: Visible ) ) . then ( Tree :: from_bits ( 0x01 ) ) ;
33+ let layout: Tree < Def , !> = Tree :: from_bits ( 0x00 )
34+ . then ( Tree :: def ( Def :: NoSafetyInvariants ) )
35+ . then ( Tree :: from_bits ( 0x01 ) ) ;
2736
2837 assert_eq ! (
29- layout. prune( & |d| matches!( d, Def :: Visible ) ) ,
38+ layout. prune( & |d| matches!( d, Def :: HasSafetyInvariants ) ) ,
3039 Tree :: from_bits( 0x00 ) . then( Tree :: from_bits( 0x01 ) )
3140 ) ;
3241 }
@@ -37,21 +46,32 @@ mod prune {
3746
3847 #[ test]
3948 fn invisible_def ( ) {
40- let layout: Tree < Def , !> = Tree :: def ( Def :: Invisible ) ;
41- assert_eq ! ( layout. prune( & |d| matches!( d, Def :: Visible ) ) , Tree :: uninhabited( ) ) ;
49+ let layout: Tree < Def , !> = Tree :: def ( Def :: HasSafetyInvariants ) ;
50+ assert_eq ! (
51+ layout. prune( & |d| matches!( d, Def :: HasSafetyInvariants ) ) ,
52+ Tree :: uninhabited( )
53+ ) ;
4254 }
4355
4456 #[ test]
4557 fn invisible_def_in_seq_len_2 ( ) {
46- let layout: Tree < Def , !> = Tree :: def ( Def :: Visible ) . then ( Tree :: def ( Def :: Invisible ) ) ;
47- assert_eq ! ( layout. prune( & |d| matches!( d, Def :: Visible ) ) , Tree :: uninhabited( ) ) ;
58+ let layout: Tree < Def , !> =
59+ Tree :: def ( Def :: NoSafetyInvariants ) . then ( Tree :: def ( Def :: HasSafetyInvariants ) ) ;
60+ assert_eq ! (
61+ layout. prune( & |d| matches!( d, Def :: HasSafetyInvariants ) ) ,
62+ Tree :: uninhabited( )
63+ ) ;
4864 }
4965
5066 #[ test]
5167 fn invisible_def_in_seq_len_3 ( ) {
52- let layout: Tree < Def , !> =
53- Tree :: def ( Def :: Visible ) . then ( Tree :: from_bits ( 0x00 ) ) . then ( Tree :: def ( Def :: Invisible ) ) ;
54- assert_eq ! ( layout. prune( & |d| matches!( d, Def :: Visible ) ) , Tree :: uninhabited( ) ) ;
68+ let layout: Tree < Def , !> = Tree :: def ( Def :: NoSafetyInvariants )
69+ . then ( Tree :: from_bits ( 0x00 ) )
70+ . then ( Tree :: def ( Def :: HasSafetyInvariants ) ) ;
71+ assert_eq ! (
72+ layout. prune( & |d| matches!( d, Def :: HasSafetyInvariants ) ) ,
73+ Tree :: uninhabited( )
74+ ) ;
5575 }
5676 }
5777
@@ -60,21 +80,26 @@ mod prune {
6080
6181 #[ test]
6282 fn visible_def ( ) {
63- let layout: Tree < Def , !> = Tree :: def ( Def :: Visible ) ;
64- assert_eq ! ( layout. prune( & |d| matches!( d, Def :: Visible ) ) , Tree :: unit( ) ) ;
83+ let layout: Tree < Def , !> = Tree :: def ( Def :: NoSafetyInvariants ) ;
84+ assert_eq ! ( layout. prune( & |d| matches!( d, Def :: HasSafetyInvariants ) ) , Tree :: unit( ) ) ;
6585 }
6686
6787 #[ test]
6888 fn visible_def_in_seq_len_2 ( ) {
69- let layout: Tree < Def , !> = Tree :: def ( Def :: Visible ) . then ( Tree :: def ( Def :: Visible ) ) ;
70- assert_eq ! ( layout. prune( & |d| matches!( d, Def :: Visible ) ) , Tree :: unit( ) ) ;
89+ let layout: Tree < Def , !> =
90+ Tree :: def ( Def :: NoSafetyInvariants ) . then ( Tree :: def ( Def :: NoSafetyInvariants ) ) ;
91+ assert_eq ! ( layout. prune( & |d| matches!( d, Def :: HasSafetyInvariants ) ) , Tree :: unit( ) ) ;
7192 }
7293
7394 #[ test]
7495 fn visible_def_in_seq_len_3 ( ) {
75- let layout: Tree < Def , !> =
76- Tree :: def ( Def :: Visible ) . then ( Tree :: from_bits ( 0x00 ) ) . then ( Tree :: def ( Def :: Visible ) ) ;
77- assert_eq ! ( layout. prune( & |d| matches!( d, Def :: Visible ) ) , Tree :: from_bits( 0x00 ) ) ;
96+ let layout: Tree < Def , !> = Tree :: def ( Def :: NoSafetyInvariants )
97+ . then ( Tree :: from_bits ( 0x00 ) )
98+ . then ( Tree :: def ( Def :: NoSafetyInvariants ) ) ;
99+ assert_eq ! (
100+ layout. prune( & |d| matches!( d, Def :: HasSafetyInvariants ) ) ,
101+ Tree :: from_bits( 0x00 )
102+ ) ;
78103 }
79104 }
80105}
0 commit comments