Skip to content

Conversation

aapoalas
Copy link
Contributor

@aapoalas aapoalas commented Aug 30, 2025

Part of #145612: This introduces the CoerceShared trait which is the Reborrow equivalent of a &mut T -> &T coercion. The trait has a Target GAT which makes this (currently) unique in the core/src/marker.rs; I'm not sure if this can be considered problematic. Maybe this is not the way such things should be done at the marker trait level? Or maybe it is fine.

Improtantly, this PR introduces a battery of basic Reborrow and CoerceShared tests. These test the very basics of the feature; custom marker types intended to have exclusive semantics (Custom<'a>(PhantomData<&'a mut ()>)), custom exclusive reference wrappers, and standard library exclusive reference wrappers (Pin<&mut T> and Option<&mut T>). None of these of course work since the implementation for Reborrow and CoerceShared is entirely missing, but this is the first step towards making these work.

Future PRs will introduce more tests, such as "recursive" reborrowing (ie. reborrowing structs that contain multiple reborrowable fields) and checks around the lifetime semantics of reborrowing ie. that a reborrow produces a new type with the same lifetime as the original.

@rustbot
Copy link
Collaborator

rustbot commented Aug 30, 2025

r? @nnethercote

rustbot has assigned @nnethercote.
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

@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. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 30, 2025
@tmandry
Copy link
Member

tmandry commented Aug 31, 2025

The definition I use of a marker trait is a trait with no items, so this would not be a marker trait. (This concept comes up in regards to coherence; it is sound to allow overlapping impls of marker traits, because they don't have items whose definitions can conflict.)

@aapoalas
Copy link
Contributor Author

The definition I use of a marker trait is a trait with no items, so this would not be a marker trait. (This concept comes up in regards to coherence; it is sound to allow overlapping impls of marker traits, because they don't have items whose definitions can conflict.)

Alright; I was kind of just following CoercePointee since the names are similar :D Would this be more appropriate in ops perhaps? Or somewhere else entirely?

@nnethercote
Copy link
Contributor

This looks fine to me from the compiler side, where very little code is added. Any controversial bits seems to be libs/lang related, where I don't have much insight.

I will forward this review on to Tyler who knows more about it. I'm not sure if a library reviewer should also be involved.

r? @tmandry

@rustbot rustbot assigned tmandry and unassigned nnethercote Sep 1, 2025
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. T-libs Relevant to the library 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