Skip to content

Commit 90711a8

Browse files
committed
Auto merge of rust-lang#99814 - aliemjay:patch-2, r=jackh726
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!
2 parents 24606de + 70200ac commit 90711a8

File tree

1 file changed

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

1 file changed

+6
-3
lines changed

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl<'tcx> InferCtxt<'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::build_with_canonical`). It basically
4747
/// brings the canonical value "into scope" within your new infcx.
@@ -63,8 +63,11 @@ impl<'tcx> InferCtxt<'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+
//
67+
// Instantiate the root-universe content into the current universe,
68+
// and create fresh universes for the higher universes.
69+
let universes: IndexVec<ty::UniverseIndex, _> = std::iter::once(self.universe())
70+
.chain((1..=canonical.max_universe.as_u32()).map(|_| self.create_next_universe()))
6871
.collect();
6972

7073
let canonical_inference_vars =

0 commit comments

Comments
 (0)