-
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
Fall back to bidirectional normalizes-to if no subst-relate candidate in alias-relate goal #112076
Conversation
Some changes occurred to the core trait solver cc @rust-lang/initiative-trait-system-refactor |
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.
please also add TAIT eq TAIT tests
and projection eq projection, would assume that these are also possible
after that r=me (though I would wait for the first commit to land separately?)
91ce800
to
36b5f01
Compare
Cannot for the life of me construct an example that involves projections only. I think this is a consequence of us still doing eager norm during HIR typeck in some places, and also a consequence of us not using the RHS of a projection predicate during candidate assembly. |
Nevermind, here's a projection-relate-projection test that has to do with regions: rust-lang/trait-system-refactor-initiative#25 (comment) Perhaps harder to construct an example that involves infer vars, but I've kinda given up on that :s |
r=me after rebase |
36b5f01
to
3ea7c51
Compare
@bors r=lcnr |
Rollup of 6 pull requests Successful merges: - rust-lang#112076 (Fall back to bidirectional normalizes-to if no subst-relate candidate in alias-relate goal) - rust-lang#112122 (Add `-Ztrait-solver=next-coherence`) - rust-lang#112251 (rustdoc: convert `if let Some()` that always matches to variable) - rust-lang#112345 (fix(expand): prevent infinity loop in macro containing only "///") - rust-lang#112359 (Respect `RUST_BACKTRACE` for delayed bugs) - rust-lang#112382 (download-rustc: Fix `x test core` on MacOS) r? `@ghost` `@rustbot` modify labels: rollup
Sometimes we get into the case where the choice of normalizes-to branch in alias-relate are both valid, but we cannot make a choice of which one to take because they are different -- either returning equivalent but permuted region constraints, or equivalent opaque type definitions but differing modulo normalization.
In this case, we can make progress by considering a fourth candidate where we compute both normalizes-to branches together and canonicalize that as a response. This is essentially the AND intersection of both normalizes-to branches. In an ideal world, we'd be returning something more like the OR intersection of both branches, but we have no way of representing that either for regions (maybe eventually) or opaques (don't see that happening ever).
This is incomplete, so like the subst-relate fallback it's only considered outside of coherence. But it doesn't seem like a dramatic strengthening of inference or anything, and is useful for helping opaque type inference succeed when the hidden type is a projection.
Example
Consider the goal -
AliasRelate(Tait, <[i32; 32] as IntoIterator>::IntoIter)
.We have three ways of currently solving this goal:
Tait normalizes-to <[i32; 32] as IntoIterator>::IntoIter
Tait := <[i32; 32] as IntoIterator>::IntoIter
<[i32; 32] as IntoIterator>::IntoIter normalizes-to Tait
std::array::IntoIter<i32, 32>
std::array::IntoIter<i32, 32>
andTait
Tait := std::array::IntoIter<i32, 32>
The problem here is that 2 and 3 are essentially both valid, since we have aliases that normalize on both sides, but due to lazy norm, they end up inferring different opaque type definitions that are only equal after normalizing them further.
r? @lcnr