Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BTreeMap: relax the explicit borrow rule to make code shorter and safer #79521

Merged
merged 1 commit into from
Dec 24, 2020

Conversation

ssomers
Copy link
Contributor

@ssomers ssomers commented Nov 28, 2020

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 28, 2020
@jyn514 jyn514 added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Dec 1, 2020
@ssomers ssomers changed the title BTreeMap: relax the explicit borrow rule to shorten borrows and code BTreeMap: relax the explicit borrow rule to make code shorter and safer Dec 12, 2020
@Mark-Simulacrum
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Dec 13, 2020

📌 Commit 22d06052a76860c4ff84198fbb9c068ac4cb0909 has been approved by Mark-Simulacrum

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 13, 2020
@Mark-Simulacrum
Copy link
Member

@bors rollup=never

@bors
Copy link
Contributor

bors commented Dec 14, 2020

🔒 Merge conflict

This pull request and the master branch diverged in a way that cannot be automatically merged. Please rebase on top of the latest master branch, and let the reviewer approve again.

How do I rebase?

Assuming self is your fork and upstream is this repository, you can resolve the conflict following these steps:

  1. git checkout btree_cleanup_2 (switch to your branch)
  2. git fetch upstream master (retrieve the latest master)
  3. git rebase upstream/master -p (rebase on top of it)
  4. Follow the on-screen instruction to resolve conflicts (check git status if you got lost).
  5. git push self btree_cleanup_2 --force-with-lease (update this PR)

You may also read Git Rebasing to Resolve Conflicts by Drew Blessing for a short tutorial.

Please avoid the "Resolve conflicts" button on GitHub. It uses git merge instead of git rebase which makes the PR commit history more difficult to read.

Sometimes step 4 will complete without asking for resolution. This is usually due to difference between how Cargo.lock conflict is handled during merge and rebase. This is normal, and you should still perform step 5 to update this PR.

Error message
Auto-merging library/alloc/src/collections/btree/node.rs
CONFLICT (content): Merge conflict in library/alloc/src/collections/btree/node.rs
Automatic merge failed; fix conflicts and then commit the result.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Dec 14, 2020
@ssomers
Copy link
Contributor Author

ssomers commented Dec 14, 2020

The conflict in clear_parent_link, and the fact that the previous code no longer compiles with:

error[E0716]: temporary value dropped while borrowed
   --> library\alloc\src\collections\btree\node.rs:632:46
    |
632 |         let leaf = NodeRef::as_leaf_mut(&mut self.borrow_mut());
    |                                              ^^^^^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
    |                                              |
    |                                              creates a temporary which is freed while still in use
633 |         leaf.parent = None;
    |         ------------------ borrow later used here
    |

reminds me of an issue I tried in vain to list here in an earlier version of the description: the old definition of fn as_leaf(this: &Self) -> &'a LeafNode<K, V> was more dangerous than it is after this PR: it extended the return value's lifetime beyond the &Self borrow.

@ssomers
Copy link
Contributor Author

ssomers commented Dec 14, 2020

Actually, these lifetime rules must be right because they mimic the public API of OccupiedEntry.

@bors
Copy link
Contributor

bors commented Dec 17, 2020

☔ The latest upstream changes (presumably #80114) made this pull request unmergeable. Please resolve the merge conflicts.

Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels:

@rustbot modify labels: +S-waiting-on-review -S-waiting-on-author

@ssomers
Copy link
Contributor Author

ssomers commented Dec 17, 2020

@rustbot modify labels: +S-waiting-on-review -S-waiting-on-author

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 17, 2020
@Mark-Simulacrum
Copy link
Member

@bors r+ rollup=never

@bors
Copy link
Contributor

bors commented Dec 23, 2020

📌 Commit 29114ff has been approved by Mark-Simulacrum

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 23, 2020
@bors
Copy link
Contributor

bors commented Dec 23, 2020

⌛ Testing commit 29114ff with merge 3d10d3e...

@bors
Copy link
Contributor

bors commented Dec 24, 2020

☀️ Test successful - checks-actions
Approved by: Mark-Simulacrum
Pushing 3d10d3e to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Dec 24, 2020
@bors bors merged commit 3d10d3e into rust-lang:master Dec 24, 2020
@rustbot rustbot added this to the 1.50.0 milestone Dec 24, 2020
@ssomers ssomers deleted the btree_cleanup_2 branch December 24, 2020 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants