Chained associated type reported as ambiguous

Continuing the discussion from Implementing a "true" Functor in Rust:

Is this a compiler bug / issue?

pub trait NestedMonad<'a>
    Self: Monad<'a, Self::FmapInOut::FmapInOut>,
    Self: FunctorSelf<'a>,
    Self::FmapInOut: FunctorSelf<'a>,
    /* … */



   Compiling playground v0.0.1 (/playground)
error[E0223]: ambiguous associated type
  --> src/
65 |     Self: Monad<'a, Self::FmapInOut::FmapInOut>,
   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^
help: if there were a trait named `Example` with associated type `FmapInOut` implemented for `<Self as FunctorSelf<'a>>::FmapInOut`, you could use the fully-qualified path
65 |     Self: Monad<'a, <<Self as FunctorSelf<'a>>::FmapInOut as Example>::FmapInOut>,
   |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

For more information about this error, try `rustc --explain E0223`.
error: could not compile `playground` (bin "playground") due to previous error

I don't see how Self::FmapInOut::FmapInOut could be ambigious because Self::FmapInOut only implements one trait that provides the associated FmapInOut type.

It requires this to compile:

-    Self: Monad<'a, Self::FmapInOut::FmapInOut>,
+    Self: Monad<'a, <Self::FmapInOut as FunctorSelf<'a>>::FmapInOut>,

Maybe this issue is already known? Or am I missing an ambiguity?

I've run into this kind of compiler error uncountably many times, so I'd be highly surprised if this isn't well known.

1 Like

Okay, I see. So it happens in other scenarios too. Well, it's not a big problem anyway; just a bit of extra verbosity needed.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.