Repository navigation
Tracking Issue for Reborrow trait lang experiment #145612
Description
This is a tracking issue for the lang experiment into a Reborrow trait and its dual CoerceShared trait.
The feature gate for the issue is #![feature(reborrow)].
For more information, see rust-lang/goals#399.
About tracking issues
Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Discussion comments will get marked as off-topic or deleted.
Repeated discussions on the tracking issue may lead to the tracking issue getting locked.
Steps
- Land a feature gate, and possibly an empty trait.
- Land an empty Reborrow trait.
- Land an empty CoerceShared trait.
- Land a test battery for basic Reborrow trait usage.
- Land a test battery for basic CoerceShared trait usage
- Land a test battery for complex Reborrow trait usage.
- Land a test battery for complex CoerceShared trait usage.
- Implement the Reborrow trait internals (probably a rustc builtin macro)
- Implement the CoerceShared trait internals (ditto)
- Start the RFC process based on the learnings
Unresolved Questions
The implementation of the Reborrow trait is likely something like this:
struct Example<'a, 'b> {
a: A<'a>,
b: B<'b>
}
fn reborrow(e: Example) {
let Example { a, b } = e;
reborrow(Example { a, b });
}This allows the compiler to see the individual field usages and, eventually, enables the correct lifetimes to be "used as exclusive". But the question is; where does this bottom out? Is any field that implements Reborrow (but not Copy, if Reborrow is blanket-implemented for Copy types) a point where the recursion into structs stops? That stops composing of reborrowable types to a depth of 2. Is a PhantomReborrowable<'a> marker type needed? If so, then what is the variance of the lifetime there?
Implementation history
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsExploration
Activity
joshtriplett commentedon Aug 20, 2025
👍 for a lang experiment here.
tmandry commentedon Aug 21, 2025
I'm happy to champion this.
Rollup merge of rust-lang#145726 - aapoalas:reborrow-lang-experiment,…
Rollup merge of rust-lang#145726 - aapoalas:reborrow-lang-experiment,…
28 remaining items
tvsfx commentedon Jul 8, 2026
Is supporting
Reborrow/CoerceSharedfor method receivers without UFCS just a matter of doing the implementation work? I was just playing with the implementation on current nightly and noticed that I need UFCS to make code like this work:But I cannot find any mention of this not working.
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=a573cbc6ecc099044f89f98b0b958f0f
aapoalas commentedon Jul 8, 2026
We haven't really gotten around to looking at this side of the equation yet - so far the compiler only inserts Reborrow/CoerceShared at assignment locations, but the method call location is not one. This ties in with #44874 and might (or probably will) affect the method resolution algorithm, which is a bit of a ... complication. As such, unfortunately for now this is unsupported.
If you're interested in looking into this, I'd be happy to help (with what meager knowledge I have)!
fix: UserRef soundness
Rollup merge of rust-lang#156338 - P8L1:derive-reborrow-coerce-shared…
Unrolled build for #156338
Rollup merge of #151753 - aapoalas:aapoalas/reborrow-and-coerce-share…
Jules-Bertholet commentedon Sep 29, 2026
#145612 (comment)
My PR #163494 partially fixes this—it ensures that a method call on a
Reborrowtype performs a reborrow.Rollup merge of rust-lang#163519 - Jules-Bertholet:no-reborrow-destru…
Rollup merge of rust-lang#163519 - Jules-Bertholet:no-reborrow-destru…
Rollup merge of rust-lang#163519 - Jules-Bertholet:no-reborrow-destru…
Rollup merge of rust-lang#163519 - Jules-Bertholet:no-reborrow-destru…
Rollup merge of rust-lang#151753 - aapoalas:aapoalas/reborrow-and-coe…
Rollup merge of rust-lang#163519 - Jules-Bertholet:no-reborrow-destru…
Rollup merge of #151753 - aapoalas:aapoalas/reborrow-and-coerce-share…
Unrolled build for #163519 in rollup 163583