@@ -424,7 +424,7 @@ where
424
424
while !node. is_null ( ) {
425
425
// SAFETY: By the type invariant of `Self`, all non-null `rb_node` pointers stored in `self`
426
426
// point to the links field of `Node<K, V>` objects.
427
- let this = unsafe { container_of ! ( node, Node <K , V >, links) } . cast_mut ( ) ;
427
+ let this = unsafe { container_of ! ( node, Node <K , V >, links) } ;
428
428
// SAFETY: `this` is a non-null node so it is valid by the type invariants.
429
429
let this_key = unsafe { & ( * this) . key } ;
430
430
// SAFETY: `node` is a non-null node so it is valid by the type invariants.
@@ -496,7 +496,7 @@ impl<K, V> Drop for RBTree<K, V> {
496
496
// but it is not observable. The loop invariant is still maintained.
497
497
498
498
// SAFETY: `this` is valid per the loop invariant.
499
- unsafe { drop ( KBox :: from_raw ( this. cast_mut ( ) ) ) } ;
499
+ unsafe { drop ( KBox :: from_raw ( this) ) } ;
500
500
}
501
501
}
502
502
}
@@ -761,7 +761,7 @@ impl<'a, K, V> Cursor<'a, K, V> {
761
761
let next = self . get_neighbor_raw ( Direction :: Next ) ;
762
762
// SAFETY: By the type invariant of `Self`, all non-null `rb_node` pointers stored in `self`
763
763
// point to the links field of `Node<K, V>` objects.
764
- let this = unsafe { container_of ! ( self . current. as_ptr( ) , Node <K , V >, links) } . cast_mut ( ) ;
764
+ let this = unsafe { container_of ! ( self . current. as_ptr( ) , Node <K , V >, links) } ;
765
765
// SAFETY: `this` is valid by the type invariants as described above.
766
766
let node = unsafe { KBox :: from_raw ( this) } ;
767
767
let node = RBTreeNode { node } ;
@@ -806,7 +806,7 @@ impl<'a, K, V> Cursor<'a, K, V> {
806
806
unsafe { bindings:: rb_erase ( neighbor, addr_of_mut ! ( self . tree. root) ) } ;
807
807
// SAFETY: By the type invariant of `Self`, all non-null `rb_node` pointers stored in `self`
808
808
// point to the links field of `Node<K, V>` objects.
809
- let this = unsafe { container_of ! ( neighbor, Node <K , V >, links) } . cast_mut ( ) ;
809
+ let this = unsafe { container_of ! ( neighbor, Node <K , V >, links) } ;
810
810
// SAFETY: `this` is valid by the type invariants as described above.
811
811
let node = unsafe { KBox :: from_raw ( this) } ;
812
812
return Some ( RBTreeNode { node } ) ;
@@ -912,7 +912,7 @@ impl<'a, K, V> Cursor<'a, K, V> {
912
912
unsafe fn to_key_value_raw < ' b > ( node : NonNull < bindings:: rb_node > ) -> ( & ' b K , * mut V ) {
913
913
// SAFETY: By the type invariant of `Self`, all non-null `rb_node` pointers stored in `self`
914
914
// point to the links field of `Node<K, V>` objects.
915
- let this = unsafe { container_of ! ( node. as_ptr( ) , Node <K , V >, links) } . cast_mut ( ) ;
915
+ let this = unsafe { container_of ! ( node. as_ptr( ) , Node <K , V >, links) } ;
916
916
// SAFETY: The passed `node` is the current node or a non-null neighbor,
917
917
// thus `this` is valid by the type invariants.
918
918
let k = unsafe { & ( * this) . key } ;
@@ -1021,7 +1021,7 @@ impl<K, V> Iterator for IterRaw<K, V> {
1021
1021
1022
1022
// SAFETY: By the type invariant of `IterRaw`, `self.next` is a valid node in an `RBTree`,
1023
1023
// and by the type invariant of `RBTree`, all nodes point to the links field of `Node<K, V>` objects.
1024
- let cur = unsafe { container_of ! ( self . next, Node <K , V >, links) } . cast_mut ( ) ;
1024
+ let cur = unsafe { container_of ! ( self . next, Node <K , V >, links) } ;
1025
1025
1026
1026
// SAFETY: `self.next` is a valid tree node by the type invariants.
1027
1027
self . next = unsafe { bindings:: rb_next ( self . next ) } ;
@@ -1216,7 +1216,7 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> {
1216
1216
// SAFETY:
1217
1217
// - `self.node_links` is a valid pointer to a node in the tree.
1218
1218
// - We have exclusive access to the underlying tree, and can thus give out a mutable reference.
1219
- unsafe { & mut ( * ( container_of ! ( self . node_links, Node <K , V >, links) . cast_mut ( ) ) ) . value }
1219
+ unsafe { & mut ( * ( container_of ! ( self . node_links, Node <K , V >, links) ) ) . value }
1220
1220
}
1221
1221
1222
1222
/// Converts the entry into a mutable reference to its value.
@@ -1226,7 +1226,7 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> {
1226
1226
// SAFETY:
1227
1227
// - `self.node_links` is a valid pointer to a node in the tree.
1228
1228
// - This consumes the `&'a mut RBTree<K, V>`, therefore it can give out a mutable reference that lives for `'a`.
1229
- unsafe { & mut ( * ( container_of ! ( self . node_links, Node <K , V >, links) . cast_mut ( ) ) ) . value }
1229
+ unsafe { & mut ( * ( container_of ! ( self . node_links, Node <K , V >, links) ) ) . value }
1230
1230
}
1231
1231
1232
1232
/// Remove this entry from the [`RBTree`].
@@ -1239,9 +1239,7 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> {
1239
1239
RBTreeNode {
1240
1240
// SAFETY: The node was a node in the tree, but we removed it, so we can convert it
1241
1241
// back into a box.
1242
- node : unsafe {
1243
- KBox :: from_raw ( container_of ! ( self . node_links, Node <K , V >, links) . cast_mut ( ) )
1244
- } ,
1242
+ node : unsafe { KBox :: from_raw ( container_of ! ( self . node_links, Node <K , V >, links) ) } ,
1245
1243
}
1246
1244
}
1247
1245
@@ -1272,8 +1270,7 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> {
1272
1270
// SAFETY:
1273
1271
// - `self.node_ptr` produces a valid pointer to a node in the tree.
1274
1272
// - Now that we removed this entry from the tree, we can convert the node to a box.
1275
- let old_node =
1276
- unsafe { KBox :: from_raw ( container_of ! ( self . node_links, Node <K , V >, links) . cast_mut ( ) ) } ;
1273
+ let old_node = unsafe { KBox :: from_raw ( container_of ! ( self . node_links, Node <K , V >, links) ) } ;
1277
1274
1278
1275
RBTreeNode { node : old_node }
1279
1276
}
0 commit comments