1
Fork 0

Normalize before erasing late-bound regions in equal_up_to_regions

This commit is contained in:
Michael Goulet 2022-09-05 06:44:33 +00:00
parent a2cdcb3fea
commit 76b494a9dd

View file

@ -89,20 +89,21 @@ pub fn equal_up_to_regions<'tcx>(
// Normalize lifetimes away on both sides, then compare. // Normalize lifetimes away on both sides, then compare.
let normalize = |ty: Ty<'tcx>| { let normalize = |ty: Ty<'tcx>| {
let ty = ty.fold_with(&mut BottomUpFolder { tcx.try_normalize_erasing_regions(param_env, ty).unwrap_or(ty).fold_with(
tcx, &mut BottomUpFolder {
// FIXME: We erase all late-bound lifetimes, but this is not fully correct. tcx,
// If you have a type like `<for<'a> fn(&'a u32) as SomeTrait>::Assoc`, // FIXME: We erase all late-bound lifetimes, but this is not fully correct.
// this is not necessarily equivalent to `<fn(&'static u32) as SomeTrait>::Assoc`, // If you have a type like `<for<'a> fn(&'a u32) as SomeTrait>::Assoc`,
// since one may have an `impl SomeTrait for fn(&32)` and // this is not necessarily equivalent to `<fn(&'static u32) as SomeTrait>::Assoc`,
// `impl SomeTrait for fn(&'static u32)` at the same time which // since one may have an `impl SomeTrait for fn(&32)` and
// specify distinct values for Assoc. (See also #56105) // `impl SomeTrait for fn(&'static u32)` at the same time which
lt_op: |_| tcx.lifetimes.re_erased, // specify distinct values for Assoc. (See also #56105)
// Leave consts and types unchanged. lt_op: |_| tcx.lifetimes.re_erased,
ct_op: |ct| ct, // Leave consts and types unchanged.
ty_op: |ty| ty, ct_op: |ct| ct,
}); ty_op: |ty| ty,
tcx.try_normalize_erasing_regions(param_env, ty).unwrap_or(ty) },
)
}; };
tcx.infer_ctxt().enter(|infcx| infcx.can_eq(param_env, normalize(src), normalize(dest)).is_ok()) tcx.infer_ctxt().enter(|infcx| infcx.can_eq(param_env, normalize(src), normalize(dest)).is_ok())
} }