about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2021-07-04 11:26:32 -0400
committerNiko Matsakis <niko@alum.mit.edu>2021-07-04 11:28:20 -0400
commit40ee019c17dc35a1681d48246b8cdd3d6563702f (patch)
treeb5e9795febaff40ffd5ab83439c2fcecc44ca655 /compiler/rustc_trait_selection
parent26f7030b16716712070d04ad938e9762b8756f7f (diff)
downloadrust-40ee019c17dc35a1681d48246b8cdd3d6563702f.tar.gz
rust-40ee019c17dc35a1681d48246b8cdd3d6563702f.zip
allow inference vars in type_implements_trait
Diffstat (limited to 'compiler/rustc_trait_selection')
-rw-r--r--compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs4
-rw-r--r--compiler/rustc_trait_selection/src/traits/mod.rs16
2 files changed, 15 insertions, 5 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
index 5c35b515f3d..dc765f5228b 100644
--- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
+++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
@@ -2396,7 +2396,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
                     normalized_ty,
                 );
                 debug!("suggest_await_before_try: try_trait_obligation {:?}", try_obligation);
-                if self.predicate_may_hold(&try_obligation) && impls_future {
+                if self.predicate_may_hold(&try_obligation)
+                    && impls_future.must_apply_modulo_regions()
+                {
                     if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
                         if snippet.ends_with('?') {
                             err.span_suggestion_verbose(
diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs
index d65a596a827..c5c1da2d2c0 100644
--- a/compiler/rustc_trait_selection/src/traits/mod.rs
+++ b/compiler/rustc_trait_selection/src/traits/mod.rs
@@ -542,8 +542,7 @@ fn vtable_trait_first_method_offset<'tcx>(
 }
 
 /// Check whether a `ty` implements given trait(trait_def_id).
-///
-/// NOTE: Always return `false` for a type which needs inference.
+/// See query definition for details.
 fn type_implements_trait<'tcx>(
     tcx: TyCtxt<'tcx>,
     key: (
@@ -552,7 +551,7 @@ fn type_implements_trait<'tcx>(
         SubstsRef<'tcx>,
         ParamEnv<'tcx>,
     ),
-) -> bool {
+) -> EvaluationResult {
     let (trait_def_id, ty, params, param_env) = key;
 
     debug!(
@@ -562,13 +561,22 @@ fn type_implements_trait<'tcx>(
 
     let trait_ref = ty::TraitRef { def_id: trait_def_id, substs: tcx.mk_substs_trait(ty, params) };
 
+    // FIXME: If there are inference variables anywhere, just give up and assume
+    // we don't know the answer. This works around the ICEs that would result from
+    // using those inference variables within the `infer_ctxt` we create below.
+    // Really we should be using canonicalized variables, or perhaps removing
+    // this query altogether.
+    if (trait_ref, param_env).needs_infer() {
+        return EvaluationResult::EvaluatedToUnknown;
+    }
+
     let obligation = Obligation {
         cause: ObligationCause::dummy(),
         param_env,
         recursion_depth: 0,
         predicate: trait_ref.without_const().to_predicate(tcx),
     };
-    tcx.infer_ctxt().enter(|infcx| infcx.predicate_must_hold_modulo_regions(&obligation))
+    tcx.infer_ctxt().enter(|infcx| infcx.evaluate_obligation_no_overflow(&obligation))
 }
 
 pub fn provide(providers: &mut ty::query::Providers) {