-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Properly find owner of closure in THIR unsafeck #87645
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Regression test for #87414. | ||
|
||
// check-pass | ||
// compile-flags: -Zthir-unsafeck | ||
|
||
fn bad<T>() -> Box<dyn Iterator<Item = [(); { |x: u32| { x }; 4 }]>> { todo!() } | ||
|
||
fn foo() -> [(); { |x: u32| { x }; 4 }] { todo!() } | ||
fn bar() { let _: [(); { |x: u32| { x }; 4 }]; } | ||
|
||
// This one should not cause any errors either: | ||
unsafe fn unsf() {} | ||
fn bad2<T>() -> Box<dyn Iterator<Item = [(); { unsafe { || { unsf() } }; 4 }]>> { todo!() } | ||
|
||
fn main() {} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just to be clear I understand, because I understood something different from your text.
owner
here is== def.did
, and thus invokingthir_check_unsafety
on that will obviously cycle?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that's not the problem. Let me illustrate with an example:
We're trying to compute unsafeck for
closure
, which should invoke unsafeck for the parent bodyfunction
. Sodef.did
is the DefId of the closure, and the HIR is constructed in such a way that the corresponding HirId hasfunction
as its owner, so in the codeowner
is the DefId offunction
which id correct.Enter consts:
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 offunction
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 thatenclosing_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.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your explanation makes sense, thanks! I do think we should get a more solid strategy around all this, but I think it kind of overlaps with various other things like generics in anonymous constants. So let's merge this PR now