Skip to content

Commit f87953f

Browse files
authored
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!
1 parent 2a22093 commit f87953f

File tree

1 file changed

+3
-3
lines changed
  • compiler/rustc_infer/src/infer/canonical

1 file changed

+3
-3
lines changed

compiler/rustc_infer/src/infer/canonical/mod.rs

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

7070
let canonical_inference_vars =

0 commit comments

Comments
 (0)