1
Fork 0

fix universe map in ifcx.instantiate_canonical_*

Previously, `infcx.instantiate_canonical_*` maps the root universe in `canonical` into `ty::UniverseIndex::Root`, I think because it assumes it works with a fresh `infcx` but this is not true for the use cases in mir typeck. Now the root universe is mapped into `infcx.universe()`.

I catched this accidentally while reviewing the code. I'm not sure if this is the right fix or if it is really a bug!
This commit is contained in:
Ali MJ Al-Nasrawy 2022-07-27 18:34:46 +03:00 committed by GitHub
parent 2a220937c2
commit f87953f01a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -41,7 +41,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
/// inference variables and applies it to the canonical value.
/// Returns both the instantiated result *and* the substitution S.
///
/// This is only meant to be invoked as part of constructing an
/// This can be invoked as part of constructing an
/// inference context at the start of a query (see
/// `InferCtxtBuilder::enter_with_canonical`). It basically
/// brings the canonical value "into scope" within your new infcx.
@ -63,8 +63,8 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
// in them, so this code has no effect, but it is looking
// forward to the day when we *do* want to carry universes
// through into queries.
let universes: IndexVec<ty::UniverseIndex, _> = std::iter::once(ty::UniverseIndex::ROOT)
.chain((0..canonical.max_universe.as_u32()).map(|_| self.create_next_universe()))
let universes: IndexVec<ty::UniverseIndex, _> = std::iter::once(self.universe())
.chain((1..=canonical.max_universe.as_u32()).map(|_| self.create_next_universe()))
.collect();
let canonical_inference_vars =