Skip to content

Document the behaviour of BTreeMap::extend - #158069

Open
Timmmm wants to merge 1 commit into
rust-lang:mainfrom
Timmmm:patch-2
Open

Document the behaviour of BTreeMap::extend#158069
Timmmm wants to merge 1 commit into
rust-lang:mainfrom
Timmmm:patch-2

Conversation

@Timmmm

@Timmmm Timmmm commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

It was unclear from the existing documentation how duplicate elements would be handled.

No AI was used for this PR.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jun 18, 2026
@rustbot

rustbot commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

r? @joboet

rustbot has assigned @joboet.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 11 candidates
  • Random selection from 6 candidates

@rust-log-analyzer

This comment has been minimized.

Comment thread library/alloc/src/collections/btree/map.rs Outdated
@Timmmm

Timmmm commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

I added the same docs to HashMap too.

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

#[stable(feature = "rust1", since = "1.0.0")]
impl<K: Ord, V, A: Allocator + Clone> Extend<(K, V)> for BTreeMap<K, V, A> {
/// Add all elements from `iter` to this map by calling [`BTreeMap::insert`]

@camsteffen camsteffen Jun 28, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would avoid promising that insert is called since that is an implementation detail that could change. It could say:

Inserts each entry into the map. Existing entries with the same key are replaced.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can't change in a way that makes it not semantically equivalent to calling insert. I could say Add all elements from iter to this map, as if insert was called for each element or something... but that seems a bit awkward and pedantic.

I think duplicating the insert documentation is not as good because you lose information. For example with your version you don't get this:

The key is not updated, though; this matters for types that can be == without being identical. See the module-level documentation for more.

It was unclear from the existing documentation how duplicate elements would be handled.
@joboet

joboet commented Jul 29, 2026

Copy link
Copy Markdown
Member

Sorry for not getting back sooner. This looks reasonable, but I'll reassign to someone from libs-api just as a cautionary measure.

r? libs-api

@rustbot rustbot added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Jul 29, 2026
@rustbot rustbot assigned BurntSushi and unassigned joboet Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants