Skip to content

type mismatch resolving <Thing as FromStr>::Err == <Thing as FromStr>::Err, with impl trait #41407

@ben0x539

Description

@ben0x539

Got this diagnostic trying to avoid having to look up what error type hyper's Uri std::str::FromStr impl returns by using <Uri as FromStr>::Err as the error type of Future and then returning it abstractly: fn foo() -> impl Future<Item=Uri, Error=<Uri as FromStr>::Err>.

Kinda sounds like #34257, but the diagnostic is more confusing and it seems to depend on impl trait.

rustc 1.18.0-nightly (9f2abad 2017-04-18)

A reduced version with no external types (playground):

#![feature(conservative_impl_trait)]

struct Thing;
struct ThingError;

trait FakeFromStr {
    type Err;
}

fn fake_parse<T: FakeFromStr>() -> Result<T, T::Err> { panic!() } 

impl FakeFromStr for Thing {
    type Err = ThingError;
}

trait FakeFuture {
    type Item;
    type Error;
}

struct FakeFutureResult<A, B>(Result<A, B>);
impl<A, B> FakeFuture for FakeFutureResult<A, B> {
    type Item = A;
    type Error = B;
}

fn foo() -> impl FakeFuture<Item=Thing, Error=<Thing as FakeFromStr>::Err> {
    FakeFutureResult(fake_parse())
}

fn main() {
    let _ = foo();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.T-compilerRelevant to the compiler 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