fix: defer const normalize in coherence mode#158205
Conversation
|
changes to the core type system cc @lcnr |
|
Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @petrochenkov (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
Why was this reviewer chosen?The reviewer was selected based on:
|
|
r? lcnr |
This comment has been minimized.
This comment has been minimized.
2054520 to
134d2ce
Compare
This comment has been minimized.
This comment has been minimized.
|
@rustbot review |
| // ripped out soon so this shouldn't matter soon. | ||
| StructurallyRelateAliases::No if !tcx.features().generic_const_exprs() => { | ||
| StructurallyRelateAliases::No | ||
| if !tcx.features().generic_const_exprs() || defer_in_coherence => |
There was a problem hiding this comment.
hmm, can you change this to instead be self.infcx.next_trait_solver() || !tcx.features().generic_const_exprs()
We don't support gce with the new solver but currently have the new solver in coherence if gce is enabled, so this should have the same results as your PR while being easier (for me) to reason about
There was a problem hiding this comment.
I see, and thank you for reviewing!
I'm running tests and will push a revised version!
There was a problem hiding this comment.
Wait, the ui test failed if I replaced my change with self.infcx.next_trait_solver() || !tcx.features().generic_const_exprs().
The case is tests/ui/const-generics/issues/issue-89304.rs that uses anon const kind like:
impl<const T: usize> From<GenericStruct<T>> for GenericStruct<{T + 1}> { ... }
impl<const T: usize> From<GenericStruct<{T + 1}>> for GenericStruct<T> { ... }There was a problem hiding this comment.
that test should fail 🤣
From<W<A>> for W<{ expr involving A }> and From<W<{ expr involving A }>> for W<A> may overlap unless we do reasoning about the generic expression.
The compiler currently does not reason about the fact that T + 1 is larger than T, so that (T, T + 1) and (U + 1, U) can never be equal.
There was a problem hiding this comment.
As in, while this example could be accepted in theory, the reason we do so right now is due to a bug and not because we correctly reason about generic expressions
There was a problem hiding this comment.
Okay, so... //@ check-pass at line 1 on tests/ui/const-generics/issues/issue-89304.rs is actually caused by a bug and currently the compiler does not check this overlap accurately, right?
How should we handle the case like this? I don't know the process to decide these regressions in the Rust dev.
Should this be discussed in some other place? I've joined rust-lang Zulip.
There was a problem hiding this comment.
exactly
for GCE it'd be fine to just delete the test I think
more generally, often it's one or a combination of
- reopen the original issue linked from the test
- open a new issue if the failure of the test changed
- mark the test as
//@ known-bug - update the comment in the test file to the new (intended) behavior
- cry
generic_const_exprs will be replaced by generic_const_args soon. We'd otherwise update the comment and expected outcome of this test and keep it around, but I think here deleting is easier 🤷
There was a problem hiding this comment.
I see, so I will delete the test, commit it, and push it. Thanks for reviewing!
This comment has been minimized.
This comment has been minimized.
20b9a4e to
7e186a8
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@rustbot review I changed the code to resolve conflict. |
I'm not confident that this fix is the best and desired in the long term point of view, but I'm confident that this does not do anything unsound.
Fixes #157937, by deferring normalization of associated const, except for anon, in coherence mode.
This fix prevents reporting impls, including associated const, are not overlapping.