Skip to content

Unable to deduce associated type equality #47897

Closed
@freshstrangemusic

Description

@freshstrangemusic

I'm working with combine and rust nightly to make some parsers and I'm wondering why both of these examples are not equivalent:

The first example compiles successfully:

pub fn source<'a, I>() -> impl Parser<Input = I, Output = Source>
where
    I: RangeStream<Item = u8, Range = &'a [u8]>,
    I::Error: ParseError<u8, &'a [u8], I::Position>,
    <I::Error as ParseError<I::Item, I::Range, I::Position>>::StreamError: From<str::Utf8Error>
{
// ...
}

whereas this one

pub fn source<'a, I>() -> impl Parser<Input = I, Output = Source>
where
    I: RangeStream<Item = u8, Range = &'a [u8]>,
    I::Error: ParseError<I::Item, I::Range, I::Position>,
    <I::Error as ParseError<I::Item, I::Range, I::Position>>::StreamError: From<str::Utf8Error>
{
// ...
}

produces this error:

error[E0277]: the trait bound `<I as combine::StreamOnce>::Error: combine::ParseError<u8, &'a [u8], <I as combine::StreamOnce>::Position>` is not satisfied
  --> src/parser.rs:57:1
   |
57 | / pub fn source<'a, I>() -> impl Parser<Input = I, Output = Source>
58 | | where
...  |
89 | |     )
90 | | }
   | |_^ the trait `combine::ParseError<u8, &'a [u8], <I as combine::StreamOnce>::Position>` is not implemented for `<I as combine::StreamOnce>::Error`
   |
   = help: consider adding a `where <I as combine::StreamOnce>::Error: combine::ParseError<u8, &'a [u8], <I as combine::StreamOnce>::Position>` bound

error[E0277]: the trait bound `<I as combine::StreamOnce>::Error: combine::ParseError<u8, &'a [u8], <I as combine::StreamOnce>::Position>` is not satisfied
  --> src/parser.rs:57:1
   |
57 | / pub fn source<'a, I>() -> impl Parser<Input = I, Output = Source>
58 | | where
...  |
89 | |     )
90 | | }
   | |_^ the trait `combine::ParseError<u8, &'a [u8], <I as combine::StreamOnce>::Position>` is not implemented for `<I as combine::StreamOnce>::Error`

AFAICT, the bounds: I::Error: ParseError<u8, &'a [u8], I::Position> and I::Error: ParseError<I::Item, I::Range, I::Position> should be identical since we know I::Item = u8 and I::Range = &'a [u8].

Is this a limitation of the compiler's inference, a bug, or something else?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)C-enhancementCategory: An issue proposing an enhancement or a PR with one.E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleE-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.T-langRelevant to the language 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