Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Associated type resolution picks wrong type #22841

Closed
bluss opened this issue Feb 26, 2015 · 1 comment
Closed

Associated type resolution picks wrong type #22841

bluss opened this issue Feb 26, 2015 · 1 comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-typesystem Area: The type system

Comments

@bluss
Copy link
Member

bluss commented Feb 26, 2015

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>`
}
@steveklabnik steveklabnik added the A-typesystem Area: The type system label Feb 26, 2015
@nikomatsakis nikomatsakis added the A-associated-items Area: Associated items (types, constants & functions) label Feb 28, 2015
bluss pushed a commit to petgraph/petgraph that referenced this issue Mar 3, 2015
@bluss
Copy link
Member Author

bluss commented Jun 17, 2015

This is an invalid bug, the fix in #26275 invalidates it.

@bluss bluss closed this as completed Jun 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-typesystem Area: The type system
Projects
None yet
Development

No branches or pull requests

3 participants