Skip to content

Commit 05c3001

Browse files
committed
Auto merge of rust-lang#82440 - ssomers:btree_fix_casts, r=Mark-Simulacrum
BTree: no longer define impossible casts Casts to leaf to internal only make sense when the original has a chance of being the thing it's cast to. r? `@Mark-Simulacrum`
2 parents 3b150b7 + 794561c commit 05c3001

File tree

1 file changed

+10
-8
lines changed
  • library/alloc/src/collections/btree

1 file changed

+10
-8
lines changed

library/alloc/src/collections/btree/node.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ impl<K, V> NodeRef<marker::Dying, K, V, marker::LeafOrInternal> {
460460
}
461461
}
462462

463-
impl<'a, K, V, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
463+
impl<'a, K, V> NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal> {
464464
/// Unsafely asserts to the compiler the static information that this node is a `Leaf`.
465465
unsafe fn cast_to_leaf_unchecked(self) -> NodeRef<marker::Mut<'a>, K, V, marker::Leaf> {
466466
debug_assert!(self.height == 0);
@@ -472,7 +472,9 @@ impl<'a, K, V, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
472472
debug_assert!(self.height > 0);
473473
NodeRef { height: self.height, node: self.node, _marker: PhantomData }
474474
}
475+
}
475476

477+
impl<'a, K, V, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
476478
/// Temporarily takes out another, mutable reference to the same node. Beware, as
477479
/// this method is very dangerous, doubly so since it may not immediately appear
478480
/// dangerous.
@@ -751,15 +753,17 @@ impl<BorrowType, K, V, NodeType, HandleType>
751753
}
752754
}
753755

754-
impl<'a, K, V, NodeType, HandleType> Handle<NodeRef<marker::Mut<'a>, K, V, NodeType>, HandleType> {
756+
impl<'a, K, V, Type> Handle<NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal>, Type> {
755757
/// Unsafely asserts to the compiler the static information that the handle's node is a `Leaf`.
756758
pub unsafe fn cast_to_leaf_unchecked(
757759
self,
758-
) -> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, HandleType> {
760+
) -> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, Type> {
759761
let node = unsafe { self.node.cast_to_leaf_unchecked() };
760762
Handle { node, idx: self.idx, _marker: PhantomData }
761763
}
764+
}
762765

766+
impl<'a, K, V, NodeType, HandleType> Handle<NodeRef<marker::Mut<'a>, K, V, NodeType>, HandleType> {
763767
/// Temporarily takes out another, mutable handle on the same location. Beware, as
764768
/// this method is very dangerous, doubly so since it may not immediately appear
765769
/// dangerous.
@@ -1509,15 +1513,13 @@ impl<BorrowType, K, V> Handle<NodeRef<BorrowType, K, V, marker::Internal>, marke
15091513
}
15101514
}
15111515

1512-
impl<BorrowType, K, V, HandleType>
1513-
Handle<NodeRef<BorrowType, K, V, marker::LeafOrInternal>, HandleType>
1514-
{
1516+
impl<BorrowType, K, V, Type> Handle<NodeRef<BorrowType, K, V, marker::LeafOrInternal>, Type> {
15151517
/// Checks whether the underlying node is an `Internal` node or a `Leaf` node.
15161518
pub fn force(
15171519
self,
15181520
) -> ForceResult<
1519-
Handle<NodeRef<BorrowType, K, V, marker::Leaf>, HandleType>,
1520-
Handle<NodeRef<BorrowType, K, V, marker::Internal>, HandleType>,
1521+
Handle<NodeRef<BorrowType, K, V, marker::Leaf>, Type>,
1522+
Handle<NodeRef<BorrowType, K, V, marker::Internal>, Type>,
15211523
> {
15221524
match self.node.force() {
15231525
ForceResult::Leaf(node) => {

0 commit comments

Comments
 (0)