Skip to content

Commit a803f31

Browse files
committed
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
2 parents 39b2a41 + 3eb5b62 commit a803f31

File tree

4 files changed

+6
-36
lines changed

4 files changed

+6
-36
lines changed

compiler/rustc_hir_analysis/src/collect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
489489
format!(
490490
"{}::",
491491
// Erase named lt, we want `<A as B<'_>::C`, not `<A as B<'a>::C`.
492-
self.tcx.anonymize_late_bound_regions(poly_trait_ref).skip_binder(),
492+
self.tcx.anonymize_bound_vars(poly_trait_ref).skip_binder(),
493493
),
494494
Applicability::MaybeIncorrect,
495495
);

compiler/rustc_hir_typeck/src/closure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
426426
// `deduce_expectations_from_expected_type` introduces
427427
// late-bound lifetimes defined elsewhere, which we now
428428
// anonymize away, so as not to confuse the user.
429-
let bound_sig = self.tcx.anonymize_late_bound_regions(bound_sig);
429+
let bound_sig = self.tcx.anonymize_bound_vars(bound_sig);
430430

431431
let closure_sigs = self.closure_sigs(expr_def_id, body, bound_sig);
432432

compiler/rustc_middle/src/ty/fold.rs

-30
Original file line numberDiff line numberDiff line change
@@ -583,36 +583,6 @@ impl<'tcx> TyCtxt<'tcx> {
583583
self.replace_late_bound_regions(value, |_| self.lifetimes.re_erased).0
584584
}
585585

586-
/// Rewrite any late-bound regions so that they are anonymous. Region numbers are
587-
/// assigned starting at 0 and increasing monotonically in the order traversed
588-
/// by the fold operation.
589-
///
590-
/// The chief purpose of this function is to canonicalize regions so that two
591-
/// `FnSig`s or `TraitRef`s which are equivalent up to region naming will become
592-
/// structurally identical. For example, `for<'a, 'b> fn(&'a isize, &'b isize)` and
593-
/// `for<'a, 'b> fn(&'b isize, &'a isize)` will become identical after anonymization.
594-
pub fn anonymize_late_bound_regions<T>(self, sig: Binder<'tcx, T>) -> Binder<'tcx, T>
595-
where
596-
T: TypeFoldable<'tcx>,
597-
{
598-
let mut counter = 0;
599-
let inner = self
600-
.replace_late_bound_regions(sig, |_| {
601-
let br = ty::BoundRegion {
602-
var: ty::BoundVar::from_u32(counter),
603-
kind: ty::BrAnon(counter, None),
604-
};
605-
let r = self.mk_region(ty::ReLateBound(ty::INNERMOST, br));
606-
counter += 1;
607-
r
608-
})
609-
.0;
610-
let bound_vars = self.mk_bound_variable_kinds(
611-
(0..counter).map(|i| ty::BoundVariableKind::Region(ty::BrAnon(i, None))),
612-
);
613-
Binder::bind_with_vars(inner, bound_vars)
614-
}
615-
616586
/// Anonymize all bound variables in `value`, this is mostly used to improve caching.
617587
pub fn anonymize_bound_vars<T>(self, value: Binder<'tcx, T>) -> Binder<'tcx, T>
618588
where

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1812,10 +1812,10 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
18121812
&& self.tcx.is_fn_trait(trait_pred.def_id())
18131813
{
18141814
let expected_self =
1815-
self.tcx.anonymize_late_bound_regions(pred.kind().rebind(trait_pred.self_ty()));
1815+
self.tcx.anonymize_bound_vars(pred.kind().rebind(trait_pred.self_ty()));
18161816
let expected_substs = self
18171817
.tcx
1818-
.anonymize_late_bound_regions(pred.kind().rebind(trait_pred.trait_ref.substs));
1818+
.anonymize_bound_vars(pred.kind().rebind(trait_pred.trait_ref.substs));
18191819

18201820
// Find another predicate whose self-type is equal to the expected self type,
18211821
// but whose substs don't match.
@@ -1828,12 +1828,12 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
18281828
// Make sure that the self type matches
18291829
// (i.e. constraining this closure)
18301830
&& expected_self
1831-
== self.tcx.anonymize_late_bound_regions(
1831+
== self.tcx.anonymize_bound_vars(
18321832
pred.kind().rebind(trait_pred.self_ty()),
18331833
)
18341834
// But the substs don't match (i.e. incompatible args)
18351835
&& expected_substs
1836-
!= self.tcx.anonymize_late_bound_regions(
1836+
!= self.tcx.anonymize_bound_vars(
18371837
pred.kind().rebind(trait_pred.trait_ref.substs),
18381838
) =>
18391839
{

0 commit comments

Comments
 (0)