From c0d780395092fdb3a54403b9aaefdb38e25c9ddd Mon Sep 17 00:00:00 2001 From: scalexm Date: Sat, 24 Nov 2018 17:13:54 +0100 Subject: [PATCH] Fix replacement of escaping bound types Multiple references to the same `BoundTy` were not using the same result. --- src/librustc/ty/fold.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/librustc/ty/fold.rs b/src/librustc/ty/fold.rs index 288ca58f8ba..0a72f733b51 100644 --- a/src/librustc/ty/fold.rs +++ b/src/librustc/ty/fold.rs @@ -533,18 +533,25 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { G: FnMut(ty::BoundTy) -> ty::Ty<'tcx>, T: TypeFoldable<'tcx> { - let mut map = BTreeMap::new(); + use rustc_data_structures::fx::FxHashMap; + + let mut region_map = BTreeMap::new(); + let mut type_map = FxHashMap::default(); if !value.has_escaping_bound_vars() { - (value.clone(), map) + (value.clone(), region_map) } else { let mut real_fld_r = |br| { - *map.entry(br).or_insert_with(|| fld_r(br)) + *region_map.entry(br).or_insert_with(|| fld_r(br)) }; - let mut replacer = BoundVarReplacer::new(self, &mut real_fld_r, &mut fld_t); + let mut real_fld_t = |bound_ty| { + *type_map.entry(bound_ty).or_insert_with(|| fld_t(bound_ty)) + }; + + let mut replacer = BoundVarReplacer::new(self, &mut real_fld_r, &mut real_fld_t); let result = value.fold_with(&mut replacer); - (result, map) + (result, region_map) } }