Skip to content

Commit 5c46002

Browse files
committed
Eagerly instantiate opaque types
1 parent 689a868 commit 5c46002

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

compiler/rustc_infer/src/infer/opaque_types.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -551,14 +551,16 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
551551
let predicate = predicate.subst(tcx, substs);
552552
debug!(?predicate);
553553

554-
// Replace all other mentions of the same opaque type with the hidden type,
555-
// as the bounds must hold on the hidden type after all.
556554
let predicate = predicate.fold_with(&mut BottomUpFolder {
557555
tcx,
558556
ty_op: |ty| match *ty.kind() {
557+
// Replace all other mentions of the same opaque type with the hidden type,
558+
// as the bounds must hold on the hidden type after all.
559559
ty::Opaque(def_id2, substs2) if def_id == def_id2 && substs == substs2 => {
560560
ty_var
561561
}
562+
// Instantiate nested instances of `impl Trait`.
563+
ty::Opaque(..) => self.instantiate_opaque_types_in_map(ty),
562564
_ => ty,
563565
},
564566
lt_op: |lt| lt,
@@ -589,10 +591,6 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
589591
return tcx.ty_error();
590592
}
591593
}
592-
// Change the predicate to refer to the type variable,
593-
// which will be the concrete type instead of the opaque type.
594-
// This also instantiates nested instances of `impl Trait`.
595-
let predicate = self.instantiate_opaque_types_in_map(predicate);
596594

597595
let cause =
598596
traits::ObligationCause::new(self.value_span, self.body_id, traits::OpaqueType);

0 commit comments

Comments
 (0)