From e2a14c98f422b11aec091438339176ba3e6ef27d Mon Sep 17 00:00:00 2001 From: human9000 Date: Mon, 1 Jun 2026 11:26:59 +0500 Subject: [PATCH] Avoid regions vars in const args lowering --- .../rustc_hir_analysis/src/hir_ty_lowering/mod.rs | 2 +- tests/ui/const-generics/mgca/region_vars_hashed.rs | 13 +++++++++++++ .../const-generics/mgca/region_vars_hashed.stderr | 8 ++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tests/ui/const-generics/mgca/region_vars_hashed.rs create mode 100644 tests/ui/const-generics/mgca/region_vars_hashed.stderr diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs index bc3e526a362a8..6edba72877ea8 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -2307,7 +2307,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { // up as a region variable in mir borrowck. It would also be somewhat concerning if // hir typeck was using equality but mir borrowck wound up using subtyping as that could // result in a non-infer in hir typeck but a region variable in borrowck. - if tcx.features().generic_const_parameter_types() + if (tcx.features().generic_const_parameter_types() || tcx.features().min_generic_const_args()) && (ty.has_free_regions() || ty.has_erased_regions()) { let e = self.dcx().span_err( diff --git a/tests/ui/const-generics/mgca/region_vars_hashed.rs b/tests/ui/const-generics/mgca/region_vars_hashed.rs new file mode 100644 index 0000000000000..46b9fb1ed2005 --- /dev/null +++ b/tests/ui/const-generics/mgca/region_vars_hashed.rs @@ -0,0 +1,13 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/157147. +//! +//! It used to ICE when trying to process region vars in const arguments, +//! Since it tries to hash intentionally un-hashable `ReVar` inference var. + +//@ compile-flags: --crate-type=lib +//@ incremental +#![feature(min_generic_const_args)] + +fn foo() { + foo::<{ Some::<&u8> { 0: const { &0_u8 } } }>() + //~^ ERROR: anonymous constants with lifetimes in their type are not yet supported +} diff --git a/tests/ui/const-generics/mgca/region_vars_hashed.stderr b/tests/ui/const-generics/mgca/region_vars_hashed.stderr new file mode 100644 index 0000000000000..e3bd5e3c839ea --- /dev/null +++ b/tests/ui/const-generics/mgca/region_vars_hashed.stderr @@ -0,0 +1,8 @@ +error: anonymous constants with lifetimes in their type are not yet supported + --> $DIR/region_vars_hashed.rs:11:30 + | +LL | foo::<{ Some::<&u8> { 0: const { &0_u8 } } }>() + | ^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error +