1
Fork 0

Auto merge of #105717 - compiler-errors:anonymize, r=jackh726

always use `anonymize_bound_vars`

Unless this is perf-sensitive, it's probably best to always use one anonymize function that does the right thing for all bound vars.

r? types
This commit is contained in:
bors 2022-12-16 06:45:08 +00:00
commit a803f313fd
4 changed files with 6 additions and 36 deletions

View file

@ -583,36 +583,6 @@ impl<'tcx> TyCtxt<'tcx> {
self.replace_late_bound_regions(value, |_| self.lifetimes.re_erased).0
}
/// Rewrite any late-bound regions so that they are anonymous. Region numbers are
/// assigned starting at 0 and increasing monotonically in the order traversed
/// by the fold operation.
///
/// The chief purpose of this function is to canonicalize regions so that two
/// `FnSig`s or `TraitRef`s which are equivalent up to region naming will become
/// structurally identical. For example, `for<'a, 'b> fn(&'a isize, &'b isize)` and
/// `for<'a, 'b> fn(&'b isize, &'a isize)` will become identical after anonymization.
pub fn anonymize_late_bound_regions<T>(self, sig: Binder<'tcx, T>) -> Binder<'tcx, T>
where
T: TypeFoldable<'tcx>,
{
let mut counter = 0;
let inner = self
.replace_late_bound_regions(sig, |_| {
let br = ty::BoundRegion {
var: ty::BoundVar::from_u32(counter),
kind: ty::BrAnon(counter, None),
};
let r = self.mk_region(ty::ReLateBound(ty::INNERMOST, br));
counter += 1;
r
})
.0;
let bound_vars = self.mk_bound_variable_kinds(
(0..counter).map(|i| ty::BoundVariableKind::Region(ty::BrAnon(i, None))),
);
Binder::bind_with_vars(inner, bound_vars)
}
/// Anonymize all bound variables in `value`, this is mostly used to improve caching.
pub fn anonymize_bound_vars<T>(self, value: Binder<'tcx, T>) -> Binder<'tcx, T>
where