-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Check that RPITs constrained by a recursive call in a closure are compatible #99079
Conversation
Ugh... so we end up with an RPIT's hidden type constrained within a closure and I didn't add appropriate checks against that. I used to have some logic to bubble all such hidden types out into the main function to solve this. Ideally we should probably unify RPIT and TAIT logic in type_of to allow closures and nested functions inside a function to register hidden types for all RPIT of that function. That's more of a lang change tho. We should outright forbid closures to bind the hidden types of RPIT imo. And then once that is landed we can ask the lang team about unifying the TAIT and RPIT defining scope logic |
@oli-obk: not sure how to do that... My understanding is that we would need to adjust the |
As in, no change in behaviour? I can imagine that, as we go back to the main function afterwards, and then suddenly it sees the old anchor again. I think we'll need to double check that an opaque type was in its defining scope at the end, when we collect it in borrowck. |
@rustbot author |
…r=oli-obk Do not allow typeck children items to constrain outer RPITs Fixes rust-lang#99073 in a simpler and more conservative way than rust-lang#99079. Simply raise a mismatched types error if we try to constrain an RPIT in an item that isn't the RPIT's parent. r? `@oli-obk`
☔ The latest upstream changes (presumably #99451) made this pull request unmergeable. Please resolve the merge conflicts. |
…r=oli-obk Do not allow typeck children items to constrain outer RPITs Fixes rust-lang#99073 in a simpler and more conservative way than rust-lang#99079. Simply raise a mismatched types error if we try to constrain an RPIT in an item that isn't the RPIT's parent. r? `@oli-obk`
Yes, this is the right step towards unifying RPIT and TAIT defining scopes. After this PR is merged, we should check if we can remove the call to
it is, I had this in an earlier version of the lazy TAIT PR. I removed it in favour of the current scheme, since the current scheme can be extended towards allowing nested things to be part of the defining scope. |
r=me after a rebase |
45330bc
to
5e8f1e8
Compare
I reverted #99345 as well, since this PR allows strictly more programs to compile and without reverting that one I don't think we'd see any changes. |
Just double checking if that's ok ^ @oli-obk |
To be clear: this PR enables no new stable code to compile, right? |
@oli-obk, actually this does allow "new" stable code to compile. Well, not really new, but code that used to compile before #99345. For example: use std::fmt::Display;
fn foo<T: Display + Copy>(t: T, recurse: bool) -> impl Display {
if recurse {
(|| {
let t: T = foo(t, false);
println!("{t}");
})();
}
t
}
fn main() {
foo(1i32, true);
} I don't think there's any value in landing this PR without reverting #99345, since we'll error out during borrowck when a closure has a defining usage of an RPIT due to that PR, so this new code path won't ever get touched. |
@bors r+ |
Rollup of 5 pull requests Successful merges: - rust-lang#99079 (Check that RPITs constrained by a recursive call in a closure are compatible) - rust-lang#99704 (Add `Self: ~const Trait` to traits with `#[const_trait]`) - rust-lang#99769 (Sync rustc_codegen_cranelift) - rust-lang#99783 (rustdoc: remove Clean trait impls for more items) - rust-lang#99789 (Refactor: use `pluralize!`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Fixes #99073
Adapts a similar visitor pattern to
find_opaque_ty_constraints
(that we use to check TAITs), but with some changes:0. Only walk the "OnlyBody" children, instead of all items in the RPIT's defining scope
r? @oli-obk -- you know all this impl-trait stuff best... is this the right approach? I can explain the underlying issue better if you'd like, in case that might reveal a better solution. Not sure if it's possible to gather up the closure's defining usages of the RPIT while borrowck'ing the outer function, that might be a better place to put this check...