diff --git a/compiler/rustc_infer/src/infer/equate.rs b/compiler/rustc_infer/src/infer/equate.rs index a962bbb03addb..59728148a84c4 100644 --- a/compiler/rustc_infer/src/infer/equate.rs +++ b/compiler/rustc_infer/src/infer/equate.rs @@ -110,6 +110,9 @@ impl<'tcx> TypeRelation<'tcx> for Equate<'_, '_, 'tcx> { .obligations, ); } + // Optimization of GeneratorWitness relation since we know that all + // free regions are replaced with bound regions during construction. + // This greatly speeds up equating of GeneratorWitness. (&ty::GeneratorWitness(a_types), &ty::GeneratorWitness(b_types)) => { let a_types = infcx.tcx.anonymize_bound_vars(a_types); let b_types = infcx.tcx.anonymize_bound_vars(b_types); @@ -121,11 +124,9 @@ impl<'tcx> TypeRelation<'tcx> for Equate<'_, '_, 'tcx> { self.relate(a, b)?; } } else { - self.fields.infcx.super_combine_tys( - self, - infcx.tcx.mk_generator_witness(a_types), - infcx.tcx.mk_generator_witness(b_types), - )?; + return Err(ty::error::TypeError::Sorts(ty::relate::expected_found( + self, a, b, + ))); } } diff --git a/compiler/rustc_infer/src/infer/sub.rs b/compiler/rustc_infer/src/infer/sub.rs index 2c14a9414f278..375dd670fabf4 100644 --- a/compiler/rustc_infer/src/infer/sub.rs +++ b/compiler/rustc_infer/src/infer/sub.rs @@ -164,6 +164,9 @@ impl<'tcx> TypeRelation<'tcx> for Sub<'_, '_, 'tcx> { ); Ok(ga) } + // Optimization of GeneratorWitness relation since we know that all + // free regions are replaced with bound regions during construction. + // This greatly speeds up subtyping of GeneratorWitness. (&ty::GeneratorWitness(a_types), &ty::GeneratorWitness(b_types)) => { let a_types = infcx.tcx.anonymize_bound_vars(a_types); let b_types = infcx.tcx.anonymize_bound_vars(b_types); @@ -174,14 +177,10 @@ impl<'tcx> TypeRelation<'tcx> for Sub<'_, '_, 'tcx> { for (a, b) in std::iter::zip(a_types, b_types) { self.relate(a, b)?; } + Ok(a) } else { - self.fields.infcx.super_combine_tys( - self, - infcx.tcx.mk_generator_witness(a_types), - infcx.tcx.mk_generator_witness(b_types), - )?; + Err(ty::error::TypeError::Sorts(ty::relate::expected_found(self, a, b))) } - Ok(a) } _ => {