about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-08-26 06:05:06 +0000
committerbors <bors@rust-lang.org>2022-08-26 06:05:06 +0000
commit983f4daddf238d114c4adc4751c5528fc6695a5a (patch)
tree7d5722e127423873e593571da3211b37165c3b2d /compiler/rustc_trait_selection/src
parent13a6aaffdf6bd6f1bce000b09aa390e93d6aca77 (diff)
parentc4a5b142113ce9d161fcb653fcb3ec11c45680bf (diff)
downloadrust-983f4daddf238d114c4adc4751c5528fc6695a5a.tar.gz
rust-983f4daddf238d114c4adc4751c5528fc6695a5a.zip
Auto merge of #100705 - compiler-errors:issue-100620, r=oli-obk
Avoid reporting overflow in `is_impossible_method`

Fixes #100620

We're evaluating a new predicate in a different param-env than it was checked during typeck, so be more careful about handling overflow errors. Instead of using `FulfillmentCtxt`, using `InferCtxt::evaluate_obligation` by itself will give us back the overflow error, so we can throw it away properly.

This may give us more false-positives, but it doesn't regress the `<HashMap as Iterator>::rev` example that originally motivated adding `is_impossible_method` in the first place.
Diffstat (limited to 'compiler/rustc_trait_selection/src')
-rw-r--r--compiler/rustc_trait_selection/src/traits/mod.rs13
1 files changed, 10 insertions, 3 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs
index 904c81f9215..e11ea7751aa 100644
--- a/compiler/rustc_trait_selection/src/traits/mod.rs
+++ b/compiler/rustc_trait_selection/src/traits/mod.rs
@@ -579,9 +579,16 @@ fn is_impossible_method<'tcx>(
     });
 
     tcx.infer_ctxt().ignoring_regions().enter(|ref infcx| {
-        let mut fulfill_ctxt = <dyn TraitEngine<'_>>::new(tcx);
-        fulfill_ctxt.register_predicate_obligations(infcx, predicates_for_trait);
-        !fulfill_ctxt.select_all_or_error(infcx).is_empty()
+        for obligation in predicates_for_trait {
+            // Ignore overflow error, to be conservative.
+            if let Ok(result) = infcx.evaluate_obligation(&obligation)
+                && !result.may_apply()
+            {
+                return true;
+            }
+        }
+
+        false
     })
 }