Skip to content

Commit 1120c5e

Browse files
committed
Auto merge of #101437 - compiler-errors:erase-normalize-ordering, r=tmandry
Normalize before erasing late-bound regions in `equal_up_to_regions` Normalize erasing regions **first**, before passing the type through a `BottomUpFolder` which erases late-bound regions too. The root cause of this issue is due to 96d4137, which removes a `normalize_erasing_regions` that happens before this call to `equal_up_to_regions`. While reverting that commit might be a fix, I think it was suspicious to be erasing late-bound regions first _then_ normalizing types in the first place in `equal_up_to_regions`. ----- I am tempted to ask the reviewer to review and `r+` this without a UI test, since the existing issues that I think this fixes are all incredibly difficult to minimize (anything hyper/warp related, given the nature of those libraries 😓) or impossible to reproduce locally (the miri test), namely: * This recently reported issue with tokio + warp: #101430 * This issue from `@RalfJung` about Miri being broken: #101344 * This additional issue reported in a comment by `@tmandry` (issue with fuchsia + hyper): #101344 (comment) I have locally verified that the repro in #101430 is fixed with this PR, but after a couple of hours of attempting to minimize this error and either failing to actually repro the ICE, or being overwhelmed with the number of traits and functions I need to inline into a UI test, I have basically given up. Thoughts are appreciated on how best to handle this. r? `@oli-obk` who is at the intersection of MIR and types-related stuff who may be able to give advice 😅
2 parents 8778809 + 76b494a commit 1120c5e

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

compiler/rustc_const_eval/src/transform/validate.rs

+15-14
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,21 @@ pub fn equal_up_to_regions<'tcx>(
9090

9191
// Normalize lifetimes away on both sides, then compare.
9292
let normalize = |ty: Ty<'tcx>| {
93-
let ty = ty.fold_with(&mut BottomUpFolder {
94-
tcx,
95-
// FIXME: We erase all late-bound lifetimes, but this is not fully correct.
96-
// If you have a type like `<for<'a> fn(&'a u32) as SomeTrait>::Assoc`,
97-
// this is not necessarily equivalent to `<fn(&'static u32) as SomeTrait>::Assoc`,
98-
// since one may have an `impl SomeTrait for fn(&32)` and
99-
// `impl SomeTrait for fn(&'static u32)` at the same time which
100-
// specify distinct values for Assoc. (See also #56105)
101-
lt_op: |_| tcx.lifetimes.re_erased,
102-
// Leave consts and types unchanged.
103-
ct_op: |ct| ct,
104-
ty_op: |ty| ty,
105-
});
106-
tcx.try_normalize_erasing_regions(param_env, ty).unwrap_or(ty)
93+
tcx.try_normalize_erasing_regions(param_env, ty).unwrap_or(ty).fold_with(
94+
&mut BottomUpFolder {
95+
tcx,
96+
// FIXME: We erase all late-bound lifetimes, but this is not fully correct.
97+
// If you have a type like `<for<'a> fn(&'a u32) as SomeTrait>::Assoc`,
98+
// this is not necessarily equivalent to `<fn(&'static u32) as SomeTrait>::Assoc`,
99+
// since one may have an `impl SomeTrait for fn(&32)` and
100+
// `impl SomeTrait for fn(&'static u32)` at the same time which
101+
// specify distinct values for Assoc. (See also #56105)
102+
lt_op: |_| tcx.lifetimes.re_erased,
103+
// Leave consts and types unchanged.
104+
ct_op: |ct| ct,
105+
ty_op: |ty| ty,
106+
},
107+
)
107108
};
108109
tcx.infer_ctxt().enter(|infcx| infcx.can_eq(param_env, normalize(src), normalize(dest)).is_ok())
109110
}

0 commit comments

Comments
 (0)