Skip to content

Commit 084fc29

Browse files
authored
Rollup merge of #79193 - tmiasko:revert-78969-normalize, r=davidtwco
Revert #78969 "Normalize function type during validation" Closes #79066. Reopens #78442.
2 parents 8216b35 + 0ab4458 commit 084fc29

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed

compiler/rustc_mir/src/transform/validate.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ pub struct Validator {
3838
impl<'tcx> MirPass<'tcx> for Validator {
3939
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
4040
let def_id = body.source.def_id();
41-
// We need to param_env_reveal_all_normalized, as some optimizations
42-
// change types in ways that require unfolding opaque types.
43-
let param_env = tcx.param_env_reveal_all_normalized(def_id);
41+
let param_env = tcx.param_env(def_id);
4442
let mir_phase = self.mir_phase;
4543

4644
let always_live_locals = AlwaysLiveLocals::new(body);
@@ -81,6 +79,7 @@ pub fn equal_up_to_regions(
8179
}
8280

8381
// Normalize lifetimes away on both sides, then compare.
82+
let param_env = param_env.with_reveal_all_normalized(tcx);
8483
let normalize = |ty: Ty<'tcx>| {
8584
tcx.normalize_erasing_regions(
8685
param_env,
@@ -168,14 +167,17 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
168167
return true;
169168
}
170169
// Normalize projections and things like that.
171-
let src = self.tcx.normalize_erasing_regions(self.param_env, src);
172-
let dest = self.tcx.normalize_erasing_regions(self.param_env, dest);
170+
// FIXME: We need to reveal_all, as some optimizations change types in ways
171+
// that require unfolding opaque types.
172+
let param_env = self.param_env.with_reveal_all_normalized(self.tcx);
173+
let src = self.tcx.normalize_erasing_regions(param_env, src);
174+
let dest = self.tcx.normalize_erasing_regions(param_env, dest);
173175

174176
// Type-changing assignments can happen when subtyping is used. While
175177
// all normal lifetimes are erased, higher-ranked types with their
176178
// late-bound lifetimes are still around and can lead to type
177179
// differences. So we compare ignoring lifetimes.
178-
equal_up_to_regions(self.tcx, self.param_env, src, dest)
180+
equal_up_to_regions(self.tcx, param_env, src, dest)
179181
}
180182
}
181183

@@ -363,7 +365,6 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
363365
}
364366
TerminatorKind::Call { func, args, destination, cleanup, .. } => {
365367
let func_ty = func.ty(&self.body.local_decls, self.tcx);
366-
let func_ty = self.tcx.normalize_erasing_regions(self.param_env, func_ty);
367368
match func_ty.kind() {
368369
ty::FnPtr(..) | ty::FnDef(..) => {}
369370
_ => self.fail(

src/test/ui/issues/issue-50865-private-impl-trait/auxiliary/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// revisions: default miropt
2+
//[miropt]compile-flags: -Z mir-opt-level=2
3+
// ~^ This flag is for #77668, it used to be ICE.
4+
15
#![crate_type = "lib"]
26

37
pub fn bar<P>( // Error won't happen if "bar" is not generic
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,17 @@
1-
// Regression test for various issues related to normalization & inlining.
2-
// * #68347, #77306, #77668 - missed normalization during inlining.
3-
// * #78442 - missed normalization in validator after inlining.
4-
//
5-
// build-pass
1+
// run-pass
62
// compile-flags:-Zmir-opt-level=2
73

4+
// Previously ICEd because we did not normalize during inlining,
5+
// see https://github.com/rust-lang/rust/pull/77306 for more discussion.
6+
87
pub fn write() {
98
create()()
109
}
1110

12-
pub fn write_generic<T>(_t: T) {
13-
hide()();
14-
}
15-
1611
pub fn create() -> impl FnOnce() {
1712
|| ()
1813
}
1914

20-
pub fn hide() -> impl Fn() {
21-
write
22-
}
23-
2415
fn main() {
2516
write();
26-
write_generic(());
2717
}

0 commit comments

Comments
 (0)