about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-05-10 05:27:54 +0000
committerbors <bors@rust-lang.org>2022-05-10 05:27:54 +0000
commit2226f19f701fa53172fa48406c0f4ccb96b88ee6 (patch)
tree23c08672d9a9f5c636faf549ede16e6f11511d8a
parent87fd70c107b23fe08336a12a20a0f5e85561d499 (diff)
parent69e5b2fde01e93a19a8102201ed1b1d2cab0661d (diff)
downloadrust-2226f19f701fa53172fa48406c0f4ccb96b88ee6.tar.gz
rust-2226f19f701fa53172fa48406c0f4ccb96b88ee6.zip
Auto merge of #96808 - cjgillot:impossible-trait, r=compiler-errors
Detect trait fulfillment in `subst_and_check_impossible_predicates`

Split from https://github.com/rust-lang/rust/pull/91743
r? `@compiler-errors`
-rw-r--r--compiler/rustc_trait_selection/src/traits/mod.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs
index 8240f5c542a..81819534e8b 100644
--- a/compiler/rustc_trait_selection/src/traits/mod.rs
+++ b/compiler/rustc_trait_selection/src/traits/mod.rs
@@ -432,6 +432,9 @@ pub fn impossible_predicates<'tcx>(
     debug!("impossible_predicates(predicates={:?})", predicates);
 
     let result = tcx.infer_ctxt().enter(|infcx| {
+        // HACK: Set tainted by errors to gracefully exit in case of overflow.
+        infcx.set_tainted_by_errors();
+
         let param_env = ty::ParamEnv::reveal_all();
         let mut selcx = SelectionContext::new(&infcx);
         let mut fulfill_cx = FulfillmentContext::new();
@@ -448,6 +451,9 @@ pub fn impossible_predicates<'tcx>(
 
         let errors = fulfill_cx.select_all_or_error(&infcx);
 
+        // Clean up after ourselves
+        let _ = infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
+
         !errors.is_empty()
     });
     debug!("impossible_predicates = {:?}", result);
@@ -461,6 +467,14 @@ fn subst_and_check_impossible_predicates<'tcx>(
     debug!("subst_and_check_impossible_predicates(key={:?})", key);
 
     let mut predicates = tcx.predicates_of(key.0).instantiate(tcx, key.1).predicates;
+
+    // Specifically check trait fulfillment to avoid an error when trying to resolve
+    // associated items.
+    if let Some(trait_def_id) = tcx.trait_of_item(key.0) {
+        let trait_ref = ty::TraitRef::from_method(tcx, trait_def_id, key.1);
+        predicates.push(ty::Binder::dummy(trait_ref).to_poly_trait_predicate().to_predicate(tcx));
+    }
+
     predicates.retain(|predicate| !predicate.needs_subst());
     let result = impossible_predicates(tcx, predicates);