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/
602 | impl<T: PolynomialCoefficient> PolynomialDivSupported for T
    |                                ^^^^^^^^^^^^^^^^^^^^^^

The relevant code:

impl<T: PolynomialCoefficient> PolynomialDivSupported for T
    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:

pub trait AlwaysExactDivAssign<Rhs = Self>:
    + 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.