Filter PhantomData fields in CoerceShared borrowck field matching#156785
Open
ikow wants to merge 2 commits into
Open
Filter PhantomData fields in CoerceShared borrowck field matching#156785ikow wants to merge 2 commits into
ikow wants to merge 2 commits into
Conversation
The `add_generic_reborrow_constraint` function matches source and dest struct fields by name when establishing borrow constraints for CoerceShared. However, it uses `all_fields()` which includes PhantomData fields, while the coherence check (`coerce_shared_info`) filters them out via `collect_struct_data_fields`. This mismatch means PhantomData fields with different names between source and dest are silently skipped, potentially dropping lifetime constraints. Fix: filter out PhantomData fields before matching, consistent with the coherence check. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Collaborator
|
r? @JohnTitor rustbot has assigned @JohnTitor. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
The
add_generic_reborrow_constraintfunction incompiler/rustc_borrowck/src/type_check/mod.rsmatches source and dest struct fields by name when establishing borrow constraints forCoerceShared. However, it usesall_fields()which includesPhantomDatafields, while the coherence check (coerce_shared_info) filters them out viacollect_struct_data_fields.This mismatch means
PhantomDatafields with different names between source and dest structs are silently skipped viacontinue(line 2524), potentially dropping lifetime constraints that should be established.Fix
Filter out
PhantomDatafields before matching, consistent with the coherence check's use ofcollect_struct_data_fields.Test plan
tests/ui/reborrow/coerce_shared_phantom_field_names.rs— a run-pass test withCoerceSharedsource/dest structs that have differently-namedPhantomDatafields (_markervs_lifetime)Tracking issue: #145612 (reborrow feature)