Skip to content

Commit

Permalink
Comment, and bail early if bound vars list differs
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Sep 22, 2022
1 parent d018144 commit 02ad984
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
11 changes: 6 additions & 5 deletions compiler/rustc_infer/src/infer/equate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
)));
}
}

Expand Down
11 changes: 5 additions & 6 deletions compiler/rustc_infer/src/infer/sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
}

_ => {
Expand Down

0 comments on commit 02ad984

Please sign in to comment.