Skip to content

Type inferencer probably could figure this case out (associated types) #23728

Open
@carllerche

Description

@carllerche
trait Async {
    type Value;
    type Error;
}

enum Result<T, E> {
    Ok(T),
    Err(E),
}

impl<T, E> Result<T, E> {
    fn reduce<F, U>(self, init: U::Value, action: F) -> U::Value
            where F: Fn(U::Value, T) -> U,
                  U: Async<Error=E> {
        unimplemented!();
    }
}

impl Async for i32 {
    type Value = i32;
    type Error = ();
}

pub fn main() {
    let res: Result<&'static str, ()> = Result::Ok("hello");
    let val: i32 = 123;

    res.reduce(val, |val /* i32 */, curr| val);
    // Compiles if annotated ^^
}

cc @nikomatsakis

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-inferenceArea: Type inferenceA-type-systemArea: Type systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types 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