Skip to content

Some std::collections types are unnecessarily invariant #30642

Open
@apasel422

Description

@apasel422

The following std::collections types are unnecessarily invariant in their type parameters:

  • binary_heap::Drain
  • btree_map::{Keys, Values}
  • btree_set::{IntoIter, Iter, Range}
  • btree_set::{Difference, Intersection, SymmetricDifference, Union}
  • hash_map::{IntoIter, Iter, Keys, Values}
  • hash_map::Drain
  • hash_set::{Difference, Intersection, IntoIter, Iter, SymmetricDifference, Union}
  • hash_set::Drain
  • linked_list::{IntoIter, Iter, LinkedList}
  • vec::Drain
  • vec_deque::Drain

Some, like btree_map::Keys, are invariant due to the use of iter::Map with fn(T) -> U being invariant over T, while others, like LinkedList, are due to the ultimate use of *mut T, and the rest are wrappers around other invariant iterators.

Of these, the most important to fix is probably LinkedList, as the rest are iterators. Given the issue with iter::Map, it is likely that some other iterators in std have the same problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-collectionsArea: `std::collections`C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions