Skip to content

The clear method in std::oldmap::HashMap now takes &mut self - and this leads to illegal borrow unless pure errors #4870

Closed
@Dretch

Description

@Dretch

std::oldmap::HashMap now takes &mut self:

impl<K: Eq IterBytes Hash, V> T<K, V>: Mutable {
    fn clear(&mut self) {
        self.count = 0u;
        self.chains = chains(initial_capacity);
    }
}

I am finding this rather awkward because HashMap also has methods like insert and remove that do not take mutable self, but are also non-pure. What this means is that I can't make my field of type std::oldmap::HashMap mut, because then rustc complains about illegal borrow unless pure when calling insert/remove, and I can't make it non-mut because then I can't call clear on it...

Does it make sense for HashMap to implement Mutable? AFAICT HashMap doesn't need mutable self because it mutates by changing its internal fields, not by creating a new instance of itself.

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