@@ -64,8 +64,10 @@ macro_rules! def_next_kv_uncheched_dealloc {
64
64
edge = match edge. $adjacent_kv( ) {
65
65
Ok ( internal_kv) => return internal_kv,
66
66
Err ( last_edge) => {
67
- let parent_edge = last_edge. into_node( ) . deallocate_and_ascend( ) ;
68
- unwrap_unchecked( parent_edge) . forget_node_type( )
67
+ unsafe {
68
+ let parent_edge = last_edge. into_node( ) . deallocate_and_ascend( ) ;
69
+ unwrap_unchecked( parent_edge) . forget_node_type( )
70
+ }
69
71
}
70
72
}
71
73
}
@@ -82,9 +84,11 @@ def_next_kv_uncheched_dealloc! {unsafe fn next_back_kv_unchecked_dealloc: left_k
82
84
/// Safety: The change closure must not panic.
83
85
#[ inline]
84
86
unsafe fn replace < T , R > ( v : & mut T , change : impl FnOnce ( T ) -> ( T , R ) ) -> R {
85
- let value = ptr:: read ( v) ;
87
+ let value = unsafe { ptr:: read ( v) } ;
86
88
let ( new_value, ret) = change ( value) ;
87
- ptr:: write ( v, new_value) ;
89
+ unsafe {
90
+ ptr:: write ( v, new_value) ;
91
+ }
88
92
ret
89
93
}
90
94
@@ -93,22 +97,26 @@ impl<'a, K, V> Handle<NodeRef<marker::Immut<'a>, K, V, marker::Leaf>, marker::Ed
93
97
/// key and value in between.
94
98
/// Unsafe because the caller must ensure that the leaf edge is not the last one in the tree.
95
99
pub unsafe fn next_unchecked ( & mut self ) -> ( & ' a K , & ' a V ) {
96
- replace ( self , |leaf_edge| {
97
- let kv = leaf_edge. next_kv ( ) ;
98
- let kv = unwrap_unchecked ( kv. ok ( ) ) ;
99
- ( kv. next_leaf_edge ( ) , kv. into_kv ( ) )
100
- } )
100
+ unsafe {
101
+ replace ( self , |leaf_edge| {
102
+ let kv = leaf_edge. next_kv ( ) ;
103
+ let kv = unwrap_unchecked ( kv. ok ( ) ) ;
104
+ ( kv. next_leaf_edge ( ) , kv. into_kv ( ) )
105
+ } )
106
+ }
101
107
}
102
108
103
109
/// Moves the leaf edge handle to the previous leaf edge and returns references to the
104
110
/// key and value in between.
105
111
/// Unsafe because the caller must ensure that the leaf edge is not the first one in the tree.
106
112
pub unsafe fn next_back_unchecked ( & mut self ) -> ( & ' a K , & ' a V ) {
107
- replace ( self , |leaf_edge| {
108
- let kv = leaf_edge. next_back_kv ( ) ;
109
- let kv = unwrap_unchecked ( kv. ok ( ) ) ;
110
- ( kv. next_back_leaf_edge ( ) , kv. into_kv ( ) )
111
- } )
113
+ unsafe {
114
+ replace ( self , |leaf_edge| {
115
+ let kv = leaf_edge. next_back_kv ( ) ;
116
+ let kv = unwrap_unchecked ( kv. ok ( ) ) ;
117
+ ( kv. next_back_leaf_edge ( ) , kv. into_kv ( ) )
118
+ } )
119
+ }
112
120
}
113
121
}
114
122
@@ -119,14 +127,16 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, marker::Edge
119
127
/// - The caller must ensure that the leaf edge is not the last one in the tree.
120
128
/// - Using the updated handle may well invalidate the returned references.
121
129
pub unsafe fn next_unchecked ( & mut self ) -> ( & ' a mut K , & ' a mut V ) {
122
- let kv = replace ( self , |leaf_edge| {
123
- let kv = leaf_edge. next_kv ( ) ;
124
- let kv = unwrap_unchecked ( kv. ok ( ) ) ;
125
- ( ptr:: read ( & kv) . next_leaf_edge ( ) , kv)
126
- } ) ;
127
- // Doing the descend (and perhaps another move) invalidates the references
128
- // returned by `into_kv_mut`, so we have to do this last.
129
- kv. into_kv_mut ( )
130
+ unsafe {
131
+ let kv = replace ( self , |leaf_edge| {
132
+ let kv = leaf_edge. next_kv ( ) ;
133
+ let kv = unwrap_unchecked ( kv. ok ( ) ) ;
134
+ ( ptr:: read ( & kv) . next_leaf_edge ( ) , kv)
135
+ } ) ;
136
+ // Doing the descend (and perhaps another move) invalidates the references
137
+ // returned by `into_kv_mut`, so we have to do this last.
138
+ kv. into_kv_mut ( )
139
+ }
130
140
}
131
141
132
142
/// Moves the leaf edge handle to the previous leaf and returns references to the
@@ -135,14 +145,16 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, marker::Edge
135
145
/// - The caller must ensure that the leaf edge is not the first one in the tree.
136
146
/// - Using the updated handle may well invalidate the returned references.
137
147
pub unsafe fn next_back_unchecked ( & mut self ) -> ( & ' a mut K , & ' a mut V ) {
138
- let kv = replace ( self , |leaf_edge| {
139
- let kv = leaf_edge. next_back_kv ( ) ;
140
- let kv = unwrap_unchecked ( kv. ok ( ) ) ;
141
- ( ptr:: read ( & kv) . next_back_leaf_edge ( ) , kv)
142
- } ) ;
143
- // Doing the descend (and perhaps another move) invalidates the references
144
- // returned by `into_kv_mut`, so we have to do this last.
145
- kv. into_kv_mut ( )
148
+ unsafe {
149
+ let kv = replace ( self , |leaf_edge| {
150
+ let kv = leaf_edge. next_back_kv ( ) ;
151
+ let kv = unwrap_unchecked ( kv. ok ( ) ) ;
152
+ ( ptr:: read ( & kv) . next_back_leaf_edge ( ) , kv)
153
+ } ) ;
154
+ // Doing the descend (and perhaps another move) invalidates the references
155
+ // returned by `into_kv_mut`, so we have to do this last.
156
+ kv. into_kv_mut ( )
157
+ }
146
158
}
147
159
}
148
160
@@ -159,12 +171,14 @@ impl<K, V> Handle<NodeRef<marker::Owned, K, V, marker::Leaf>, marker::Edge> {
159
171
/// if the two preconditions above hold.
160
172
/// - Using the updated handle may well invalidate the returned references.
161
173
pub unsafe fn next_unchecked ( & mut self ) -> ( K , V ) {
162
- replace ( self , |leaf_edge| {
163
- let kv = next_kv_unchecked_dealloc ( leaf_edge) ;
164
- let k = ptr:: read ( kv. reborrow ( ) . into_kv ( ) . 0 ) ;
165
- let v = ptr:: read ( kv. reborrow ( ) . into_kv ( ) . 1 ) ;
166
- ( kv. next_leaf_edge ( ) , ( k, v) )
167
- } )
174
+ unsafe {
175
+ replace ( self , |leaf_edge| {
176
+ let kv = next_kv_unchecked_dealloc ( leaf_edge) ;
177
+ let k = ptr:: read ( kv. reborrow ( ) . into_kv ( ) . 0 ) ;
178
+ let v = ptr:: read ( kv. reborrow ( ) . into_kv ( ) . 1 ) ;
179
+ ( kv. next_leaf_edge ( ) , ( k, v) )
180
+ } )
181
+ }
168
182
}
169
183
170
184
/// Moves the leaf edge handle to the previous leaf edge and returns the key
@@ -179,12 +193,14 @@ impl<K, V> Handle<NodeRef<marker::Owned, K, V, marker::Leaf>, marker::Edge> {
179
193
/// if the two preconditions above hold.
180
194
/// - Using the updated handle may well invalidate the returned references.
181
195
pub unsafe fn next_back_unchecked ( & mut self ) -> ( K , V ) {
182
- replace ( self , |leaf_edge| {
183
- let kv = next_back_kv_unchecked_dealloc ( leaf_edge) ;
184
- let k = ptr:: read ( kv. reborrow ( ) . into_kv ( ) . 0 ) ;
185
- let v = ptr:: read ( kv. reborrow ( ) . into_kv ( ) . 1 ) ;
186
- ( kv. next_back_leaf_edge ( ) , ( k, v) )
187
- } )
196
+ unsafe {
197
+ replace ( self , |leaf_edge| {
198
+ let kv = next_back_kv_unchecked_dealloc ( leaf_edge) ;
199
+ let k = ptr:: read ( kv. reborrow ( ) . into_kv ( ) . 0 ) ;
200
+ let v = ptr:: read ( kv. reborrow ( ) . into_kv ( ) . 1 ) ;
201
+ ( kv. next_back_leaf_edge ( ) , ( k, v) )
202
+ } )
203
+ }
188
204
}
189
205
}
190
206
0 commit comments