Filter PhantomData fields in CoerceShared borrowck field matching#156785
Filter PhantomData fields in CoerceShared borrowck field matching#156785ikow 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>
|
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>
|
@ikow Hello! Could you cite the actual code pattern in Rust source that should or should not compile but (on the current It is not actually clear to me what your regression test is actually testing, because it is a run-pass test but the code also compiles and passes using a nightly compiler. I did not build main's b954122 to verify since nightly's e50aa6f worked. There is no regression that this test can prevent because a run-pass test first has to be something that doesn't compile on some previous Rust version. |
|
@rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
|
Please do not send us PRs that were generated that. We're a community, not just a code repository. We want contributors who want to meaningfully contribute, not just bugs that are fixed (which in your case the generated tests and code don't do). Feel free to reach out on Zulip to ask for how to best contribute and do read the rustc-dev-guide and our contribution guidelines. This is a moderation warning. If you want to discuss your warning, reach out to moderation via email or on Zulip. |
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)