Skip to content

Commit 3d10d3e

Browse files
committed
Auto merge of #79521 - ssomers:btree_cleanup_2, r=Mark-Simulacrum
BTreeMap: relax the explicit borrow rule to make code shorter and safer Expressions like `.reborrow_mut().into_len_mut()` are annoyingly long, and kind of dangerous for the reason `reborrow_mut()` is unsafe. By relaxing the single rule, we no longer have to make an exception for functions with a `borrow` name and functions like `as_leaf_mut`. This is largely restoring the declaration style of the btree::node API about a year ago, but with more explanation and consistency. r? `@Mark-Simulacrum`
2 parents 7f9c43c + 29114ff commit 3d10d3e

File tree

2 files changed

+108
-106
lines changed

2 files changed

+108
-106
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ where
248248
let (map, dormant_map) = DormantMutRef::new(self);
249249
let root_node = Self::ensure_is_owned(&mut map.root).borrow_mut();
250250
match search::search_tree::<marker::Mut<'_>, K, (), K>(root_node, &key) {
251-
Found(handle) => Some(mem::replace(handle.into_key_mut(), key)),
251+
Found(mut kv) => Some(mem::replace(kv.key_mut(), key)),
252252
GoDown(handle) => {
253253
VacantEntry { key, handle, dormant_map, _marker: PhantomData }.insert(());
254254
None

0 commit comments

Comments
 (0)