Skip to content

The key parameter of Index should be made an associated type #20523

@sfackler

Description

@sfackler

The orphan check rules currently prevent implementations of Index with the key type generic over BorrowFrom.

src/ordered_map.rs:64:1: 70:2 error: type parameter `T` must also appear as a type parameter of some type defined within this crate
src/ordered_map.rs:64 impl<K, V, Sized? T> Index<T> for OrderedMap<K, V> where T: Eq + PhfHash + BorrowFrom<K> {
src/ordered_map.rs:65     type Output = V;
src/ordered_map.rs:66 
src/ordered_map.rs:67     fn index(&self, k: &T) -> &V {
src/ordered_map.rs:68         self.get(k).expect("invalid key")
src/ordered_map.rs:69     }
                      ...
src/ordered_map.rs:64:1: 70:2 note: for a limited time, you can add `#![feature(old_orphan_check)]` to your crate to disable this rule
src/ordered_map.rs:64 impl<K, V, Sized? T> Index<T> for OrderedMap<K, V> where T: Eq + PhfHash + BorrowFrom<K> {
src/ordered_map.rs:65     type Output = V;
src/ordered_map.rs:66 
src/ordered_map.rs:67     fn index(&self, k: &T) -> &V {
src/ordered_map.rs:68         self.get(k).expect("invalid key")
src/ordered_map.rs:69     }
                      ...

cc @nikomatsakis @japaric

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions