Skip to content

Fix DenseSlotMap::try_insert_with_key panic docs - #163

Open
hxperl wants to merge 1 commit into
orlp:masterfrom
hxperl:fix-dense-try-insert-panics-doc
Open

hxperl wants to merge 1 commit into
orlp:masterfrom
hxperl:fix-dense-try-insert-panics-doc

Conversation

@hxperl

@hxperl hxperl commented Sep 15, 2026 •

Copy link
Copy Markdown

DenseSlotMap::try_insert_with_key documents a panic its body cannot produce — "the number of elements equals 2³² − 2". The only panic is on the slot vector length:

if self.slots.len() >= u32::MAX as usize { panic!("DenseSlotMap is full"); }

There is no element counter in DenseSlotMap. The two methods above it wrap this exact function and both say "Panics if the slot map is full" — same code path, contradictory docs.

A missed line: 223d022 added the 2³²−2 wording to all three maps, 53ba2b2 fixed three occurrences in basic.rs but only two in dense.rs. HopSlotMap keeps it, and there it is accurate.

One doc line. cargo test: 17 + 191 doctests green.

If you meant Dense to have Hop's cap and the code is what is wrong, say so and I will redo it.

53ba2b2 replaced the "2^32 - 2 elements" panic wording with "Panics if
the slot map is full." in basic.rs (all three insert methods) and in
dense.rs, but dense.rs's try_insert_with_key was missed. It is the
function insert and insert_with_key both delegate to, so its documented
panic condition must match theirs; its only panic is

    if self.slots.len() >= u32::MAX as usize {
        panic!("DenseSlotMap is full");
    }

which is not an element-count check. Align the wording with the two
callers.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant