From 2ae298711f92a79ea5bc59479846bfeea49481ef Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 9 Jan 2026 10:42:48 +1100 Subject: [PATCH] Replace two `BottomUpFolder`s with `fold_regions`. Because these folders only change regions. Note: `BottomUpFolder` folds all regions, while `fold_regions` skips some bound regions. But that's ok because these two folders only modify `ReVar`s. --- .../src/interpret/intrinsics.rs | 11 +++-------- compiler/rustc_hir_analysis/src/check/check.rs | 17 ++++++----------- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/compiler/rustc_const_eval/src/interpret/intrinsics.rs b/compiler/rustc_const_eval/src/interpret/intrinsics.rs index 94832c0c2577..fe1dd1b6eb35 100644 --- a/compiler/rustc_const_eval/src/interpret/intrinsics.rs +++ b/compiler/rustc_const_eval/src/interpret/intrinsics.rs @@ -13,7 +13,7 @@ use rustc_infer::infer::TyCtxtInferExt; use rustc_middle::mir::interpret::{CTFE_ALLOC_SALT, read_target_uint, write_target_uint}; use rustc_middle::mir::{self, BinOp, ConstValue, NonDivergingIntrinsic}; use rustc_middle::ty::layout::TyAndLayout; -use rustc_middle::ty::{FloatTy, PolyExistentialPredicate, Ty, TyCtxt, TypeFoldable}; +use rustc_middle::ty::{FloatTy, PolyExistentialPredicate, Ty, TyCtxt}; use rustc_middle::{bug, span_bug, ty}; use rustc_span::{Symbol, sym}; use rustc_trait_selection::traits::{Obligation, ObligationCause, ObligationCtxt}; @@ -243,13 +243,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { ocx.register_obligations(preds.iter().map(|pred: PolyExistentialPredicate<'_>| { let pred = pred.with_self_ty(tcx, tp_ty); // Lifetimes can only be 'static because of the bound on T - let pred = pred.fold_with(&mut ty::BottomUpFolder { - tcx, - ty_op: |ty| ty, - lt_op: |lt| { - if lt == tcx.lifetimes.re_erased { tcx.lifetimes.re_static } else { lt } - }, - ct_op: |ct| ct, + let pred = ty::fold_regions(tcx, pred, |r, _| { + if r == tcx.lifetimes.re_erased { tcx.lifetimes.re_static } else { r } }); Obligation::new(tcx, ObligationCause::dummy(), param_env, pred) })); diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index ad66003a6bf9..4664bfcce853 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -508,23 +508,18 @@ fn sanity_check_found_hidden_type<'tcx>( return Ok(()); } } - let strip_vars = |ty: Ty<'tcx>| { - ty.fold_with(&mut BottomUpFolder { - tcx, - ty_op: |t| t, - ct_op: |c| c, - lt_op: |l| match l.kind() { - RegionKind::ReVar(_) => tcx.lifetimes.re_erased, - _ => l, - }, + let erase_re_vars = |ty: Ty<'tcx>| { + fold_regions(tcx, ty, |r, _| match r.kind() { + RegionKind::ReVar(_) => tcx.lifetimes.re_erased, + _ => r, }) }; // Closures frequently end up containing erased lifetimes in their final representation. // These correspond to lifetime variables that never got resolved, so we patch this up here. - ty.ty = strip_vars(ty.ty); + ty.ty = erase_re_vars(ty.ty); // Get the hidden type. let hidden_ty = tcx.type_of(key.def_id).instantiate(tcx, key.args); - let hidden_ty = strip_vars(hidden_ty); + let hidden_ty = erase_re_vars(hidden_ty); // If the hidden types differ, emit a type mismatch diagnostic. if hidden_ty == ty.ty {