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

Rustc failed to resolve trait bounds for trait implementation #44591

Open
weiznich opened this issue Sep 15, 2017 · 9 comments
Open

Rustc failed to resolve trait bounds for trait implementation #44591

weiznich opened this issue Sep 15, 2017 · 9 comments

Comments

@weiznich
Copy link
Contributor

@weiznich weiznich commented Sep 15, 2017

While trying to do some magic with traits I've stumbled over the following issue:
Rustc is telling me that some trait bound is missing and suggest to add this bound. Now is the issue that exactly this bounds is already in the where clause.

More or less minimal self contained example

Workaround:
Replace every occurrence of Collection in the Factory trait with Vec<TypeA>, but this removes the freedom the add additional impl's of Factory using other collection types.

@Mark-Simulacrum

This comment has been minimized.

Copy link
Member

@Mark-Simulacrum Mark-Simulacrum commented Sep 17, 2017

This is another case of insufficient normalization, I believe. cc @arielb1

@bkchr

This comment has been minimized.

Copy link
Contributor

@bkchr bkchr commented Nov 1, 2018

I think I found another occurrence of this "bug". The following example shows it. I would assume that I don't need to replicate the where clause of Test2 on the implementation of TestImpl.

@bkchr

This comment has been minimized.

Copy link
Contributor

@bkchr bkchr commented Jul 1, 2019

@Mark-Simulacrum @arielb1 any chance to get an update for this? With some mentoring I could maybe look into this.

@Mark-Simulacrum

This comment has been minimized.

Copy link
Member

@Mark-Simulacrum Mark-Simulacrum commented Jul 1, 2019

I'm not sure how easy this type of bug is to provide mentoring for; cc @eddyb @nikomatsakis -- perhaps you could determine that better than I?

@tmandry

This comment has been minimized.

Copy link
Contributor

@tmandry tmandry commented Sep 13, 2019

I don't know of a short-term fix. That said, an interesting data point would be to run this program through chalk and see if it can solve the constraints correctly. See here for an overview of chalk.

The basic steps are to clone chalk, start the chalk repl with cargo run, load your program with load <filename>, then run the lowered command to see if it gives you any well-formedness errors when lowering your program.

You'll have to modify your program for chalk to accept it, however. In particular, there are no methods in chalk. You can express everything you need to with structs, traits, impls, where clauses, and associated types.

Chalk doesn't have access to the standard library, so you'll need to include these definitions. There are no tuple types either, but you can replace them with structs. Here's a starter for you:

trait Sized {}
trait FromIterator<A> {}
trait Iterator {
  type Item;
}
struct Vec<T> {}
struct Tup1<A> {}
struct Tup2<A, B> {}
// impl for FromIterator here; you may need to define IntoIterator
// continue with the rest of your program
@estebank

This comment has been minimized.

Copy link
Contributor

@estebank estebank commented Oct 8, 2019

Current output:

error[E0277]: the trait bound `<I as std::iter::Iterator>::Item: Collectable<std::vec::Vec<TypeA>>` is not satisfied
   --> src/main.rs:155:5
    |
155 | /     fn make_from_iter<I>(&self, iter: I)
156 | |     -> <<I::Item as Collectable<Vec<TypeA>>>::Collected as Mapper<(Resp, )>>::Res
157 | |         where I: Iterator,
158 | |               I::Item: Collectable<Vec<TypeA>>,
...   |
161 | |         I::Item::collect(iter).and_then(|_items| (Resp,))
162 | |     }
    | |_____^ the trait `Collectable<std::vec::Vec<TypeA>>` is not implemented for `<I as std::iter::Iterator>::Item`
    |
    = help: consider adding a `where <I as std::iter::Iterator>::Item: Collectable<std::vec::Vec<TypeA>>` bound

error[E0276]: impl has stricter requirements than trait
   --> src/main.rs:155:5
    |
143 | /     fn make_from_iter<I>(&self, iter: I)
144 | |     -> <<I::Item as Collectable<Self::Collection>>::Collected as Mapper<(Resp, )>>::Res
145 | |         where I: Iterator,
146 | |               I::Item: Collectable<Self::Collection>,
147 | |               <I::Item as Collectable<Self::Collection>>::Collected: Mapper<(Resp,)>;
    | |_____________________________________________________________________________________- definition of `make_from_iter` from trait
...
155 | /     fn make_from_iter<I>(&self, iter: I)
156 | |     -> <<I::Item as Collectable<Vec<TypeA>>>::Collected as Mapper<(Resp, )>>::Res
157 | |         where I: Iterator,
158 | |               I::Item: Collectable<Vec<TypeA>>,
...   |
161 | |         I::Item::collect(iter).and_then(|_items| (Resp,))
162 | |     }
    | |_____^ impl has extra requirement `<I as std::iter::Iterator>::Item: Collectable<std::vec::Vec<TypeA>>`
@bkchr

This comment has been minimized.

Copy link
Contributor

@bkchr bkchr commented Oct 8, 2019

@estebank is that the output of chalk?

@estebank

This comment has been minimized.

Copy link
Contributor

@estebank estebank commented Oct 8, 2019

That's the current rustc output, I don't think it is using chalk.

@bkchr

This comment has been minimized.

Copy link
Contributor

@bkchr bkchr commented Oct 9, 2019

Ahh yeah, I thought you maybe tried @tmandry comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.