@@ -2,11 +2,15 @@ use super::Tree;
2
2
3
3
#[ derive( Debug , Hash , Eq , PartialEq , Clone , Copy ) ]
4
4
pub enum Def {
5
- Visible ,
6
- Invisible ,
5
+ NoSafetyInvariants ,
6
+ HasSafetyInvariants ,
7
7
}
8
8
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
+ }
10
14
11
15
mod prune {
12
16
use super :: * ;
@@ -16,17 +20,22 @@ mod prune {
16
20
17
21
#[ test]
18
22
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
+ ) ;
21
29
}
22
30
23
31
#[ test]
24
32
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 ) ) ;
27
36
28
37
assert_eq ! (
29
- layout. prune( & |d| matches!( d, Def :: Visible ) ) ,
38
+ layout. prune( & |d| matches!( d, Def :: HasSafetyInvariants ) ) ,
30
39
Tree :: from_bits( 0x00 ) . then( Tree :: from_bits( 0x01 ) )
31
40
) ;
32
41
}
@@ -37,21 +46,32 @@ mod prune {
37
46
38
47
#[ test]
39
48
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
+ ) ;
42
54
}
43
55
44
56
#[ test]
45
57
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
+ ) ;
48
64
}
49
65
50
66
#[ test]
51
67
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
+ ) ;
55
75
}
56
76
}
57
77
@@ -60,21 +80,26 @@ mod prune {
60
80
61
81
#[ test]
62
82
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( ) ) ;
65
85
}
66
86
67
87
#[ test]
68
88
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( ) ) ;
71
92
}
72
93
73
94
#[ test]
74
95
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
+ ) ;
78
103
}
79
104
}
80
105
}
0 commit comments