Skip to content

Filter PhantomData fields in CoerceShared borrowck field matching#156785

Open
ikow wants to merge 2 commits into
rust-lang:mainfrom
ikow:fix/coerce-shared-field-matching
Open

Filter PhantomData fields in CoerceShared borrowck field matching#156785
ikow wants to merge 2 commits into
rust-lang:mainfrom
ikow:fix/coerce-shared-field-matching

Conversation

@ikow
Copy link
Copy Markdown

@ikow ikow commented May 20, 2026

Summary

The add_generic_reborrow_constraint function in compiler/rustc_borrowck/src/type_check/mod.rs 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 structs are silently skipped via continue (line 2524), potentially dropping lifetime constraints that should be established.

Fix

Filter out PhantomData fields before matching, consistent with the coherence check's use of collect_struct_data_fields.

Test plan

  • Added tests/ui/reborrow/coerce_shared_phantom_field_names.rs — a run-pass test with CoerceShared source/dest structs that have differently-named PhantomData fields (_marker vs _lifetime)
  • This test verifies the borrow constraints are correctly established even with mismatched PhantomData field names

Tracking issue: #145612 (reborrow feature)

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>
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 20, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 20, 2026

r? @JohnTitor

rustbot has assigned @JohnTitor.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 20 candidates

@rust-log-analyzer

This comment has been minimized.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants