Dedup elaborated predicates with const generic parameter in AutoTrait#108397
Closed
megakorre wants to merge 1 commit intorust-lang:masterfrom
Closed
Dedup elaborated predicates with const generic parameter in AutoTrait#108397megakorre wants to merge 1 commit intorust-lang:masterfrom
megakorre wants to merge 1 commit intorust-lang:masterfrom
Conversation
Collaborator
|
r? @nagisa (rustbot has picked a reviewer for you, use r? to override) |
4510389 to
ee75156
Compare
Collaborator
|
☔ The latest upstream changes (presumably #108250) made this pull request unmergeable. Please resolve the merge conflicts. |
e24273d to
108cad1
Compare
Member
|
r? @lcnr |
Contributor
|
r? @BoxyUwU |
Contributor
|
I'll play with the ball, too r? compiler |
Contributor
Member
|
@megakorre Could you update the snippet issue: #107715 in the PR description to Fixes #107715 so GitHub can prominently link to this PR from the issue (I almost missed that there is a fix) and autoclose it when this PR gets merged? That would be great, thanks! |
Member
|
Closing this as the issue this is referencing is already closed/fixed. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #107715
Explanation
The
param_envpassed in toevaluate_predicatesin the added test case has the constantNsubstituted for the value of the referencing constant1. But the call toelaborate_predicatesproduces non normalized obligations (without the constant being substituted).This means we will call
SelectionContext.selectwith aparam_envwith multiple Predicates that willrelateand cause a ambiguity. And eventually run in to a panic!.Other normalization workarounds already happens in the
AutoTraitFinderin the
add_user_predmethod to work around lifetime differences.But that method is called before
elaborate_predicateswhich is what ends up adding the non normalized predicate.This PR adds extra de-duplication with normalization that ends up removing the redundant predicate that causes the error here.
The first place I tried to put this de-duplication was in the Elaborator (this).
But the normalize utility I'm calling is not available from
rustc_inferand the comments inAutoTraitFinderseems to suggest that the need to normalize the predicates like this is unique to it's use.Existing Regression
running
cargo-rustc-bisectfinds that the test example was working befored49e7e7(PR: #103279).The removal of the code here makes the test pass. Not because the predicates then gets normalized the same. The
param_envwill still have extra predicates in it. But without the extra eval in therelate_constscodeSelectionContext.selectwill only pick on off the 2 bounds and there will not be a ambiguity.Making sure there are not multiple duplicates in the
param_envseems more in line with the rest ofAutoTraitFinder.generic_const_exprs
With
generic_const_exprsturned on the example works before and after this PR. The predicates get normalized to leaving the const un-evaluated in all cases.So I left a comment that this de-duping can probably be removed when that feature is stable. this code has a similar comment.
Questions:
generic_const_exprsenabled. That functionality was not broken before this so maybe its not needed? 🤷🏻 But the functionality of this is different in that case