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

Does not infer associated type in another associated type #2603

Closed
edwin0cheng opened this issue Dec 19, 2019 · 6 comments
Closed

Does not infer associated type in another associated type #2603

edwin0cheng opened this issue Dec 19, 2019 · 6 comments
Labels
A-ty type system / type inference / traits / method resolution

Comments

@edwin0cheng
Copy link
Member

It is related to #2592:

struct Bar;
struct Foo;

trait A {
    type OutputA;
}

impl A for Bar {
    type OutputA = Foo;
}

trait B {
    type Output;    
    fn foo() -> Self::Output;
}

impl<T:A> B for T {
    type Output = T::OutputA;
    fn foo() -> Self::Output { loop {} }
}

fn main() {
    let b = Bar::foo();  // <- b is unknown    
}
@edwin0cheng edwin0cheng changed the title Does not infer associated Type in another assoiated Type Does not infer associated type in another assoiated type Dec 19, 2019
@edwin0cheng edwin0cheng changed the title Does not infer associated type in another assoiated type Does not infer associated type in another associated type Dec 19, 2019
@flodiebold
Copy link
Member

I think this is a slightly different issue than the one in #2592. This one I think is probably related to rust-lang/chalk#234; the one in #2592 is more complicated, because Chalk would need to know that integer variables can only be one of a few different types for that one.

@flodiebold flodiebold added the A-ty type system / type inference / traits / method resolution label Dec 26, 2019
@flodiebold
Copy link
Member

Another case possibly related to that Chalk issue:

trait T {
    type O;
}

impl T for () {
    type O = ();
}

fn f<X, F>(_v: F)
where
    X: T,
    F: FnOnce(X::O),
{
}

fn main() {
    f::<(), _>(|_z| {});
}

@flodiebold
Copy link
Member

Another simple case:

    let mut action_contexts: Vec<i32> = vec![1, 2, 3];
    for v in action_contexts.iter_mut() {
        dbg!(v);
    }

@flodiebold
Copy link
Member

Example from #3548:

    let x = vec![Foo {i: 1}, Foo {i: 2}];
    if let Some(found) = x.iter().find(|x| x.i == 1) {
        found.<CURSOR_HERE>
    }

@flodiebold
Copy link
Member

All these examples work now 🎉

@edwin0cheng
Copy link
Member Author

So do iterator work now ? Yeah

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ty type system / type inference / traits / method resolution
Projects
None yet
Development

No branches or pull requests

2 participants