From d526a8d5940182c9e020783600578a1f7b4b2122 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 3 Feb 2022 13:44:29 +0000 Subject: [PATCH] Clean up opaque type obligations in query results --- .../src/infer/canonical/query_response.rs | 15 +++++++-------- compiler/rustc_middle/src/infer/canonical.rs | 11 +++++++---- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_infer/src/infer/canonical/query_response.rs b/compiler/rustc_infer/src/infer/canonical/query_response.rs index 18a1120051efe..7d86f8a763c30 100644 --- a/compiler/rustc_infer/src/infer/canonical/query_response.rs +++ b/compiler/rustc_infer/src/infer/canonical/query_response.rs @@ -25,7 +25,7 @@ use rustc_middle::arena::ArenaAllocatable; use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::relate::TypeRelation; use rustc_middle::ty::subst::{GenericArg, GenericArgKind}; -use rustc_middle::ty::{self, BoundVar, Const, OpaqueTypeKey, ToPredicate, Ty, TyCtxt}; +use rustc_middle::ty::{self, BoundVar, Const, ToPredicate, Ty, TyCtxt}; use rustc_span::Span; use std::fmt::Debug; use std::iter; @@ -146,13 +146,13 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { }) } - fn take_opaque_types_for_query_response(&self) -> Vec<(OpaqueTypeKey<'tcx>, Ty<'tcx>)> { + fn take_opaque_types_for_query_response(&self) -> Vec<(Ty<'tcx>, Ty<'tcx>)> { self.inner .borrow_mut() .opaque_type_storage .take_opaque_types() .into_iter() - .map(|(k, v)| (k, v.hidden_type.ty)) + .map(|(k, v)| (self.tcx.mk_opaque(k.def_id, k.substs), v.hidden_type.ty)) .collect() } @@ -497,11 +497,10 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { let mut obligations = vec![]; // Carry all newly resolved opaque types to the caller's scope - for &(key, ty) in &query_response.value.opaque_types { - let substs = substitute_value(self.tcx, &result_subst, key.substs); - let opaque = self.tcx.mk_opaque(key.def_id, substs); - let ty = substitute_value(self.tcx, &result_subst, ty); - obligations.extend(self.handle_opaque_type(opaque, ty, cause, param_env)?.obligations); + for &(a, b) in &query_response.value.opaque_types { + let a = substitute_value(self.tcx, &result_subst, a); + let b = substitute_value(self.tcx, &result_subst, b); + obligations.extend(self.handle_opaque_type(a, b, cause, param_env)?.obligations); } Ok(InferOk { value: result_subst, obligations }) diff --git a/compiler/rustc_middle/src/infer/canonical.rs b/compiler/rustc_middle/src/infer/canonical.rs index 654ec022b604f..2fc901bdbff34 100644 --- a/compiler/rustc_middle/src/infer/canonical.rs +++ b/compiler/rustc_middle/src/infer/canonical.rs @@ -23,7 +23,7 @@ use crate::infer::MemberConstraint; use crate::ty::subst::GenericArg; -use crate::ty::{self, BoundVar, List, OpaqueTypeKey, Region, Ty, TyCtxt}; +use crate::ty::{self, BoundVar, List, Region, Ty, TyCtxt}; use rustc_index::vec::IndexVec; use rustc_macros::HashStable; use smallvec::SmallVec; @@ -178,9 +178,12 @@ pub struct QueryResponse<'tcx, R> { pub var_values: CanonicalVarValues<'tcx>, pub region_constraints: QueryRegionConstraints<'tcx>, pub certainty: Certainty, - /// List of opaque types for which we figured out a hidden type - /// during the evaluation of the query. - pub opaque_types: Vec<(OpaqueTypeKey<'tcx>, Ty<'tcx>)>, + /// List of opaque types which we tried to compare to another type. + /// Inside the query we don't know yet whether the opaque type actually + /// should get its hidden type inferred. So we bubble the opaque type + /// and the type it was compared against upwards and let the query caller + /// handle it. + pub opaque_types: Vec<(Ty<'tcx>, Ty<'tcx>)>, pub value: R, }