Skip to content

Commit fcba8d3

Browse files
committed
Remove the Instantiator now that we don't recurse within it anymore
1 parent e03edd2 commit fcba8d3

File tree

1 file changed

+19
-28
lines changed

1 file changed

+19
-28
lines changed

compiler/rustc_infer/src/infer/opaque_types.rs

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
8686
if !matches!(a.kind(), ty::Opaque(..)) {
8787
return None;
8888
}
89-
Instantiator { infcx: self, cause: cause.clone(), param_env }
90-
.fold_opaque_ty_new(a, |_, _| b)
89+
self.fold_opaque_ty_new(a, cause.clone(), param_env, |_, _| b)
9190
};
9291
if let Some(res) = process(a, b) {
9392
res
@@ -480,16 +479,12 @@ impl UseKind {
480479
}
481480
}
482481

483-
struct Instantiator<'a, 'tcx> {
484-
infcx: &'a InferCtxt<'a, 'tcx>,
485-
cause: ObligationCause<'tcx>,
486-
param_env: ty::ParamEnv<'tcx>,
487-
}
488-
489-
impl<'a, 'tcx> Instantiator<'a, 'tcx> {
482+
impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
490483
fn fold_opaque_ty_new(
491-
&mut self,
484+
&self,
492485
ty: Ty<'tcx>,
486+
cause: ObligationCause<'tcx>,
487+
param_env: ty::ParamEnv<'tcx>,
493488
mk_ty: impl FnOnce(&InferCtxt<'_, 'tcx>, Span) -> Ty<'tcx>,
494489
) -> Option<InferResult<'tcx, ()>> {
495490
// Check that this is `impl Trait` type is
@@ -527,9 +522,8 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
527522
// }
528523
// ```
529524
let opaque_type_key = ty.expect_opaque_type();
530-
if let Some(origin) = self.infcx.opaque_type_origin(opaque_type_key.def_id, self.cause.span)
531-
{
532-
return Some(self.fold_opaque_ty(ty, opaque_type_key, origin, mk_ty));
525+
if let Some(origin) = self.opaque_type_origin(opaque_type_key.def_id, cause.span) {
526+
return Some(self.fold_opaque_ty(ty, cause, param_env, opaque_type_key, origin, mk_ty));
533527
}
534528

535529
debug!(?ty, "encountered opaque outside its definition scope",);
@@ -538,34 +532,35 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
538532

539533
#[instrument(skip(self, mk_ty), level = "debug")]
540534
fn fold_opaque_ty(
541-
&mut self,
535+
&self,
542536
ty: Ty<'tcx>,
537+
cause: ObligationCause<'tcx>,
538+
param_env: ty::ParamEnv<'tcx>,
543539
opaque_type_key: OpaqueTypeKey<'tcx>,
544540
origin: hir::OpaqueTyOrigin,
545541
mk_ty: impl FnOnce(&InferCtxt<'_, 'tcx>, Span) -> Ty<'tcx>,
546542
) -> InferResult<'tcx, ()> {
547-
let infcx = self.infcx;
548-
let tcx = infcx.tcx;
543+
let tcx = self.tcx;
549544
let OpaqueTypeKey { def_id, substs } = opaque_type_key;
550545

551-
let ty_var = mk_ty(infcx, self.cause.span);
546+
let ty_var = mk_ty(self, cause.span);
552547

553548
// Ideally, we'd get the span where *this specific `ty` came
554549
// from*, but right now we just use the span from the overall
555550
// value being folded. In simple cases like `-> impl Foo`,
556551
// these are the same span, but not in cases like `-> (impl
557552
// Foo, impl Bar)`.
558-
let span = self.cause.span;
553+
let span = cause.span;
559554

560555
let mut obligations = vec![];
561-
let prev = self.infcx.inner.borrow_mut().opaque_types().register(
556+
let prev = self.inner.borrow_mut().opaque_types().register(
562557
OpaqueTypeKey { def_id, substs },
563558
ty,
564559
OpaqueHiddenType { ty: ty_var, span },
565560
origin,
566561
);
567562
if let Some(prev) = prev {
568-
obligations = self.infcx.at(&self.cause, self.param_env).eq(prev, ty_var)?.obligations;
563+
obligations = self.at(&cause, param_env).eq(prev, ty_var)?.obligations;
569564
}
570565

571566
debug!("generated new type inference var {:?}", ty_var.kind());
@@ -581,10 +576,10 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
581576
ty_op: |ty| match *ty.kind() {
582577
// We can't normalize associated types from `rustc_infer`,
583578
// but we can eagerly register inference variables for them.
584-
ty::Projection(projection_ty) if !projection_ty.has_escaping_bound_vars() => infcx.infer_projection(
585-
self.param_env,
579+
ty::Projection(projection_ty) if !projection_ty.has_escaping_bound_vars() => self.infer_projection(
580+
param_env,
586581
projection_ty,
587-
self.cause.clone(),
582+
cause.clone(),
588583
0,
589584
&mut obligations,
590585
),
@@ -608,11 +603,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
608603
}
609604
// Require that the predicate holds for the concrete type.
610605
debug!(?predicate);
611-
obligations.push(traits::Obligation::new(
612-
self.cause.clone(),
613-
self.param_env,
614-
predicate,
615-
));
606+
obligations.push(traits::Obligation::new(cause.clone(), param_env, predicate));
616607
}
617608
Ok(InferOk { value: (), obligations })
618609
}

0 commit comments

Comments
 (0)