-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Remap impl-trait lifetimes on HIR instead of AST lowering #129383
Conversation
8127ba2
to
d334955
Compare
This comment has been minimized.
This comment has been minimized.
d334955
to
1729436
Compare
This comment was marked as resolved.
This comment was marked as resolved.
1729436
to
92cd183
Compare
This comment was marked as resolved.
This comment was marked as resolved.
c2ad831
to
12b94cd
Compare
HIR ty lowering was modified cc @fmease Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
This comment was marked as resolved.
This comment was marked as resolved.
7a0204e
to
44ced4f
Compare
☔ The latest upstream changes (presumably #131724) made this pull request unmergeable. Please resolve the merge conflicts. |
Reviewed. |
44ced4f
to
e9c3954
Compare
@compiler-errors do you mind taking a look? I'm not sure I correctly implemented the logic around |
Sure. If I don't look at this in a day or two, please ping me again. Do you have any specific concerns, like any code that you are suspicious that may act differently than before or needs some input, or do you just want a general review? |
This comment has been minimized.
This comment has been minimized.
//~^ ERROR ['_: o] | ||
//~| ERROR ['_: o] | ||
//~| ERROR `impl Trait` captures lifetime parameter | ||
//~^ ERROR [] |
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.
Ah, this doesn't seem right. Or at least, it changes the semantics of what we mean by "capture all in-scope parameters" for nested opaques.
Without having yet looked at the code, I assume what's happening here is that the nested opaque doesn't see any nested lifetimes because of the use<>
from the outer opaque, which shadows the lifetimes that the inner opaque considers to be in-scope. Is that right?
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.
I'm not actually certain if https://rust-lang.github.io/rfcs/3617-precise-capturing.html#summary prescribes what should happen here 🤔 -- it doesn't seem to do so, after having done a brief scan.
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.
I changed the code to recurse and capture all in-scope lifetimes when we have nested opaques.
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.
@compiler-errors I have re-implemented the resolution to walk the scopes and not stop at the closest opaque. Is this closer to what you had in mind?
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.
Yeah, I believe so. If in the future we want opaque type captures to stop at the closest opaque, we can do so; that actually seems like the right behavior, but this should mean there are no observable changes.
This comment has been minimized.
This comment has been minimized.
b196430
to
ad543e4
Compare
This comment has been minimized.
This comment has been minimized.
ad543e4
to
f7beaab
Compare
r=me,petrochenkov after rebase |
f7beaab
to
2d74d8f
Compare
@bors r=compiler-errors,petrochenkov rollup=iffy |
…kingjubilee Rollup of 5 pull requests Successful merges: - rust-lang#129383 (Remap impl-trait lifetimes on HIR instead of AST lowering) - rust-lang#132210 (rustdoc: make doctest span tweak a 2024 edition change) - rust-lang#132246 (Rename `rustc_abi::Abi` to `BackendRepr`) - rust-lang#132267 (force-recompile library changes on download-rustc="if-unchanged") - rust-lang#132344 (Merge `HostPolarity` and `BoundConstness`) Failed merges: - rust-lang#132347 (Remove `ValueAnalysis` and `ValueAnalysisWrapper`.) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#129383 - cjgillot:opaque-noremap, r=compiler-errors,petrochenkov Remap impl-trait lifetimes on HIR instead of AST lowering Current AST->HIR lowering goes out of its way to remap lifetimes for opaque types. This is complicated and leaks into upstream and downstream code. This PR stops trying to be clever during lowering, and prefers to do this remapping during the HIR->ty lowering. The remapping computation easily fits into the bound var resolution code. Its result can be used in by `generics_of` and `hir_ty_lowering::new_opaque` to add the proper parameters and arguments. See an example on the doc for query `opaque_captured_lifetimes`. Based on rust-lang#129244 Fixes rust-lang#125249 Fixes rust-lang#126850 cc `@compiler-errors` `@spastorino` r? `@petrochenkov`
Current AST->HIR lowering goes out of its way to remap lifetimes for opaque types. This is complicated and leaks into upstream and downstream code.
This PR stops trying to be clever during lowering, and prefers to do this remapping during the HIR->ty lowering. The remapping computation easily fits into the bound var resolution code. Its result can be used in by
generics_of
andhir_ty_lowering::new_opaque
to add the proper parameters and arguments.See an example on the doc for query
opaque_captured_lifetimes
.Based on #129244
Fixes #125249
Fixes #126850
cc @compiler-errors @spastorino
r? @petrochenkov