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

Unable to deduce associated type equality #47897

Closed
brennie opened this issue Jan 31, 2018 · 3 comments
Closed

Unable to deduce associated type equality #47897

brennie opened this issue Jan 31, 2018 · 3 comments
Labels
A-associated-items Area: Associated items (types, constants & functions) C-enhancement Category: An issue proposing an enhancement or a PR with one. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@brennie
Copy link

brennie commented Jan 31, 2018

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?

@Marwes
Copy link
Contributor

Marwes commented Jan 31, 2018

@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
Copy link
Contributor

rkarp commented Feb 3, 2018

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.

@pietroalbini pietroalbini added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-associated-items Area: Associated items (types, constants & functions) labels Feb 6, 2018
@estebank estebank changed the title Inable to deduce associated type equality Unable to deduce associated type equality Nov 5, 2019
@estebank estebank added F-associated_type_bounds `#![feature(associated_type_bounds)]` T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Nov 5, 2019
@jonas-schievink jonas-schievink removed the F-associated_type_bounds `#![feature(associated_type_bounds)]` label Jan 28, 2021
JohnTitor added a commit to JohnTitor/rust that referenced this issue Feb 2, 2021
Add some tests for associated-type-bounds issues

Closes rust-lang#38917
Closes rust-lang#40093
Closes rust-lang#43475
Closes rust-lang#63591

rust-lang#47897 is likely closable too, but it needs an MCVE
~~rust-lang#38917, rust-lang#40093, rust-lang#43475, rust-lang#47897 all are mislabeled and shouldn't have the `F-associated-type-bounds` label~~

~~rust-lang#71685 is also mislabeled as commented on in that thread~~
@estebank estebank added E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. labels Feb 2, 2021
@jackh726
Copy link
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
Labels
A-associated-items Area: Associated items (types, constants & functions) C-enhancement Category: An issue proposing an enhancement or a PR with one. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants