From f87953f01a5ba5966327055c935cc21eb2fc1762 Mon Sep 17 00:00:00 2001 From: Ali MJ Al-Nasrawy Date: Wed, 27 Jul 2022 18:34:46 +0300 Subject: [PATCH 1/2] 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! --- compiler/rustc_infer/src/infer/canonical/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_infer/src/infer/canonical/mod.rs b/compiler/rustc_infer/src/infer/canonical/mod.rs index f251d561c60..270c05a2370 100644 --- a/compiler/rustc_infer/src/infer/canonical/mod.rs +++ b/compiler/rustc_infer/src/infer/canonical/mod.rs @@ -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 = std::iter::once(ty::UniverseIndex::ROOT) - .chain((0..canonical.max_universe.as_u32()).map(|_| self.create_next_universe())) + let universes: IndexVec = std::iter::once(self.universe()) + .chain((1..=canonical.max_universe.as_u32()).map(|_| self.create_next_universe())) .collect(); let canonical_inference_vars = From 70200ac1907812a0f2abb7e9534e2bc26ae9f103 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 10 Oct 2022 16:51:36 -0400 Subject: [PATCH 2/2] Update compiler/rustc_infer/src/infer/canonical/mod.rs --- compiler/rustc_infer/src/infer/canonical/mod.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/rustc_infer/src/infer/canonical/mod.rs b/compiler/rustc_infer/src/infer/canonical/mod.rs index 270c05a2370..5b37dda1233 100644 --- a/compiler/rustc_infer/src/infer/canonical/mod.rs +++ b/compiler/rustc_infer/src/infer/canonical/mod.rs @@ -63,6 +63,9 @@ 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. + // + // Instantiate the root-universe content into the current universe, + // and create fresh universes for the higher universes. let universes: IndexVec = std::iter::once(self.universe()) .chain((1..=canonical.max_universe.as_u32()).map(|_| self.create_next_universe())) .collect();