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

Cannot unify associated type bounds across traits #69640

Closed
Pratyush opened this issue Mar 2, 2020 · 1 comment
Closed

Cannot unify associated type bounds across traits #69640

Pratyush opened this issue Mar 2, 2020 · 1 comment
Labels
C-bug Category: This is a bug.

Comments

@Pratyush
Copy link
Contributor

Pratyush commented Mar 2, 2020

Hi!

I tried this code:

trait Engine {
    type G: Curve<F = Self::F>;
    type F;
}

trait Curve: core::ops::MulAssign<<Self as Curve>::F> {
    type F;
}

fn should_work<E: Engine>(mut p: E::G, f: E::F) {
    p *= f
}

fn main() {
    println!("Hello, world!");
}

I expected this to compile, because I clearly specify that G::F = Self::F, but it seems that this unification doesn't occur, resulting in the following compiler error:

Compiling playground v0.0.1 (/playground)
error[E0277]: cannot multiply-assign `<E as Engine>::F` to `<E as Engine>::G`
  --> src/main.rs:11:7
   |
6  | trait Curve: core::ops::MulAssign<<Self as Curve>::F> {
   | ----------------------------------------------------- required by `Curve`
...
10 | fn test<E: Engine>(mut p: E::G, f: E::F) {
   |                                         - help: consider further restricting the associated type: `where <E as Engine>::G: std::ops::MulAssign<<E as Engine>::F>`
11 |     p *= f
   |       ^^ no implementation for `<E as Engine>::G *= <E as Engine>::F`
   |
   = help: the trait `std::ops::MulAssign<<E as Engine>::F>` is not implemented for `<E as Engine>::G`

error[E0308]: mismatched types
  --> src/main.rs:11:10
   |
11 |     p *= f
   |          ^ expected Curve::F, found Engine::F
   |
   = note: expected associated type `<<E as Engine>::G as Curve>::F`
              found associated type `<E as Engine>::F`

Here's a playground link: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=c008af6306a36b074e3704fe6b474c84

Meta

This reproduces on the latest stable, beta, and nightly.

This might be related to #20775 and #48822, but not sure.

@jonas-schievink
Copy link
Contributor

It works with an additional E::G: Curve<F = E::F> bound on test. Therefore, closing as a duplicate of #20671.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants