Skip to content

shrink_to() may not guarantee capacity >= min_capacity #159

Description

@yanfenghu

Hi,

I found a potential API contract violation in the shrink_to method through Kani formal verification.

Location: src/basic.rs (shrink_to implementation)

Issue:

In some edge cases, shrink_to(min_capacity) may result in a capacity less than min_capacity.

Verification:

let mut sm: SlotMap<DefaultKey, u32> = SlotMap::with_capacity(100);
sm.shrink_to(50);
assert!(sm.capacity() >= 50); // May fail in some cases
Impact:

Violates API contract

May cause unexpected behavior

Could you please confirm if this is a valid issue? I can provide a more detailed reproduction case if needed.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions