Remove the Instantiator
now that we don't recurse within it anymore
This commit is contained in:
parent
e03edd287e
commit
fcba8d31c4
1 changed files with 19 additions and 28 deletions
|
@ -86,8 +86,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
if !matches!(a.kind(), ty::Opaque(..)) {
|
if !matches!(a.kind(), ty::Opaque(..)) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
Instantiator { infcx: self, cause: cause.clone(), param_env }
|
self.fold_opaque_ty_new(a, cause.clone(), param_env, |_, _| b)
|
||||||
.fold_opaque_ty_new(a, |_, _| b)
|
|
||||||
};
|
};
|
||||||
if let Some(res) = process(a, b) {
|
if let Some(res) = process(a, b) {
|
||||||
res
|
res
|
||||||
|
@ -480,16 +479,12 @@ impl UseKind {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Instantiator<'a, 'tcx> {
|
impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
infcx: &'a InferCtxt<'a, 'tcx>,
|
|
||||||
cause: ObligationCause<'tcx>,
|
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, 'tcx> Instantiator<'a, 'tcx> {
|
|
||||||
fn fold_opaque_ty_new(
|
fn fold_opaque_ty_new(
|
||||||
&mut self,
|
&self,
|
||||||
ty: Ty<'tcx>,
|
ty: Ty<'tcx>,
|
||||||
|
cause: ObligationCause<'tcx>,
|
||||||
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
mk_ty: impl FnOnce(&InferCtxt<'_, 'tcx>, Span) -> Ty<'tcx>,
|
mk_ty: impl FnOnce(&InferCtxt<'_, 'tcx>, Span) -> Ty<'tcx>,
|
||||||
) -> Option<InferResult<'tcx, ()>> {
|
) -> Option<InferResult<'tcx, ()>> {
|
||||||
// Check that this is `impl Trait` type is
|
// Check that this is `impl Trait` type is
|
||||||
|
@ -527,9 +522,8 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
|
||||||
// }
|
// }
|
||||||
// ```
|
// ```
|
||||||
let opaque_type_key = ty.expect_opaque_type();
|
let opaque_type_key = ty.expect_opaque_type();
|
||||||
if let Some(origin) = self.infcx.opaque_type_origin(opaque_type_key.def_id, self.cause.span)
|
if let Some(origin) = self.opaque_type_origin(opaque_type_key.def_id, cause.span) {
|
||||||
{
|
return Some(self.fold_opaque_ty(ty, cause, param_env, opaque_type_key, origin, mk_ty));
|
||||||
return Some(self.fold_opaque_ty(ty, opaque_type_key, origin, mk_ty));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!(?ty, "encountered opaque outside its definition scope",);
|
debug!(?ty, "encountered opaque outside its definition scope",);
|
||||||
|
@ -538,34 +532,35 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
|
||||||
|
|
||||||
#[instrument(skip(self, mk_ty), level = "debug")]
|
#[instrument(skip(self, mk_ty), level = "debug")]
|
||||||
fn fold_opaque_ty(
|
fn fold_opaque_ty(
|
||||||
&mut self,
|
&self,
|
||||||
ty: Ty<'tcx>,
|
ty: Ty<'tcx>,
|
||||||
|
cause: ObligationCause<'tcx>,
|
||||||
|
param_env: ty::ParamEnv<'tcx>,
|
||||||
opaque_type_key: OpaqueTypeKey<'tcx>,
|
opaque_type_key: OpaqueTypeKey<'tcx>,
|
||||||
origin: hir::OpaqueTyOrigin,
|
origin: hir::OpaqueTyOrigin,
|
||||||
mk_ty: impl FnOnce(&InferCtxt<'_, 'tcx>, Span) -> Ty<'tcx>,
|
mk_ty: impl FnOnce(&InferCtxt<'_, 'tcx>, Span) -> Ty<'tcx>,
|
||||||
) -> InferResult<'tcx, ()> {
|
) -> InferResult<'tcx, ()> {
|
||||||
let infcx = self.infcx;
|
let tcx = self.tcx;
|
||||||
let tcx = infcx.tcx;
|
|
||||||
let OpaqueTypeKey { def_id, substs } = opaque_type_key;
|
let OpaqueTypeKey { def_id, substs } = opaque_type_key;
|
||||||
|
|
||||||
let ty_var = mk_ty(infcx, self.cause.span);
|
let ty_var = mk_ty(self, cause.span);
|
||||||
|
|
||||||
// Ideally, we'd get the span where *this specific `ty` came
|
// Ideally, we'd get the span where *this specific `ty` came
|
||||||
// from*, but right now we just use the span from the overall
|
// from*, but right now we just use the span from the overall
|
||||||
// value being folded. In simple cases like `-> impl Foo`,
|
// value being folded. In simple cases like `-> impl Foo`,
|
||||||
// these are the same span, but not in cases like `-> (impl
|
// these are the same span, but not in cases like `-> (impl
|
||||||
// Foo, impl Bar)`.
|
// Foo, impl Bar)`.
|
||||||
let span = self.cause.span;
|
let span = cause.span;
|
||||||
|
|
||||||
let mut obligations = vec![];
|
let mut obligations = vec![];
|
||||||
let prev = self.infcx.inner.borrow_mut().opaque_types().register(
|
let prev = self.inner.borrow_mut().opaque_types().register(
|
||||||
OpaqueTypeKey { def_id, substs },
|
OpaqueTypeKey { def_id, substs },
|
||||||
ty,
|
ty,
|
||||||
OpaqueHiddenType { ty: ty_var, span },
|
OpaqueHiddenType { ty: ty_var, span },
|
||||||
origin,
|
origin,
|
||||||
);
|
);
|
||||||
if let Some(prev) = prev {
|
if let Some(prev) = prev {
|
||||||
obligations = self.infcx.at(&self.cause, self.param_env).eq(prev, ty_var)?.obligations;
|
obligations = self.at(&cause, param_env).eq(prev, ty_var)?.obligations;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!("generated new type inference var {:?}", ty_var.kind());
|
debug!("generated new type inference var {:?}", ty_var.kind());
|
||||||
|
@ -581,10 +576,10 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
|
||||||
ty_op: |ty| match *ty.kind() {
|
ty_op: |ty| match *ty.kind() {
|
||||||
// We can't normalize associated types from `rustc_infer`,
|
// We can't normalize associated types from `rustc_infer`,
|
||||||
// but we can eagerly register inference variables for them.
|
// but we can eagerly register inference variables for them.
|
||||||
ty::Projection(projection_ty) if !projection_ty.has_escaping_bound_vars() => infcx.infer_projection(
|
ty::Projection(projection_ty) if !projection_ty.has_escaping_bound_vars() => self.infer_projection(
|
||||||
self.param_env,
|
param_env,
|
||||||
projection_ty,
|
projection_ty,
|
||||||
self.cause.clone(),
|
cause.clone(),
|
||||||
0,
|
0,
|
||||||
&mut obligations,
|
&mut obligations,
|
||||||
),
|
),
|
||||||
|
@ -608,11 +603,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
// Require that the predicate holds for the concrete type.
|
// Require that the predicate holds for the concrete type.
|
||||||
debug!(?predicate);
|
debug!(?predicate);
|
||||||
obligations.push(traits::Obligation::new(
|
obligations.push(traits::Obligation::new(cause.clone(), param_env, predicate));
|
||||||
self.cause.clone(),
|
|
||||||
self.param_env,
|
|
||||||
predicate,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
Ok(InferOk { value: (), obligations })
|
Ok(InferOk { value: (), obligations })
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue