rustdoc: fix auto trait synthesis ICE with higher-ranked GAT bounds - #160734
Open
souvik1997 wants to merge 1 commit into
Open
rustdoc: fix auto trait synthesis ICE with higher-ranked GAT bounds#160734souvik1997 wants to merge 1 commit into
souvik1997 wants to merge 1 commit into
Conversation
`AutoTraitFinder::add_user_clause` deduplicates discovered clauses that
differ only in their regions, keeping the stricter (higher-ranked) one,
because a `ParamEnv` containing both confuses `SelectionContext`: both
candidates apply, selection reports ambiguity, and the sanity check in
`find_auto_trait_generics` turns that into an ICE ("Unable to fulfill
trait ...: [Ambiguity]").
The dedup only compared regions appearing as direct generic arguments of
the trait ref (`T: Trait<'a>` vs. `for<'b> T: Trait<'b>`). With generic
associated types the differing region can instead sit inside a type
argument: `for<'w> <A as Alloc>::Wired<'w>: Send` and
`<A as Alloc>::Wired<'static>: Send` have unequal self types, so the
dedup bailed out, both clauses landed in the `ParamEnv`, and the final
fulfillment check panicked.
Compare the argument lists with all regions erased instead, and, when
they are equal modulo regions, walk the regions of both argument lists
in lockstep so the existing preference rules also apply to regions
nested inside type arguments.
Fixes rust-lang#144918
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Collaborator
|
Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @JohnTitor (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:
|
Collaborator
|
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.
rustdoc's auto trait impl synthesis deduplicates discovered clauses that differ only in their regions (
AutoTraitFinder::add_user_clause), keeping the stricter (higher-ranked) one, because aParamEnvcontaining both confusesSelectionContext: both candidates apply, selection reports ambiguity, and the sanity check infind_auto_trait_genericsturns that into an ICE:The dedup only compared regions appearing as direct generic arguments of the trait ref (
T: Trait<'a>vs.for<'b> T: Trait<'b>). With generic associated types the differing region can instead sit inside a type argument:for<'w> <A as Alloc>::Wired<'w>: Sendand<A as Alloc>::Wired<'static>: Sendhave unequal self types, so the dedup bailed out ("we can't compare lifetimes if the types are different"), both clauses landed in theParamEnv, and the final fulfillment check panicked.This PR compares the argument lists with all regions erased instead, and, when they are equal modulo regions, walks the regions of both argument lists in lockstep so the existing preference rules (keep the higher-ranked bound, drop region variables) also apply to regions nested inside type arguments.
Minimal reproduction (ICEs on stable and nightly before this change):
Synthesizing
Custody<A>: Senddiscoversfor<'w> A::Wired<'w>: Send(fromSlot's manual impl) andA::Wired<'static>: Send(from the second field); with this change the latter is subsumed by the former and the synthesized impl is rendered with the higher-ranked bound.Fixes #144918.
#149019 rewrites the synthesis on the next solver and would also fix this; this PR is a targeted fix for the current implementation in the meantime.
The related #110741 hits the same panic through an ambiguous projection clause (
FnOnce::Output), whichadd_user_clausedoes not deduplicate at all; that flavor is not addressed here.