about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src/traits/mod.rs
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2025-01-14 01:50:53 +0000
committerMichael Goulet <michael@errs.io>2025-01-14 01:51:16 +0000
commit377dbc96a6d5b7d22b75d4bd98fd00d9e1bb194e (patch)
treec918f98edd11b94c6bbb3c2bffab219bea89cc53 /compiler/rustc_trait_selection/src/traits/mod.rs
parent2ae9916816a448fcaab3b2da461de754eda0055a (diff)
downloadrust-377dbc96a6d5b7d22b75d4bd98fd00d9e1bb194e.tar.gz
rust-377dbc96a6d5b7d22b75d4bd98fd00d9e1bb194e.zip
Leak check in impossible_predicates to avoid monomorphizing impossible instances
Diffstat (limited to 'compiler/rustc_trait_selection/src/traits/mod.rs')
-rw-r--r--compiler/rustc_trait_selection/src/traits/mod.rs15
1 files changed, 12 insertions, 3 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs
index 1dcd0d0dfb8..da16a742099 100644
--- a/compiler/rustc_trait_selection/src/traits/mod.rs
+++ b/compiler/rustc_trait_selection/src/traits/mod.rs
@@ -714,9 +714,18 @@ pub fn impossible_predicates<'tcx>(tcx: TyCtxt<'tcx>, predicates: Vec<ty::Clause
     }
     let errors = ocx.select_all_or_error();
 
-    let result = !errors.is_empty();
-    debug!("impossible_predicates = {:?}", result);
-    result
+    if !errors.is_empty() {
+        return true;
+    }
+
+    // Leak check for any higher-ranked trait mismatches.
+    // We only need to do this in the old solver, since the new solver already
+    // leak-checks.
+    if !infcx.next_trait_solver() && infcx.leak_check(ty::UniverseIndex::ROOT, None).is_err() {
+        return true;
+    }
+
+    false
 }
 
 fn instantiate_and_check_impossible_predicates<'tcx>(