Comment, and bail early if bound vars list differs

This commit is contained in:
Michael Goulet 2022-08-29 18:23:45 +00:00
parent d018144761
commit 02ad984d74
2 changed files with 11 additions and 11 deletions

View File

@ -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,
)));
}
}

View File

@ -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)
}
_ => {