Open zesterer opened 2 years ago
Setting the recursion limit to be very small (like #![recursion_limit = "15"]
) makes this complete within a reasonable time frame. This can also be kinda replicated without GATs like so:
trait Bar<'a> {
type Ctx;
fn run(
&mut self,
ctx: &Self::Ctx,
);
}
struct Foo<F>(F);
impl<'a, F> Bar<'a> for Foo<F>
where F: FnMut(&<Self as Bar<'_>>::Ctx)
{
type Ctx = ();
fn run(
&mut self,
ctx: &Self::Ctx,
) {
(self.0)(ctx)
}
}
(The code isn't exactly the same -- but that's another way of getting it to hang in the same way)
Yes, this is not a GATs bug, but more of an associated types bug. There are some related issues (that I don't have links to right now). IIRC, the problem stems from using the associated type in the impl where clauses - we try to normalize that and get in a loop.
I'd like to give a more descriptive name to this issue, but unfortunately I don't know enough about the internals of rustc to be more useful. To my uneducated eye, it seems like the Rust is choking on the obligation produced by the
where
bound on theBar
implementation.I can't fully confirm that this is caused by GATs, but removing the generic lifetime on
Bar::Ctx
results in the compiler generating the more reasonableoverflow evaluating the requirement
error.I tried this code:
I expected to see this happen: The compiler to not freeze
Instead, this happened: The compiler froze
Meta
rustc --version --verbose
: