Rustc can't resolve type equality when given in where clause

I'm writing an algebraic numbers library, and I've run into a bug where rustc gives only one error:

error[E0284]: type annotations required: cannot resolve `for<'a> <T as std::ops::Div<&'a T>>::Output == T`
   --> src/polynomial.rs:602:32
    |
602 | impl<T: PolynomialCoefficient> PolynomialDivSupported for T
    |                                ^^^^^^^^^^^^^^^^^^^^^^

The relevant code:
polynomial.rs:602-610

impl<T: PolynomialCoefficient> PolynomialDivSupported for T
where
    T: for<'a> ExactDiv<&'a T, Output = T>
        + for<'a> Div<&'a T, Output = T>
        + AlwaysExactDivAssign
        + for<'a> AlwaysExactDivAssign<&'a T>,
    for<'b> T::Element: ExactDivAssign<&'b T::Element> + One + ExactDivAssign,
{
}

I'm pretty sure I missing trait bounds somewhere and/or there's a rustc bug. Any suggestions?

This Output throws it off

pub trait AlwaysExactDiv<Rhs = Self>:
    ExactDiv<Rhs> + Div<Rhs/*, Output = <Self as ExactDiv<Rhs>>::Output*/>
1 Like

I would have expected rustc to be able to resolve that since AlwaysExactDivAssign requires Output = Self:
traits.rs:580-587

pub trait AlwaysExactDivAssign<Rhs = Self>:
    AlwaysExactDiv<Rhs>
    + ExactDivAssign<Rhs>
    + DivAssign<Rhs>
    + ExactDiv<Rhs, Output = Self>
    + Div<Rhs, Output = Self>
{
}

I'll try removing the bound in AlwaysExactDiv and get back to you.

your solution does work, thanks!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.