Skip to content

Commit d486bfc

Browse files
committed
Normalize function type during validation
During inlining, the callee body is normalized and has types revealed, but some of locals corresponding to the arguments might come from the caller body which is not. As a result the caller body does not pass validation without additional normalization.
1 parent 9722952 commit d486bfc

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

compiler/rustc_mir/src/transform/validate.rs

+2
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,9 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
357357
}
358358
}
359359
TerminatorKind::Call { func, args, destination, cleanup, .. } => {
360+
let param_env = self.param_env.with_reveal_all_normalized(self.tcx);
360361
let func_ty = func.ty(&self.body.local_decls, self.tcx);
362+
let func_ty = self.tcx.normalize_erasing_regions(param_env, func_ty);
361363
match func_ty.kind() {
362364
ty::FnPtr(..) | ty::FnDef(..) => {}
363365
_ => self.fail(

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

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
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-
51
#![crate_type = "lib"]
62

73
pub fn bar<P>( // Error won't happen if "bar" is not generic
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
1-
// run-pass
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
26
// compile-flags:-Zmir-opt-level=2
37

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

12+
pub fn write_generic<T>(_t: T) {
13+
hide()();
14+
}
15+
1116
pub fn create() -> impl FnOnce() {
1217
|| ()
1318
}
1419

20+
pub fn hide() -> impl Fn() {
21+
write
22+
}
23+
1524
fn main() {
1625
write();
26+
write_generic(());
1727
}

0 commit comments

Comments
 (0)