Skip to content

Commit

Permalink
Auto merge of rust-lang#79521 - ssomers:btree_cleanup_2, r=Mark-Simul…
Browse files Browse the repository at this point in the history
…acrum

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`
  • Loading branch information
bors committed Dec 23, 2020
2 parents 7f9c43c + 29114ff commit 3d10d3e
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 106 deletions.
2 changes: 1 addition & 1 deletion library/alloc/src/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ where
let (map, dormant_map) = DormantMutRef::new(self);
let root_node = Self::ensure_is_owned(&mut map.root).borrow_mut();
match search::search_tree::<marker::Mut<'_>, K, (), K>(root_node, &key) {
Found(handle) => Some(mem::replace(handle.into_key_mut(), key)),
Found(mut kv) => Some(mem::replace(kv.key_mut(), key)),
GoDown(handle) => {
VacantEntry { key, handle, dormant_map, _marker: PhantomData }.insert(());
None
Expand Down
Loading

0 comments on commit 3d10d3e

Please sign in to comment.