Skip to content

feat(Reborrow): Allow multiple lifetimes - #163284

Open
aapoalas wants to merge 5 commits into
rust-lang:mainfrom
aapoalas:reborrow/allow-multiple-lifetimes
Open

aapoalas wants to merge 5 commits into
rust-lang:mainfrom
aapoalas:reborrow/allow-multiple-lifetimes

Conversation

@aapoalas

Copy link
Copy Markdown
Contributor

The Reborrow/CoerceShared borrow checking code is now robust enough to properly handle multiple lifetimes, and for that we can allow multiple lifetimes in the traits. This requires making the CoerceShared derive macro produce multiple lifetimes and in particular produce 'a_ where 'a: 'a_` additions to the generics, and removing some now-unnecessary checks from the wf-checks.

The derive trait code is some of the uglies stuff I've ever written.

r? @oli-obk

@rustbot

rustbot commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

This PR changes a file inside tests/crashes. If a crash was fixed, please move into the corresponding ui subdir and add 'Fixes #' to the PR description to autoclose the issue upon merge.

@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. labels Sep 24, 2026
@rust-bors

This comment has been minimized.

Comment on lines 765 to 789
@@ -803,9 +778,12 @@ fn field_tys_satisfy_relation_after_normalization_and_resolution<'tcx>(
else {
return false;
};
if source_region != target_region {
return false;
}
infcx.sub_regions(
SubregionOrigin::RelateObjectBound(span),
target_region,
source_region,
ty::VisibleForLeakCheck::Yes,
);
if ocx.sup(&cause, param_env, target_referent_ty, source_referent_ty).is_err() {
return false;
}

@oli-obk oli-obk Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I couldn't find any in-tree docs about the lifetime handling. Should probably add some now that you aren't requiring equality anymore. I had to grab a variance table and poke at the code and tests here until I was sure it was all in the right direction 😆

View changes since the review

@aapoalas aapoalas Oct 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Where should they be located in? Just here in the code?

Comment on lines 242 to 245
if trait_impl_lifetime_params_count(tcx, impl_did) != 1 {
if trait_impl_lifetime_params_count(tcx, impl_did) == 0 {
return Err(tcx
.dcx()
.emit_err(diagnostics::CoerceSharedNotSingleLifetimeParam { span, trait_name }));

@oli-obk oli-obk Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

probably needs updating of the diagnostic (and at minimum of the diagnostic struct name)

View changes since the review


let Some(last) = path.segments.last_mut() else {
// FIXME(reborrow): we might want to support CoerceShared<Foo> for Bar at some point.
cx.dcx().emit_err(MalformedTarget { span: attr.span });

@oli-obk oli-obk Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

probably want to use more precise span for all the MalformedTarget errors, usually you have a specific item available which has its own span

View changes since the review

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 28, 2026
@rustbot

rustbot commented Sep 28, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

.filter_map(|param| match param.kind {
GenericParamKind::Lifetime => {
GenericArg::Lifetime(cx.lifetime(param.span(), param.ident))
if trait_name == sym::CoerceShared && !param.ident.as_str().ends_with("_") {

@dingxiangfei2009 dingxiangfei2009 Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What would happen if the lifetime generic already has a _ suffix?

View changes since the review

@aapoalas
aapoalas force-pushed the reborrow/allow-multiple-lifetimes branch from 00337c0 to fb3a7fd Compare October 3, 2026 10:49
@rustbot

rustbot commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler 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