From 824f07f92b0e2aeedf69d99d3c7cd1039e0456a1 Mon Sep 17 00:00:00 2001 From: Adwin White Date: Sat, 29 Aug 2026 15:03:20 +0800 Subject: [PATCH] treat identity region constraint as true --- .../rustc_type_ir/src/region_constraint.rs | 4 +++ .../identity_region_outlives.rs | 29 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 tests/ui/assumptions_on_binders/identity_region_outlives.rs diff --git a/compiler/rustc_type_ir/src/region_constraint.rs b/compiler/rustc_type_ir/src/region_constraint.rs index 2923709432ee5..1e4e7572c8551 100644 --- a/compiler/rustc_type_ir/src/region_constraint.rs +++ b/compiler/rustc_type_ir/src/region_constraint.rs @@ -681,6 +681,10 @@ fn pull_region_outlives_constraints_out_of_universe< constraint } RegionOutlives(region_1, region_2, ()) => { + if region_1 == region_2 { + return RegionConstraint::new_true(); + } + let region_1_u = max_universe(infcx, region_1); let region_2_u = max_universe(infcx, region_2); diff --git a/tests/ui/assumptions_on_binders/identity_region_outlives.rs b/tests/ui/assumptions_on_binders/identity_region_outlives.rs new file mode 100644 index 0000000000000..b12c7d4909945 --- /dev/null +++ b/tests/ui/assumptions_on_binders/identity_region_outlives.rs @@ -0,0 +1,29 @@ +//@ compile-flags: -Zassumptions-on-binders +//@ check-pass + +// Regression test for #161733. +// Previously we didn't properly handle identity region outlives +// and it was mistakenly considered as false region constraint. +// The closure is needed to register the type outlives obligation +// in borrowck. + +#![feature(test_binder_constraints)] + +fn foo() +where + for<'a> &'a T: 'a, +{ + || {}; +} + +core::test_binder_constraints! { + impl { + forall<'a> where T: 'a { + 'a: 'a, + T: 'a, + } expect { + } + } +} + +fn main() {}