Skip to content

Associated type resolution picks wrong type #22841

Closed
@bluss

Description

@bluss

To me it looks like all the function signatures try to produce Dfs<G::NodeId, G::Map>, but rustc thinks I produce Dfs<G::Map, G::Map> and throws a type error. (The associated types are part of different traits, that inherit.)

rustc version: rustc 1.0.0-nightly (4db0b3246 2015-02-25) (built 2015-02-26)

Testcase, derived from this repo.

pub trait Graphlike {
    type NodeId;
}

pub trait Visitable : Graphlike {
    type Map;
}

pub struct Dfs<N, VM> {
    pub stack: Vec<N>,
    pub discovered: VM,
}

impl<G> Dfs<G::NodeId, G::Map> where G: Visitable
{
    pub fn new(graph: &G, _start: G::NodeId) -> Self
    {
        panic!()
    }
}

pub fn new<G>(graph: &G, start: G::NodeId) where G: Visitable
{
    let dfs: Dfs<G::NodeId, G::Map> = Dfs::new(graph, start);
    // ^ERROR:
    // error: mismatched types:
    //  expected `Dfs<<G as Graphlike>::NodeId, <G as Visitable>::Map>`,
    //     found `Dfs<<G as Visitable>::Map, <G as Visitable>::Map>`
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-type-systemArea: Type system

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions