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?

Activity

Marwes

Marwes commented on Jan 31, 2018

@Marwes
Contributor

@brennie I believe this is #43475 (and a few other issues linked from that post). I think this is planned to be fixed with the trait system rewrite (lazy normalization) but I don't know what the timeline is for that :(.

rkarp

rkarp commented on Feb 3, 2018

@rkarp
Contributor

The oldest related issue seems to be #24159, which was even before Rust 1.0. I think fixing this should be a priority considering that many people have run into this over almost 3 years.

added
C-enhancementCategory: An issue proposing an enhancement or a PR with one.
A-associated-itemsArea: Associated items (types, constants & functions)
on Feb 6, 2018
changed the title [-]Inable to deduce associated type equality[/-] [+]Unable to deduce associated type equality[/+] on Nov 5, 2019
added a commit that references this issue on Feb 2, 2021

Rollup merge of rust-lang#81485 - jackh726:atb-issues, r=Mark-Simulacrum

acd5b4b
added
E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.
on Feb 2, 2021
jackh726

jackh726 commented on Dec 25, 2023

@jackh726
Member

I'm going to close this since it may be fixed already, but regardless doesn't have an MCVE. There are cases where we'll still run into these types of problems, but I know there are other issues covering more complex cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @freshstrangemusic@Marwes@estebank@jonas-schievink@pietroalbini

        Issue actions

          Unable to deduce associated type equality · Issue #47897 · rust-lang/rust