Skip to content

Commit d526a8d

Browse files
committed
Clean up opaque type obligations in query results
1 parent d9bb93f commit d526a8d

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

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

+7-8
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use rustc_middle::arena::ArenaAllocatable;
2525
use rustc_middle::ty::fold::TypeFoldable;
2626
use rustc_middle::ty::relate::TypeRelation;
2727
use rustc_middle::ty::subst::{GenericArg, GenericArgKind};
28-
use rustc_middle::ty::{self, BoundVar, Const, OpaqueTypeKey, ToPredicate, Ty, TyCtxt};
28+
use rustc_middle::ty::{self, BoundVar, Const, ToPredicate, Ty, TyCtxt};
2929
use rustc_span::Span;
3030
use std::fmt::Debug;
3131
use std::iter;
@@ -146,13 +146,13 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
146146
})
147147
}
148148

149-
fn take_opaque_types_for_query_response(&self) -> Vec<(OpaqueTypeKey<'tcx>, Ty<'tcx>)> {
149+
fn take_opaque_types_for_query_response(&self) -> Vec<(Ty<'tcx>, Ty<'tcx>)> {
150150
self.inner
151151
.borrow_mut()
152152
.opaque_type_storage
153153
.take_opaque_types()
154154
.into_iter()
155-
.map(|(k, v)| (k, v.hidden_type.ty))
155+
.map(|(k, v)| (self.tcx.mk_opaque(k.def_id, k.substs), v.hidden_type.ty))
156156
.collect()
157157
}
158158

@@ -497,11 +497,10 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
497497
let mut obligations = vec![];
498498

499499
// Carry all newly resolved opaque types to the caller's scope
500-
for &(key, ty) in &query_response.value.opaque_types {
501-
let substs = substitute_value(self.tcx, &result_subst, key.substs);
502-
let opaque = self.tcx.mk_opaque(key.def_id, substs);
503-
let ty = substitute_value(self.tcx, &result_subst, ty);
504-
obligations.extend(self.handle_opaque_type(opaque, ty, cause, param_env)?.obligations);
500+
for &(a, b) in &query_response.value.opaque_types {
501+
let a = substitute_value(self.tcx, &result_subst, a);
502+
let b = substitute_value(self.tcx, &result_subst, b);
503+
obligations.extend(self.handle_opaque_type(a, b, cause, param_env)?.obligations);
505504
}
506505

507506
Ok(InferOk { value: result_subst, obligations })

compiler/rustc_middle/src/infer/canonical.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
2424
use crate::infer::MemberConstraint;
2525
use crate::ty::subst::GenericArg;
26-
use crate::ty::{self, BoundVar, List, OpaqueTypeKey, Region, Ty, TyCtxt};
26+
use crate::ty::{self, BoundVar, List, Region, Ty, TyCtxt};
2727
use rustc_index::vec::IndexVec;
2828
use rustc_macros::HashStable;
2929
use smallvec::SmallVec;
@@ -178,9 +178,12 @@ pub struct QueryResponse<'tcx, R> {
178178
pub var_values: CanonicalVarValues<'tcx>,
179179
pub region_constraints: QueryRegionConstraints<'tcx>,
180180
pub certainty: Certainty,
181-
/// List of opaque types for which we figured out a hidden type
182-
/// during the evaluation of the query.
183-
pub opaque_types: Vec<(OpaqueTypeKey<'tcx>, Ty<'tcx>)>,
181+
/// List of opaque types which we tried to compare to another type.
182+
/// Inside the query we don't know yet whether the opaque type actually
183+
/// should get its hidden type inferred. So we bubble the opaque type
184+
/// and the type it was compared against upwards and let the query caller
185+
/// handle it.
186+
pub opaque_types: Vec<(Ty<'tcx>, Ty<'tcx>)>,
184187
pub value: R,
185188
}
186189

0 commit comments

Comments
 (0)