Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pointer] Fix Ptr[Inner] variance #2351

Merged
merged 1 commit into from
Feb 18, 2025

Conversation

joshlf
Copy link
Member

@joshlf joshlf commented Feb 18, 2025

Previously, Ptr<'a, T> and PtrInner<'a, T> documented themselves to
be covariant in both 'a and T. This was true for PtrInner, but not
for Ptr, which used GATs, which are invariant. This is also not the
desired variance: for Exclusive aliasing, the desired variance matches
that of &mut references - namely, covariant in 'a but invariant in
T.

This commit fixes this by making Ptr<'a, T> and PtrInner<'a, T>
unconditionally covariant in 'a and invariant in T.


This PR is on branch transmute-from.

@joshlf joshlf mentioned this pull request Feb 18, 2025
@joshlf joshlf requested a review from jswrenn February 18, 2025 00:29
@codecov-commenter
Copy link

codecov-commenter commented Feb 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.32%. Comparing base (9322a2c) to head (2a1dd8b).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2351   +/-   ##
=======================================
  Coverage   89.32%   89.32%           
=======================================
  Files          16       16           
  Lines        6025     6025           
=======================================
  Hits         5382     5382           
  Misses        643      643           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Previously, `Ptr<'a, T>` and `PtrInner<'a, T>` documented themselves to
be covariant in both `'a` and `T`. This was true for `PtrInner`, but not
for `Ptr`, which used GATs, which are invariant. This is also not the
desired variance: for `Exclusive` aliasing, the desired variance matches
that of `&mut` references - namely, covariant in `'a` but invariant in
`T`.

This commit fixes this by making `Ptr<'a, T>` and `PtrInner<'a, T>`
unconditionally covariant in `'a` and invariant in `T`.

gherrit-pr-id: I29f8429d9d7b14026313f030f8dc1e895a98ad56
@jswrenn jswrenn force-pushed the I29f8429d9d7b14026313f030f8dc1e895a98ad56 branch from 674e2af to 2a1dd8b Compare February 18, 2025 16:37
Copy link
Member Author

@joshlf joshlf left a comment

Choose a reason for hiding this comment

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

Tests look good, thanks for adding!

@joshlf joshlf enabled auto-merge February 18, 2025 16:44
@joshlf joshlf added this pull request to the merge queue Feb 18, 2025
Merged via the queue into main with commit 79ec7c4 Feb 18, 2025
69 checks passed
@joshlf joshlf deleted the I29f8429d9d7b14026313f030f8dc1e895a98ad56 branch February 18, 2025 17:15
joshlf added a commit that referenced this pull request Feb 25, 2025
Previously, `Ptr<'a, T>` and `PtrInner<'a, T>` documented themselves to
be covariant in both `'a` and `T`. This was true for `PtrInner`, but not
for `Ptr`, which used GATs, which are invariant. This is also not the
desired variance: for `Exclusive` aliasing, the desired variance matches
that of `&mut` references - namely, covariant in `'a` but invariant in
`T`.

This commit fixes this by making `Ptr<'a, T>` and `PtrInner<'a, T>`
unconditionally covariant in `'a` and invariant in `T`.

gherrit-pr-id: I29f8429d9d7b14026313f030f8dc1e895a98ad56
@joshlf
Copy link
Member Author

joshlf commented Feb 25, 2025

Backporting in #2393

joshlf added a commit that referenced this pull request Feb 25, 2025
Previously, `Ptr<'a, T>` and `PtrInner<'a, T>` documented themselves to
be covariant in both `'a` and `T`. This was true for `PtrInner`, but not
for `Ptr`, which used GATs, which are invariant. This is also not the
desired variance: for `Exclusive` aliasing, the desired variance matches
that of `&mut` references - namely, covariant in `'a` but invariant in
`T`.

This commit fixes this by making `Ptr<'a, T>` and `PtrInner<'a, T>`
unconditionally covariant in `'a` and invariant in `T`.

gherrit-pr-id: I29f8429d9d7b14026313f030f8dc1e895a98ad56
github-merge-queue bot pushed a commit that referenced this pull request Feb 25, 2025
Previously, `Ptr<'a, T>` and `PtrInner<'a, T>` documented themselves to
be covariant in both `'a` and `T`. This was true for `PtrInner`, but not
for `Ptr`, which used GATs, which are invariant. This is also not the
desired variance: for `Exclusive` aliasing, the desired variance matches
that of `&mut` references - namely, covariant in `'a` but invariant in
`T`.

This commit fixes this by making `Ptr<'a, T>` and `PtrInner<'a, T>`
unconditionally covariant in `'a` and invariant in `T`.

gherrit-pr-id: I29f8429d9d7b14026313f030f8dc1e895a98ad56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants