Skip to content

Allow field(0) projection as a no-op when target value is a PtrLocal#871

Merged
jberthold merged 3 commits intomasterfrom
transparent-struct-access-hack
Dec 1, 2025
Merged

Allow field(0) projection as a no-op when target value is a PtrLocal#871
jberthold merged 3 commits intomasterfrom
transparent-struct-access-hack

Conversation

@jberthold
Copy link
Member

The change in #811 allows pointer casts between pointers to data and pointers to "transparent wrapper structs" containing one field with the same data. While the code tries to insert field(0, _) projections when casting, this remediation falls short when the cast pointer is of a second degree, i.e., a pointer to a pointer.
An example of this can be observed in Iterator<_>::next, where a pointer **T is cast to a pointer *NonNull<T>, NonNull being one of these "transparent wrapper structs".

The proposed code change allows for a field(0, _) projection to be treated as a No-Op when applied to a non-aggregate (nor union), specifically a PtrLocal for the case of next().

This fixes iter.next() for cases where Some(element) is returned. The case where it returns None is a separate issue tested but not fixed here.

@jberthold jberthold marked this pull request as ready for review December 1, 2025 03:31
Copy link
Contributor

@Stevengre Stevengre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@jberthold jberthold merged commit a9876cb into master Dec 1, 2025
7 checks passed
@jberthold jberthold deleted the transparent-struct-access-hack branch December 1, 2025 06:42
Stevengre added a commit that referenced this pull request Dec 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants