Skip to content

Commit b708a02

Browse files
committed
Use Vec in instantiate_binder_with_fresh_vars
1 parent 28e684b commit b708a02

File tree

1 file changed

+20
-24
lines changed
  • compiler/rustc_infer/src/infer

1 file changed

+20
-24
lines changed

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use opaque_types::OpaqueTypeStorage;
1919
use region_constraints::{GenericKind, VarInfos, VerifyBound};
2020
use region_constraints::{RegionConstraintCollector, RegionConstraintStorage};
2121
use rustc_data_structures::captures::Captures;
22-
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
22+
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
2323
use rustc_data_structures::sync::Lrc;
2424
use rustc_data_structures::undo_log::Rollback;
2525
use rustc_data_structures::unify as ut;
@@ -1317,38 +1317,34 @@ impl<'tcx> InferCtxt<'tcx> {
13171317
return inner;
13181318
}
13191319

1320-
struct ToFreshVars<'a, 'tcx> {
1321-
infcx: &'a InferCtxt<'tcx>,
1322-
span: Span,
1323-
lbrct: BoundRegionConversionTime,
1324-
map: FxHashMap<ty::BoundVar, ty::GenericArg<'tcx>>,
1320+
let bound_vars = value.bound_vars();
1321+
let mut args = Vec::with_capacity(bound_vars.len());
1322+
1323+
for bound_var_kind in bound_vars {
1324+
let arg: ty::GenericArg<'_> = match bound_var_kind {
1325+
ty::BoundVariableKind::Ty(_) => self.next_ty_var(span).into(),
1326+
ty::BoundVariableKind::Region(br) => self.next_region_var(BoundRegion(span, br, lbrct)).into(),
1327+
ty::BoundVariableKind::Const => self.next_const_var(span).into()
1328+
};
1329+
args.push(arg);
1330+
}
1331+
1332+
struct ToFreshVars<'tcx> {
1333+
args: Vec<ty::GenericArg<'tcx>>,
13251334
}
13261335

1327-
impl<'tcx> BoundVarReplacerDelegate<'tcx> for ToFreshVars<'_, 'tcx> {
1336+
impl<'tcx> BoundVarReplacerDelegate<'tcx> for ToFreshVars<'tcx> {
13281337
fn replace_region(&mut self, br: ty::BoundRegion) -> ty::Region<'tcx> {
1329-
self.map
1330-
.entry(br.var)
1331-
.or_insert_with(|| {
1332-
self.infcx
1333-
.next_region_var(BoundRegion(self.span, br.kind, self.lbrct))
1334-
.into()
1335-
})
1336-
.expect_region()
1338+
self.args[br.var.index()].expect_region()
13371339
}
13381340
fn replace_ty(&mut self, bt: ty::BoundTy) -> Ty<'tcx> {
1339-
self.map
1340-
.entry(bt.var)
1341-
.or_insert_with(|| self.infcx.next_ty_var(self.span).into())
1342-
.expect_ty()
1341+
self.args[bt.var.index()].expect_ty()
13431342
}
13441343
fn replace_const(&mut self, bv: ty::BoundVar) -> ty::Const<'tcx> {
1345-
self.map
1346-
.entry(bv)
1347-
.or_insert_with(|| self.infcx.next_const_var(self.span).into())
1348-
.expect_const()
1344+
self.args[bv.index()].expect_const()
13491345
}
13501346
}
1351-
let delegate = ToFreshVars { infcx: self, span, lbrct, map: Default::default() };
1347+
let delegate = ToFreshVars { args };
13521348
self.tcx.replace_bound_vars_uncached(value, delegate)
13531349
}
13541350

0 commit comments

Comments
 (0)