about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src/transform
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-09-02 18:21:58 +0200
committerGitHub <noreply@github.com>2022-09-02 18:21:58 +0200
commit938897e2e429445dca5a549b5d4eb194a291a7c2 (patch)
treeb8183ee6ccaa30a69ca70623e6724b3ba67e9d0c /compiler/rustc_const_eval/src/transform
parent9353538c7bea6edb245457712cec720305c4576e (diff)
parent96d4137deed6c52c6db2dd19568c37d1c160f1e7 (diff)
downloadrust-938897e2e429445dca5a549b5d4eb194a291a7c2.tar.gz
rust-938897e2e429445dca5a549b5d4eb194a291a7c2.zip
Rollup merge of #100121 - Nilstrieb:mir-validator-param-env, r=oli-obk
Try normalizing types without RevealAll in ParamEnv in MIR validation

Before, the MIR validator used RevealAll in its ParamEnv for type
checking. This could cause false negatives in some cases due to
RevealAll ParamEnvs not always use all predicates as expected here.

Since some MIR passes like inlining use RevealAll as well, keep using
it in the MIR validator too, but when it fails usign RevealAll, also
try the check without it, to stop false negatives.

Fixes #99866

cc ````````@compiler-errors```````` who nicely helped me on zulip
Diffstat (limited to 'compiler/rustc_const_eval/src/transform')
-rw-r--r--compiler/rustc_const_eval/src/transform/validate.rs17
1 files changed, 12 insertions, 5 deletions
diff --git a/compiler/rustc_const_eval/src/transform/validate.rs b/compiler/rustc_const_eval/src/transform/validate.rs
index b662513e70f..b7988625839 100644
--- a/compiler/rustc_const_eval/src/transform/validate.rs
+++ b/compiler/rustc_const_eval/src/transform/validate.rs
@@ -181,16 +181,23 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
         if (src, dest).has_opaque_types() {
             return true;
         }
-        // Normalize projections and things like that.
-        let param_env = self.param_env.with_reveal_all_normalized(self.tcx);
-        let src = self.tcx.normalize_erasing_regions(param_env, src);
-        let dest = self.tcx.normalize_erasing_regions(param_env, dest);
 
+        // Normalize projections and things like that.
         // Type-changing assignments can happen when subtyping is used. While
         // all normal lifetimes are erased, higher-ranked types with their
         // late-bound lifetimes are still around and can lead to type
         // differences. So we compare ignoring lifetimes.
-        equal_up_to_regions(self.tcx, param_env, src, dest)
+
+        // First, try with reveal_all. This might not work in some cases, as the predicates
+        // can be cleared in reveal_all mode. We try the reveal first anyways as it is used
+        // by some other passes like inlining as well.
+        let param_env = self.param_env.with_reveal_all_normalized(self.tcx);
+        if equal_up_to_regions(self.tcx, param_env, src, dest) {
+            return true;
+        }
+
+        // If this fails, we can try it without the reveal.
+        equal_up_to_regions(self.tcx, self.param_env, src, dest)
     }
 }