You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
VacantEntry::insert receives a value and returns a reference to the value's final location. Internally, it passes the value several levels down the stack, sneaks back a pointer to the place where the value was written, and converts that pointer to a reference at the last minute. I think it's actually safer and more efficient to not pass the value around, but only the location, and write the value there at the last minute.
Safer because every use of VacantEntry::insert (including your average BTreeMap::insert) ensures the correct address is returned, whereas now there is only one unit test (in test_entry) superficially testing that the returned reference really points to the value.
Hey! It looks like you've submitted a new PR for the library teams!
If this PR contains changes to any rust-lang/rust public library APIs then please comment with r? rust-lang/libs-api @rustbot label +T-libs-api -T-libs to request review from a libs-api team reviewer. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.
Examples of T-libs-api changes:
Stabilizing library features
Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
Changing public documentation in ways that create new stability guarantees
Changing observable runtime behavior of library APIs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
S-waiting-on-reviewStatus: Awaiting review from the assignee but also interested parties.T-libsRelevant to the library team, which will review and decide on the PR/issue.
5 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
VacantEntry::insertreceives a value and returns a reference to the value's final location. Internally, it passes the value several levels down the stack, sneaks back a pointer to the place where the value was written, and converts that pointer to a reference at the last minute. I think it's actually safer and more efficient to not pass the value around, but only the location, and write the value there at the last minute.VacantEntry::insert(including your averageBTreeMap::insert) ensures the correct address is returned, whereas now there is only one unit test (intest_entry) superficially testing that the returned reference really points to the value.