Properly find owner of closure in THIR unsafeck by LeSeulArtichaut · Pull Request #87645 · rust-lang/rust (original) (raw)
No, that's not the problem. Let me illustrate with an example:
fn function() { let closure = || {}; }
We're trying to compute unsafeck for closure
, which should invoke unsafeck for the parent body function
. So def.did
is the DefId of the closure, and the HIR is constructed in such a way that the corresponding HirId has function
as its owner, so in the code owner
is the DefId of function
which id correct.
Enter consts:
fn function() -> [(); { || {}; 4 }] {}
Here, if I try the same "hack", i.e. get the HirId for the closure and take its owner, I get owner
to be the DefId of function
whereas I want the DefId of the anonymous constant { || {}; 4 }
.
To be fair I don't entirely understand which query invocations cycle and which don't when using ensure
, and I've also not dived into the internals of HIR to check that enclosing_body_owner
always does the right thing, but this PR doesn't cycle on the examples provided in #87414 and passed the rest of the test suite.