mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
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:
commit
a803f313fd
@ -489,7 +489,7 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
|
||||
format!(
|
||||
"{}::",
|
||||
// Erase named lt, we want `<A as B<'_>::C`, not `<A as B<'a>::C`.
|
||||
self.tcx.anonymize_late_bound_regions(poly_trait_ref).skip_binder(),
|
||||
self.tcx.anonymize_bound_vars(poly_trait_ref).skip_binder(),
|
||||
),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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
|
||||
|
@ -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),
|
||||
) =>
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user