Conversation
PR indexmap-rs#448 unified the index assertions in this file, but Core::shift_insert_unique kept a bare assert!(index <= end) and is the only index-taking Core method that panics without #[track_caller]. That leaks through the public VacantEntry::shift_insert, which panics with "assertion failed: index <= end" located in indexmap's internals instead of the caller. Also covers RawVacantEntryMut::shift_insert and shift_insert_hashed_nocheck, which reach the same assertion.
youdie006
force-pushed
the
track-caller-shift-insert-unique
branch
from
September 15, 2026 02:26
4f991e2 to
bef5fff
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
#448 unified the index assertions in
src/inner.rs, butCore::shift_insert_uniquekept its bareassert!(index <= end)(src/inner.rs:531) and is the only index-takingCoremethod that panics without#[track_caller]—drain:173,split_off:196,split_splice:208,replace_index_unique:508,move_index:648 andswap_indices:677 all have it. (shift_remove_index:551 andswap_remove_index:574 take an index too, but returnOptionand never panic.)That leaks through the public
VacantEntry::shift_insert, whose doc atsrc/inner/entry.rs:363promises***Panics*** if index is out of bounds. Its neighbour in the same impl block,VacantEntry::replace_index(src/inner/entry.rs:381), carries the same doc line and does it right.On a map of len 1, inserting at index 5:
IndexMap::shift_insertindex out of bounds: the len is 1 but the index is 5. Expected index <= lenIndexMap::insert_beforeVacantEntry::shift_insertassertion failed: index <= endindexmap/src/inner.rs:531stdVec::insert(reference)insertion index (is 5) should be <= len (is 1)RawVacantEntryMut::shift_insertandshift_insert_hashed_nocheck(src/map/raw_entry_v1.rs:596,612) reach the same assertion and are fixed by the same two lines.IndexMap::shift_insertandIndexMap::insert_beforealready assert before delegating, so they are unaffected.Verification
Base
41a8708. Three tests: the message (vacant_entry_shift_insert_oob), the guard row whereindex == lenmust still succeed (vacant_entry_shift_insert_at_len), and the location. The location test replaces the global panic hook, so it lives in its own test binary (tests/track_caller.rs) rather than in the shared--libharness.src/inner.rsmd5--lib vacant_entry--test track_caller725aaef7…"assertion failed: index <= end")panic reported at src/inner.rs)d8c71a57…assert!(index <= end)f64c4378……_oobfailedassert_index_lt1bc23f6c……_ooband…_at_lenfailed#[track_caller]87eff44f…Each mutant was killed by a different test, so the two halves of the change are independently covered. Every mutated md5 differs from GREEN's, and each anchor's occurrence count was asserted as 1 before the rewrite.
CI gates, run as
.github/workflows/ci.ymlwrites them:cargo test/cargo test --release, features"",arbitrary,quickcheck,rayon,serde,sval,borsh,stdbuild,doc,test,test --releasecargo clippy --all-featurescargo doc --all-featurescargo build --target=thumbv6m-none-eabi --no-default-featurescargo miri test --doccargo miri teston both new binariesIf you would rather not carry the panic-hook test, the
#[track_caller]line stands on #367 and #389 on its own and that file can be dropped.Disclosure: written with the help of Claude (an AI assistant). The verification above is from runs on my machine; I have reviewed the change and stand behind it.