Skip to content

HashMap.clear() leads to VacantEntry.set() asserting #19485

Closed
@frankmcsherry

Description

@frankmcsherry

The following code causes a panic in set(i) ('assertion failed: probe.index() != idx_end'). The current belief is that clear() causes the underlying array to shrink below tested levels (being fixed independently), at which point a corner case may show up in insertion.

use std::collections::HashMap;
use std::collections::hash_map::Vacant;

fn main()
{
    let mut m = HashMap::with_capacity(4); 

    m.clear(); 

    for i in range(0u, 4) 
    { 
        match m.entry(i) 
        { 
            Vacant(x) => { x.set(i); }, 
            _ => {}, 
        } 
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions