diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index 1eeaaf55e63..0c4649cea14 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -489,7 +489,7 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> { format!( "{}::", // Erase named lt, we want `::C`, not `::C`. - self.tcx.anonymize_late_bound_regions(poly_trait_ref).skip_binder(), + self.tcx.anonymize_bound_vars(poly_trait_ref).skip_binder(), ), Applicability::MaybeIncorrect, ); diff --git a/compiler/rustc_hir_typeck/src/closure.rs b/compiler/rustc_hir_typeck/src/closure.rs index 72d8a936ab3..5bd02dff73b 100644 --- a/compiler/rustc_hir_typeck/src/closure.rs +++ b/compiler/rustc_hir_typeck/src/closure.rs @@ -426,7 +426,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // `deduce_expectations_from_expected_type` introduces // late-bound lifetimes defined elsewhere, which we now // anonymize away, so as not to confuse the user. - let bound_sig = self.tcx.anonymize_late_bound_regions(bound_sig); + let bound_sig = self.tcx.anonymize_bound_vars(bound_sig); let closure_sigs = self.closure_sigs(expr_def_id, body, bound_sig); diff --git a/compiler/rustc_middle/src/ty/fold.rs b/compiler/rustc_middle/src/ty/fold.rs index d431d008ddf..09fee0c3f7c 100644 --- a/compiler/rustc_middle/src/ty/fold.rs +++ b/compiler/rustc_middle/src/ty/fold.rs @@ -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(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(self, value: Binder<'tcx, T>) -> Binder<'tcx, T> where diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 057b0a368bf..d47a5ea3e37 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -1812,10 +1812,10 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { && self.tcx.is_fn_trait(trait_pred.def_id()) { let expected_self = - self.tcx.anonymize_late_bound_regions(pred.kind().rebind(trait_pred.self_ty())); + self.tcx.anonymize_bound_vars(pred.kind().rebind(trait_pred.self_ty())); let expected_substs = self .tcx - .anonymize_late_bound_regions(pred.kind().rebind(trait_pred.trait_ref.substs)); + .anonymize_bound_vars(pred.kind().rebind(trait_pred.trait_ref.substs)); // Find another predicate whose self-type is equal to the expected self type, // but whose substs don't match. @@ -1828,12 +1828,12 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { // Make sure that the self type matches // (i.e. constraining this closure) && expected_self - == self.tcx.anonymize_late_bound_regions( + == self.tcx.anonymize_bound_vars( pred.kind().rebind(trait_pred.self_ty()), ) // But the substs don't match (i.e. incompatible args) && expected_substs - != self.tcx.anonymize_late_bound_regions( + != self.tcx.anonymize_bound_vars( pred.kind().rebind(trait_pred.trait_ref.substs), ) => {