← Back to Pull requests

feat(Reborrow): Allow multiple lifetimes #163284

Merged
aapoalas merged 49 files (597 lines) on Nov 07, 2026 06:12 UTC
View on GitHub
aapoalas aapoalas commented on Sep 24, 2026 19:28 UTC
Author

<!-- homu-ignore:start -->
View all comments
<!-- homu-ignore:end -->

<!-- homu-ignore:start -->
<!--
Please read our [LLM policy] before opening a PR,
If you used an LLM to generate any part of this PR, including the PR description, please disclose that according to our [guidelines][disclosure guidelines].
LLM contributions are not banned, but are held to a higher standard of review and correctness.

[LLM policy]: https://forge.rust-lang.org/policies/llm-usage.html
[disclosure guidelines]: https://rustc-dev-guide.rust-lang.org/llm-guidance/writing.html#disclosure-guidelines

If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.

This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using

r? <reviewer name>

When merged, your PR's description becomes part of the commit message of a merge commit.
If you do not want certain parts of it (such as your LLM disclosure) to show up in the permanent git history,
surround them with a pair of HTML comments containing homu-ignore:start and homu-ignore:end.
-->
<!-- homu-ignore:end -->

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

Diff: 597 lines (+332 / -265) across 49 files Reviewer: oli-obk Review duration: 62563m
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.75) × (1 − Review Confidence (0.76)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.75 · 597 lines diff across 49 files
0.75
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.52 · 5 substantive comment(s)
0.52
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
75%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.383
Mass File Touch mass_file_touch
0.080
Ai Authored ai_authored
0.050
Real PR Conversation Timeline
29 items
rustbot rustbot commented on Sep 24, 2026 19:28 UTC
Contributor

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

rust-bors[bot] rust-bors[bot] commented on Sep 28, 2026 07:17 UTC
Bot

:umbrella: The latest upstream changes (presumably #163419) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.

oli-obk oli-obk commented on code on Sep 28, 2026 10:25 UTC
Code Review
compiler/rustc_hir_analysis/src/coherence/builtin/coerce_shared.rs:1
@@ -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;
             }

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

oli-obk oli-obk commented on code on Sep 28, 2026 10:27 UTC
Code Review
compiler/rustc_hir_analysis/src/coherence/builtin/coerce_shared.rs:1
@@ -239,7 +239,7 @@ pub(super) fn coerce_shared_info<'tcx>(
     let source = tcx.type_of(impl_did).instantiate_identity().skip_norm_wip();
     let trait_ref = tcx.impl_trait_ref(impl_did).instantiate_identity().skip_norm_wip();
 
-    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 }));

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

View changes since the review

oli-obk oli-obk commented on code on Sep 28, 2026 10:29 UTC
Code Review
compiler/rustc_builtin_macros/src/deriving/reborrow.rs:1
@@ -105,7 +114,79 @@ fn coerce_shared_target(cx: &ExtCtxt<'_>, span: Span, item: &ast::Item) -> Optio
         return None;
     }
 
-    Some(target)
+    let rustc_ast::TyKind::Path(_, path) = &mut target.kind else {
+        cx.dcx().emit_err(MalformedTarget { span: attr.span });
+        return None;
+    };
+
+    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 });

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

oli-obk oli-obk requested changes on Sep 28, 2026 10:29 UTC
Changes Requested Reviewer

Requested changes.

rustbot rustbot commented on Sep 28, 2026 10:30 UTC
Contributor

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

dingxiangfei2009 dingxiangfei2009 commented on code on Oct 01, 2026 16:19 UTC
Code Review
compiler/rustc_builtin_macros/src/deriving/reborrow.rs:1
@@ -125,15 +206,19 @@ fn push_marker_impl(
     let self_params: Vec<_> = generics
         .params
         .iter()
-        .map(|param| match param.kind {
+        .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("_") {

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

View changes since the review

rustbot rustbot commented on Oct 03, 2026 10:49 UTC
Contributor

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 on code on Oct 03, 2026 10:50 UTC
Code Review
compiler/rustc_hir_analysis/src/coherence/builtin/coerce_shared.rs:1
@@ -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;
             }

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

aapoalas aapoalas commented on code on Oct 03, 2026 11:47 UTC
Code Review
compiler/rustc_builtin_macros/src/deriving/reborrow.rs:1
@@ -125,15 +206,19 @@ fn push_marker_impl(
     let self_params: Vec<_> = generics
         .params
         .iter()
-        .map(|param| match param.kind {
+        .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("_") {

Added a names_set to ensure no conflicts happen

aapoalas aapoalas commented on code on Oct 03, 2026 11:47 UTC
Code Review
compiler/rustc_builtin_macros/src/deriving/reborrow.rs:1
@@ -105,7 +114,79 @@ fn coerce_shared_target(cx: &ExtCtxt<'_>, span: Span, item: &ast::Item) -> Optio
         return None;
     }
 
-    Some(target)
+    let rustc_ast::TyKind::Path(_, path) = &mut target.kind else {
+        cx.dcx().emit_err(MalformedTarget { span: attr.span });
+        return None;
+    };
+
+    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 });

Added more specific errors.

aapoalas aapoalas commented on code on Oct 03, 2026 11:47 UTC
Code Review
compiler/rustc_hir_analysis/src/coherence/builtin/coerce_shared.rs:1
@@ -239,7 +239,7 @@ pub(super) fn coerce_shared_info<'tcx>(
     let source = tcx.type_of(impl_did).instantiate_identity().skip_norm_wip();
     let trait_ref = tcx.impl_trait_ref(impl_did).instantiate_identity().skip_norm_wip();
 
-    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 }));

Updated diagnostics name and message

cyrgani cyrgani commented on code on Oct 03, 2026 12:38 UTC
Code Review
compiler/rustc_builtin_macros/src/deriving/reborrow.rs:1
@@ -96,7 +112,104 @@ fn coerce_shared_target(cx: &ExtCtxt<'_>, span: Span, item: &ast::Item) -> Optio
         return None;
     }
 
-    Some(target)
+    let rustc_ast::TyKind::Path(_, path) = &mut target.kind else {
+        cx.dcx().emit_err(MalformedTargetType { span: target.span });
+        return None;
+    };
+
+    let Some(last) = path.segments.last_mut() else {
+        // It shouldn't be possible for segments to be empty.
+        cx.dcx().emit_err(MalformedTargetType { span: path.span });
+        return None;
+    };
+
+    let Some(rustc_ast::GenericArgs::AngleBracketed(target_args)) = last.args.as_deref_mut() else {
+        // FIXME(reborrow): same as above.
+        cx.dcx().emit_err(NoGenericsOnTargetType { span: last.span() });
+        return None;
+    };
+
+    // Map to check generated lifetime arg names against.
+    let mut lt_names: FxHashSet<Symbol> = target_args
+        .args
+        .iter()
+        .filter_map(|arg| {
+            if let AngleBracketedArg::Arg(GenericArg::Lifetime(arg)) = arg {
+                Some(arg.ident.name)
+            } else {
+                None
+            }
+        })
+        .collect();
+
+    // struct Source<'a, 'b, T, const U> {} + coerce_shared(Target<'a>) =>
+    // impl<'a, 'a_, T, const U> CoerceShared<Target<'a_>> for Source<'a, T, const U>
+    //   where 'a: 'a_ {}
+    let coerce_shared_trait_param_count = source_generics.params.len() + lt_names.len();
+    let mut trait_params = ThinVec::with_capacity(coerce_shared_trait_param_count);
+    let mut trait_where_clause = source_generics.where_clause.clone();
+
+    // First add in the existing lifetimes.
+    trait_params.extend(
+        source_generics
+            .params
+            .iter()
+            .take_while(|p| matches!(p.kind, rustc_ast::GenericParamKind::Lifetime))
+            .cloned(),
+    );
+
+    // Remember how many lifetime parameters there were.
+    let source_generics_lt_count = trait_params.len();
+
+    // Replace all lifetime parameters 'a with a new 'a_ where 'a: 'a_ in the Target definition, and
+    // push the new lifetimes into trait params.
+    for arg in target_args.args.iter_mut() {
+        let AngleBracketedArg::Arg(GenericArg::Lifetime(arg)) = arg else {
+            continue;
+        };
+
+        // Eagerly intern the generated lifetime name - it is unlikely we have a naming conflict.
+        let mut name_string = format!("{}_", arg.ident.as_str());
+        let mut name = Symbol::intern(&name_string);
+        while lt_names.contains(&name) {
+            // Just keep piling on the underscores.
+            name_string.push('_');
+            name = Symbol::intern(&name_string);
+        }
+        // Now that we generated a unique lifetime name, add it into the set.
+        lt_names.insert(name);
+
+        // Create our lifetime, add it into the trait parameters and create a where-clause predicate
+        // for it.
+        let lt = rustc_ast::Lifetime { id: DUMMY_NODE_ID, ident: Ident::with_dummy_span(name) };
+        trait_params.push(GenericParam {
+            id: DUMMY_NODE_ID,
+            ident: lt.ident,
+            attrs: Default::default(),
+            bounds: Default::default(),
+            is_placeholder: false,
+            kind: GenericParamKind::Lifetime,
+            colon_span: None,
+        });

        trait_params.push(cx.lifetime_param(lt.ident, Default::default()));

View changes since the review

aapoalas aapoalas commented on code on Oct 08, 2026 18:35 UTC
Code Review
compiler/rustc_builtin_macros/src/deriving/reborrow.rs:1
@@ -96,7 +112,104 @@ fn coerce_shared_target(cx: &ExtCtxt<'_>, span: Span, item: &ast::Item) -> Optio
         return None;
     }
 
-    Some(target)
+    let rustc_ast::TyKind::Path(_, path) = &mut target.kind else {
+        cx.dcx().emit_err(MalformedTargetType { span: target.span });
+        return None;
+    };
+
+    let Some(last) = path.segments.last_mut() else {
+        // It shouldn't be possible for segments to be empty.
+        cx.dcx().emit_err(MalformedTargetType { span: path.span });
+        return None;
+    };
+
+    let Some(rustc_ast::GenericArgs::AngleBracketed(target_args)) = last.args.as_deref_mut() else {
+        // FIXME(reborrow): same as above.
+        cx.dcx().emit_err(NoGenericsOnTargetType { span: last.span() });
+        return None;
+    };
+
+    // Map to check generated lifetime arg names against.
+    let mut lt_names: FxHashSet<Symbol> = target_args
+        .args
+        .iter()
+        .filter_map(|arg| {
+            if let AngleBracketedArg::Arg(GenericArg::Lifetime(arg)) = arg {
+                Some(arg.ident.name)
+            } else {
+                None
+            }
+        })
+        .collect();
+
+    // struct Source<'a, 'b, T, const U> {} + coerce_shared(Target<'a>) =>
+    // impl<'a, 'a_, T, const U> CoerceShared<Target<'a_>> for Source<'a, T, const U>
+    //   where 'a: 'a_ {}
+    let coerce_shared_trait_param_count = source_generics.params.len() + lt_names.len();
+    let mut trait_params = ThinVec::with_capacity(coerce_shared_trait_param_count);
+    let mut trait_where_clause = source_generics.where_clause.clone();
+
+    // First add in the existing lifetimes.
+    trait_params.extend(
+        source_generics
+            .params
+            .iter()
+            .take_while(|p| matches!(p.kind, rustc_ast::GenericParamKind::Lifetime))
+            .cloned(),
+    );
+
+    // Remember how many lifetime parameters there were.
+    let source_generics_lt_count = trait_params.len();
+
+    // Replace all lifetime parameters 'a with a new 'a_ where 'a: 'a_ in the Target definition, and
+    // push the new lifetimes into trait params.
+    for arg in target_args.args.iter_mut() {
+        let AngleBracketedArg::Arg(GenericArg::Lifetime(arg)) = arg else {
+            continue;
+        };
+
+        // Eagerly intern the generated lifetime name - it is unlikely we have a naming conflict.
+        let mut name_string = format!("{}_", arg.ident.as_str());
+        let mut name = Symbol::intern(&name_string);
+        while lt_names.contains(&name) {
+            // Just keep piling on the underscores.
+            name_string.push('_');
+            name = Symbol::intern(&name_string);
+        }
+        // Now that we generated a unique lifetime name, add it into the set.
+        lt_names.insert(name);
+
+        // Create our lifetime, add it into the trait parameters and create a where-clause predicate
+        // for it.
+        let lt = rustc_ast::Lifetime { id: DUMMY_NODE_ID, ident: Ident::with_dummy_span(name) };
+        trait_params.push(GenericParam {
+            id: DUMMY_NODE_ID,
+            ident: lt.ident,
+            attrs: Default::default(),
+            bounds: Default::default(),
+            is_placeholder: false,
+            kind: GenericParamKind::Lifetime,
+            colon_span: None,
+        });

Fixed and also added a helper function for the WherePredicate creation.

aapoalas aapoalas commented on Oct 08, 2026 18:35 UTC
Author

@rustbot ready

rust-log-analyzer rust-log-analyzer commented on Oct 08, 2026 18:41 UTC
Contributor

The job test-x86_64-gnu-miri failed! Check out the build log: (web) (plain enhanced) (plain)

<details><summary><i>Click to see the possible cause of the failure (guessed by this bot)</i></summary>

[RUSTC-TIMING] rustc_metadata test:false 17.248
   Compiling rustc_codegen_ssa v0.0.0 (/checkout/compiler/rustc_codegen_ssa)
[RUSTC-TIMING] rustc_borrowck test:false 79.030
   Compiling rustc_resolve v0.0.0 (/checkout/compiler/rustc_resolve)
warning: unused imports: `GenericBound`, `GenericParamKind`, `GenericParam`, `WherePredicateKind`, `WherePredicate`, and `WhereRegionPredicate`
 --> compiler/rustc_builtin_macros/src/deriving/reborrow.rs:2:74
  |
2 |     self as ast, AngleBracketedArg, AttrArgs, DUMMY_NODE_ID, GenericArg, GenericBound,
  |                                                                          ^^^^^^^^^^^^
3 |     GenericParam, GenericParamKind, Generics, ItemKind, WherePredicate, WherePredicateKind,
  |     ^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^                      ^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^^
4 |     WhereRegionPredicate, token,
  |     ^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` (part of `#[warn(unused)]`) on by default

warning: unused import: `DUMMY_SP`
  --> compiler/rustc_builtin_macros/src/deriving/reborrow.rs:10:18
   |
10 | use rustc_span::{DUMMY_SP, Ident, Span, Symbol, sym};
   |                  ^^^^^^^^

warning: unused import: `thin_vec`
  --> compiler/rustc_builtin_macros/src/deriving/reborrow.rs:11:25
   |

</details>

oli-obk oli-obk commented on code on Oct 09, 2026 10:45 UTC
Code Review
compiler/rustc_hir_analysis/src/coherence/builtin/coerce_shared.rs:1
@@ -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;
             }

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

aapoalas aapoalas commented on code on Oct 09, 2026 20:02 UTC
Code Review
compiler/rustc_hir_analysis/src/coherence/builtin/coerce_shared.rs:1
@@ -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;
             }

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

rustbot rustbot commented on Oct 17, 2026 20:26 UTC
Contributor

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.

rustbot rustbot commented on Oct 17, 2026 20:28 UTC
Contributor

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.

rust-bors[bot] rust-bors[bot] commented on Oct 21, 2026 19:47 UTC
Bot

:umbrella: The latest upstream changes (presumably #164699) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.

oli-obk oli-obk approved these changes on Oct 23, 2026 16:13 UTC
Approved Reviewer

r=me with rebase and squashing

View changes since this review

rustbot rustbot commented on Nov 01, 2026 17:45 UTC
Contributor

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 on Nov 01, 2026 17:49 UTC
Author

@rustbot ready

rust-log-analyzer rust-log-analyzer commented on Nov 01, 2026 18:27 UTC
Contributor

The job test-x86_64-gnu-gcc failed! Check out the build log: (web) (plain enhanced) (plain)

<details><summary><i>Click to see the possible cause of the failure (guessed by this bot)</i></summary>

-   --> $DIR/coerce-shared-marker-no-target-lifetime.rs:13:10
+ error: implementing `CoerceShared` requires source and target structs to use the same field style
+   --> $DIR/coerce-shared-marker-no-target-lifetime.rs:13:1
3    |
4 LL | impl<'a> CoerceShared<CustomMarkerRef> for CustomMarker<'a> {}
-    |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6 
7 error: aborting due to 1 previous error
8 
---
To only update this specific test, also pass `--test-args reborrow/coerce-shared-marker-no-target-lifetime.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/reborrow/coerce-shared-marker-no-target-lifetime.rs" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "-Zcodegen-backend=gcc" "--target=x86_64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/reborrow/coerce-shared-marker-no-target-lifetime" "-Znext-solver=coherence" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--edition=2024"
stdout: none
--- stderr -------------------------------
error: implementing `CoerceShared` requires source and target structs to use the same field style
##[error]  --> /checkout/tests/ui/reborrow/coerce-shared-marker-no-target-lifetime.rs:13:1
   |
LL | impl<'a> CoerceShared<CustomMarkerRef> for CustomMarker<'a> {}
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error
------------------------------------------

---
-   --> $DIR/invalid-coerce-shared-static-mut-field.rs:20:5
+ error: implementing `CoerceShared` currently requires source and target to have at most one non-ZST reborrow data field
+   --> $DIR/invalid-coerce-shared-static-mut-field.rs:24:1
3    |
- LL |     a: &'static mut u8,
-    |     ------------------ source field `a` has type `&'static mut u8`
- ...
- LL |     a: &'a u8,
-    |     ^^^^^^^^^ target field `a` has type `&'a u8`
- ...
10 LL | impl<'a> CoerceShared<ReorderRef<'a>> for ReorderMut<'a> {}
-    | ----------------------------------------------------------- required by this `CoerceShared` implementation
+    | ^^^^^^^^^^^^^^^^^^^^^^--------------^^^^^^--------------^^^
+    | |                     |                   |
+    | |                     |                   source type has 2 non-ZST reborrow data fields
+    | |                     target type has 2 non-ZST reborrow data fields
---
To only update this specific test, also pass `--test-args reborrow/invalid-coerce-shared-static-mut-field.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/reborrow/invalid-coerce-shared-static-mut-field.rs" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "-Zcodegen-backend=gcc" "--target=x86_64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/reborrow/invalid-coerce-shared-static-mut-field" "-Znext-solver=coherence" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--edition=2015"
stdout: none
--- stderr -------------------------------
error: implementing `CoerceShared` currently requires source and target to have at most one non-ZST reborrow data field
##[error]  --> /checkout/tests/ui/reborrow/invalid-coerce-shared-static-mut-field.rs:24:1
   |
LL | impl<'a> CoerceShared<ReorderRef<'a>> for ReorderMut<'a> {}
   | ^^^^^^^^^^^^^^^^^^^^^^--------------^^^^^^--------------^^^
   | |                     |                   |
   | |                     |                   source type has 2 non-ZST reborrow data fields
   | |                     target type has 2 non-ZST reborrow data fields
   | in this `CoerceShared` implementation
---
To only update this specific test, also pass `--test-args reborrow/invalid-reborrow-derive-const-param.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/reborrow/invalid-reborrow-derive-const-param.rs" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "-Zcodegen-backend=gcc" "--target=x86_64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/reborrow/invalid-reborrow-derive-const-param" "-Znext-solver=coherence" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--edition=2015"
stdout: none
--- stderr -------------------------------
error: implementing `Reborrow` requires that at least one lifetime parameter
##[error]  --> /checkout/tests/ui/reborrow/invalid-reborrow-derive-const-param.rs:11:10
   |
---
---- [ui] tests/ui/reborrow/invalid-reborrow-impl-no-lifetime.rs stdout ----

error: Error: expected failure status (Some(1)) but received status Some(101).
status: exit status: 101
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/reborrow/invalid-reborrow-impl-no-lifetime.rs" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "-Zcodegen-backend=gcc" "--target=x86_64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/reborrow/invalid-reborrow-impl-no-lifetime" "-Znext-solver=coherence" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--edition=2015"
stdout: none
--- stderr -------------------------------
##[error]error: internal compiler error: compiler/rustc_borrowck/src/borrow_set.rs:403:17: ADT containing no '&mut T' or 'T: Reborrow' fields must only have one lifetime to implement Reborrow


thread 'rustc' (139118) panicked at compiler/rustc_borrowck/src/borrow_set.rs:403:17:
Box<dyn Any>
stack backtrace:
   0: std::panicking::begin_panic::<rustc_span::macros::ExplicitBug>
   1: rustc_span::macros::bug_impl
   2: <rustc_borrowck::borrow_set::GatherBorrows>::gather_reborrows
   3: <rustc_borrowck::borrow_set::GatherBorrows as rustc_middle::mir::visit::Visitor>::visit_assign
   4: <rustc_borrowck::borrow_set::BorrowSet>::build
   5: rustc_borrowck::borrowck_collect_region_constraints
   6: <rustc_borrowck::root_cx::BorrowCheckRootCtxt>::do_mir_borrowck
   7: rustc_borrowck::mir_borrowck
      [... omitted 1 frame ...]
   8: <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface::passes::run_required_analyses::{closure#2}::{closure#0}>::{closure#0}
   9: rustc_data_structures::sync::parallel::par_for_each_in::<rustc_span::def_id::LocalDefId, [rustc_span::def_id::LocalDefId], <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners<rustc_interface::passes::run_required_analyses::{closure#2}::{closure#0}>::{closure#0}>
  10: <rustc_session::session::Session>::time::<(), rustc_interface::passes::run_required_analyses::{closure#2}>
  11: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  12: <std::thread::local::LocalKey<core::cell::Cell<*const ()>>>::with::<rustc_middle::ty::context::tls::enter_context<<rustc_middle::ty::context::GlobalCtxt>::enter<rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::compiler_entrypoint::{closure#0}::{closure#1}>::{closure#2}, core::option::Option<rustc_interface::queries::Linker>>::{closure#1}, core::option::Option<rustc_interface::queries::Linker>>::{closure#0}, core::option::Option<rustc_interface::queries::Linker>>
  13: <rustc_middle::ty::context::TyCtxt>::create_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::compiler_entrypoint::{closure#0}::{closure#1}>::{closure#2}>
  14: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::compiler_entrypoint::{closure#0}::{closure#1}>
  15: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::compiler_entrypoint::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}::{closure#0}, ()>
  16: rustc_span::create_session_globals_then::<(), rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::compiler_entrypoint::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}::{closure#0}>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: please make sure that you have updated to the latest nightly

note: rustc 1.101.0-nightly (c1168185a 2026-11-01) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z simulate-remapped-rust-src-base=/rustc/FAKE_PREFIX -Z translate-remapped-path-to-local-path=no -Z ignore-directory-in-diagnostics-source-blocks=/cargo -Z ignore-directory-in-diagnostics-source-blocks=/checkout/vendor -Z codegen-backend=gcc -C codegen-units=1 -Z ui-testing -Z deduplicate-diagnostics=no -Z write-long-types-to-disk=no -C strip=debuginfo -C prefer-dynamic -Z next-solver=coherence -C rpath -C debuginfo=0

query stack during panic:
#0 [mir_borrowck] borrow-checking `main`
#1 [analysis] running analysis passes on crate `invalid_reborrow_impl_no_lifetime`
end of query stack
error: aborting due to 1 previous error
------------------------------------------

---
To only update this specific test, also pass `--test-args reborrow/invalid-reborrow-impl-phantom-data-wrong-generics.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/reborrow/invalid-reborrow-impl-phantom-data-wrong-generics.rs" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "-Zcodegen-backend=gcc" "--target=x86_64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/reborrow/invalid-reborrow-impl-phantom-data-wrong-generics" "-Znext-solver=coherence" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--edition=2015"
stdout: none
--- stderr -------------------------------
error[E0107]: struct takes 0 lifetime arguments but 1 lifetime argument was supplied
##[error]  --> /checkout/tests/ui/reborrow/invalid-reborrow-impl-phantom-data-wrong-generics.rs:9:23
   |

</details>

[!IMPORTANT]

For more information how to resolve CI failures of this job, visit this link.

oli-obk oli-obk commented on Nov 06, 2026 09:11 UTC
Contributor

@bors r+ rollup

rust-bors[bot] rust-bors[bot] commented on Nov 06, 2026 09:11 UTC
Bot

:pushpin: Commit 500e0c68d175573b0bf1ec878d595f99d3853e95 has been approved by oli-obk

It is now in the queue for this repository.

Reviewers
Assignees
aapoalas aapoalas
Labels
risk: low confidence: 75.6% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 74.8% (HIGH) · Higher = larger blast radius
74.8%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 75.6% · Lower = rushed or shallow review
75.6%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 18.2% · Safe to merge
18.2%
Repository