]> git.lizzy.rs Git - rust.git/commitdiff
Normalize function type during validation
authorTomasz Miąsko <tomasz.miasko@gmail.com>
Thu, 12 Nov 2020 00:00:00 +0000 (00:00 +0000)
committerTomasz Miąsko <tomasz.miasko@gmail.com>
Thu, 12 Nov 2020 19:57:43 +0000 (20:57 +0100)
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.

compiler/rustc_mir/src/transform/validate.rs
src/test/ui/issues/issue-50865-private-impl-trait/auxiliary/lib.rs
src/test/ui/mir/mir-inlining/ice-issue-77306-1.rs

index e1e6e71acb5a8f80b02e3cde4f33a6b3251603d9..2fbfe13082f89613861c36e48a592e9ba6447fac 100644 (file)
@@ -357,7 +357,9 @@ fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location
                 }
             }
             TerminatorKind::Call { func, args, destination, cleanup, .. } => {
+                let param_env = self.param_env.with_reveal_all_normalized(self.tcx);
                 let func_ty = func.ty(&self.body.local_decls, self.tcx);
+                let func_ty = self.tcx.normalize_erasing_regions(param_env, func_ty);
                 match func_ty.kind() {
                     ty::FnPtr(..) | ty::FnDef(..) => {}
                     _ => self.fail(
index fb4bf2b8b44e7642e5f68244b9057cd2234e4f8f..f3a51b415facac0719b55f2e6f27f624def40e4b 100644 (file)
@@ -1,7 +1,3 @@
-// revisions: default miropt
-//[miropt]compile-flags: -Z mir-opt-level=2
-// ~^ This flag is for #77668, it used to be ICE.
-
 #![crate_type = "lib"]
 
 pub fn bar<P>( // Error won't happen if "bar" is not generic
index 4d083bf23215599a16ecf1c8f16cabcf6a678488..ccb279f7fa212c076a65348238bba678d7bc94f7 100644 (file)
@@ -1,17 +1,27 @@
-// run-pass
+// Regression test for various issues related to normalization & inlining.
+// * #68347, #77306, #77668 - missed normalization during inlining.
+// * #78442 - missed normalization in validator after inlining.
+//
+// build-pass
 // compile-flags:-Zmir-opt-level=2
 
-// Previously ICEd because we did not normalize during inlining,
-// see https://github.com/rust-lang/rust/pull/77306 for more discussion.
-
 pub fn write() {
     create()()
 }
 
+pub fn write_generic<T>(_t: T) {
+    hide()();
+}
+
 pub fn create() -> impl FnOnce() {
    || ()
 }
 
+pub fn hide() -> impl Fn() {
+    write
+}
+
 fn main() {
     write();
+    write_generic(());
 }