Skip to content

feat(Reborrow): Allow multiple lifetimes - #163284

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
aapoalas:reborrow/allow-multiple-lifetimes
Nov 7, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
aapoalas:reborrow/allow-multiple-lifetimes

Conversation

@aapoalas

@aapoalas aapoalas commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

View all comments

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?

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.

yea, there are existing docs in the code, but they don't mention lifetimes yet at all beyond the trivial usage

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.

Added inline comments to this. You might want to also read https://hackmd.io/xl3EvNkZSHqqNi_K2XwdRg regarding this - if we do go back to an associated type on CoerceShared (which I think we should - otherwise we cannot represent &mut T and &T using Reborrow and CoerceShared alone) then the lifetime stuff here will revert to an invariant again :D


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

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.

Added more specific errors.

@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.

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

This comment has been minimized.

@aapoalas

aapoalas commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

@rustbot ready

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

This comment has been minimized.

@aapoalas
aapoalas force-pushed the reborrow/allow-multiple-lifetimes branch from 45b49ff to 467dff7 Compare October 17, 2026 20:26
@rustbot

This comment has been minimized.

@aapoalas
aapoalas force-pushed the reborrow/allow-multiple-lifetimes branch from 467dff7 to c39f3f2 Compare October 17, 2026 20:28
@rustbot

This comment has been minimized.

@rust-bors

This comment has been minimized.

@oli-obk oli-obk left a comment •

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.

r=me with rebase and squashing

View changes since this review

@oli-obk oli-obk 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 Oct 23, 2026
@aapoalas
aapoalas force-pushed the reborrow/allow-multiple-lifetimes branch from c39f3f2 to 08a244e Compare November 1, 2026 17:45
@rustbot

rustbot commented Nov 1, 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.

@aapoalas

aapoalas commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

@rustbot ready

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

This comment has been minimized.

@aapoalas
aapoalas force-pushed the reborrow/allow-multiple-lifetimes branch from 08a244e to 500e0c6 Compare November 1, 2026 20:14
@oli-obk

oli-obk commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

@bors r+ rollup

@rust-bors

rust-bors Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 500e0c6 has been approved by oli-obk

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 6, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 6, 2026
…ifetimes, r=oli-obk

feat(Reborrow): Allow multiple lifetimes

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
rust-bors Bot pushed a commit that referenced this pull request Nov 6, 2026
…uwer

Rollup of 19 pull requests

Successful merges:

 - #164784 (Introduce OptimizationObjective and fix the entry shim's size attributes)
 - #165037 (Drop array elements in order after a partial move)
 - #165078 (Use the `2.38` binutils version in CI)
 - #159374 (Lower #[no_mangle] to #[symbol_name]/#[link_name])
 - #163284 (feat(Reborrow): Allow multiple lifetimes)
 - #164775 (Tweak output on misused `const` parameter to provide more context and more accurate suggestion)
 - #165194 (name elided lifetimes in `use<...>` suggestion when `impl Trait` params are present)
 - #165222 (Anonymize inner binders when checking refining)
 - #165335 (Fallible type ops)
 - #165388 (Accept variadic SysV64, Win64, and Aapcs FnAbis in rustc_public)
 - #165448 (Update `Vec::retain_unstable` docs to say that this method is generally faster than `Vec::retain_mut`)
 - #165494 (fix Miri ICE on exit with () return type)
 - #165503 (update Enzyme submodule)
 - #165505 (DFV: Reject `#[non_exhaustive]` on enum variants with default field values)
 - #165512 (Fix warnings for the L4Re targets)
 - #165514 (Remove unused `WhereEqPredicate` and `ScopeId` types)
 - #165518 (style-guide: Remove ABI explicitness prescription for extern items)
 - #165519 (Update books)
 - #165534 (rename MIR_borrow_checking timing scope to less confusing name)
rust-bors Bot pushed a commit that referenced this pull request Nov 7, 2026
Rollup of 15 pull requests

Successful merges:

 - #165037 (Drop array elements in order after a partial move)
 - #165550 (Make `Literal::cstr_value` return a `CString`)
 - #159374 (Lower #[no_mangle] to #[symbol_name]/#[link_name])
 - #163284 (feat(Reborrow): Allow multiple lifetimes)
 - #164775 (Tweak output on misused `const` parameter to provide more context and more accurate suggestion)
 - #165194 (name elided lifetimes in `use<...>` suggestion when `impl Trait` params are present)
 - #165222 (Anonymize inner binders when checking refining)
 - #165335 (Fallible type ops)
 - #165388 (Accept variadic SysV64, Win64, and Aapcs FnAbis in rustc_public)
 - #165448 (Update `Vec::retain_unstable` docs to say that this method is generally faster than `Vec::retain_mut`)
 - #165494 (fix Miri ICE on exit with () return type)
 - #165505 (DFV: Reject `#[non_exhaustive]` on enum variants with default field values)
 - #165512 (Fix warnings for the L4Re targets)
 - #165514 (Remove unused `WhereEqPredicate` and `ScopeId` types)
 - #165518 (style-guide: Remove ABI explicitness prescription for extern items)
@rust-bors
rust-bors Bot merged commit db327f9 into rust-lang:main Nov 7, 2026
14 checks passed
@rustbot rustbot added this to the 1.101.0 milestone Nov 7, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 7, 2026
Rollup merge of #163284 - aapoalas:reborrow/allow-multiple-lifetimes, r=oli-obk

feat(Reborrow): Allow multiple lifetimes

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

6 participants