Encode synthetic by-move coroutine body with a different DefPathData
by compiler-errors · Pull Request #139153 · rust-lang/rust (original) (raw)
See the included test. In the first revision rpass1, we have an async closure {closure#0}
which has a coroutine as a child {closure#0}::{closure#0}
. We synthesize a by-move coroutine body, which is {closure#0}::{closure#1}
which depends on the mir_built query, which depends on the typeck query.
In the second revision rpass2, we've replaced the coroutine-closure by a closure with two children closure. Notably, the def path of the second child closure is the same as the synthetic def id from the last revision: {closure#0}::{closure#1}
. When type-checking this closure, we end up trying to compute its def_span, which tries to fetch it from the incremental cache; this will try to force the dependencies from the last run, which ends up forcing the mir_built query, which ends up forcing the typeck query, which ends up with a query cycle.
The problem here is that we really should never have used the same DefPathData
for the synthetic by-move coroutine body, since it's not a closure. Changing the DefPathData
will mean that we can see that the def ids are distinct, which means we won't try to look up the closure's def span from the incremental cache, which will properly skip replaying the node's dependencies and avoid a query cycle.
Fixes #139142