about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2025-07-20 22:33:04 +0000
committerCamille GILLOT <gillot.camille@gmail.com>2025-07-20 22:45:07 +0000
commit1987471d05854cc8b5014dab44e7648834c02213 (patch)
treedce0f8c54332578b7878af90833726233b81ab4e /compiler/rustc_mir_transform/src
parent82310651b93a594a3fd69015e1562186a080d94c (diff)
downloadrust-1987471d05854cc8b5014dab44e7648834c02213.tar.gz
rust-1987471d05854cc8b5014dab44e7648834c02213.zip
Consider parent predicates in ImpossiblePredicates pass.
Diffstat (limited to 'compiler/rustc_mir_transform/src')
-rw-r--r--compiler/rustc_mir_transform/src/impossible_predicates.rs26
1 files changed, 19 insertions, 7 deletions
diff --git a/compiler/rustc_mir_transform/src/impossible_predicates.rs b/compiler/rustc_mir_transform/src/impossible_predicates.rs
index 86e2bf6cb3c..5f116d7716d 100644
--- a/compiler/rustc_mir_transform/src/impossible_predicates.rs
+++ b/compiler/rustc_mir_transform/src/impossible_predicates.rs
@@ -27,7 +27,7 @@
 //! it's usually never invoked in this way.
 
 use rustc_middle::mir::{Body, START_BLOCK, TerminatorKind};
-use rustc_middle::ty::{TyCtxt, TypeVisitableExt};
+use rustc_middle::ty::{TyCtxt, TypeFlags, TypeVisitableExt};
 use rustc_trait_selection::traits;
 use tracing::trace;
 
@@ -36,14 +36,26 @@ use crate::pass_manager::MirPass;
 pub(crate) struct ImpossiblePredicates;
 
 impl<'tcx> MirPass<'tcx> for ImpossiblePredicates {
+    #[tracing::instrument(level = "trace", skip(self, tcx, body))]
     fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
-        let predicates = tcx
-            .predicates_of(body.source.def_id())
+        tracing::trace!(def_id = ?body.source.def_id());
+        let predicates = tcx.predicates_of(body.source.def_id()).instantiate_identity(tcx);
+        tracing::trace!(?predicates);
+        let predicates = predicates
             .predicates
-            .iter()
-            .filter_map(|(p, _)| if p.is_global() { Some(*p) } else { None });
-        if traits::impossible_predicates(tcx, traits::elaborate(tcx, predicates).collect()) {
-            trace!("found unsatisfiable predicates for {:?}", body.source);
+            .into_iter()
+            .filter(|p| {
+                !p.has_type_flags(
+                    // Only consider global clauses to simplify.
+                    TypeFlags::HAS_FREE_LOCAL_NAMES
+                    // Clauses that refer to unevaluated constants as they cause cycles.
+                    | TypeFlags::HAS_CT_PROJECTION,
+                )
+            })
+            .collect();
+        tracing::trace!(?predicates);
+        if traits::impossible_predicates(tcx, predicates) {
+            trace!("found unsatisfiable predicates");
             // Clear the body to only contain a single `unreachable` statement.
             let bbs = body.basic_blocks.as_mut();
             bbs.raw.truncate(1);