about summary refs log tree commit diff
path: root/src/tools/clippy/clippy_utils
diff options
context:
space:
mode:
authorAman Arora <me@aman-arora.com>2021-07-06 05:38:15 -0400
committerAman Arora <me@aman-arora.com>2021-07-06 14:38:10 -0400
commit8ef5212effdd5c5b904e51e68fc99c71fb87a1e9 (patch)
tree6fbbbcf26fc0fe81791dd1efeb719cba181ffb3d /src/tools/clippy/clippy_utils
parent969a6c2481c41cea793708f7fdd2f96a3397143f (diff)
downloadrust-8ef5212effdd5c5b904e51e68fc99c71fb87a1e9.tar.gz
rust-8ef5212effdd5c5b904e51e68fc99c71fb87a1e9.zip
Make type_implements_trait not a query
Diffstat (limited to 'src/tools/clippy/clippy_utils')
-rw-r--r--src/tools/clippy/clippy_utils/src/ty.rs14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/tools/clippy/clippy_utils/src/ty.rs b/src/tools/clippy/clippy_utils/src/ty.rs
index 2808fc35e2a..8857e77d898 100644
--- a/src/tools/clippy/clippy_utils/src/ty.rs
+++ b/src/tools/clippy/clippy_utils/src/ty.rs
@@ -15,6 +15,7 @@ use rustc_span::sym;
 use rustc_span::symbol::{Ident, Symbol};
 use rustc_span::DUMMY_SP;
 use rustc_trait_selection::traits::query::normalize::AtExt;
+use rustc_trait_selection::infer::InferCtxtExt;
 
 use crate::{match_def_path, must_use_attr};
 
@@ -112,6 +113,7 @@ pub fn has_iter_method(cx: &LateContext<'_>, probably_ref_ty: Ty<'_>) -> Option<
 }
 
 /// Checks whether a type implements a trait.
+/// The function returns false in case the type contains an inference variable.
 /// See also `get_trait_def_id`.
 pub fn implements_trait<'tcx>(
     cx: &LateContext<'tcx>,
@@ -119,18 +121,18 @@ pub fn implements_trait<'tcx>(
     trait_id: DefId,
     ty_params: &[GenericArg<'tcx>],
 ) -> bool {
-    // Do not check on infer_types to avoid panic in evaluate_obligation.
-    if ty.has_infer_types() {
-        return false;
-    }
+    // Clippy shouldn't have infer types
+    assert!(!ty.needs_infer());
+
     let ty = cx.tcx.erase_regions(ty);
     if ty.has_escaping_bound_vars() {
         return false;
     }
     let ty_params = cx.tcx.mk_substs(ty_params.iter());
-    cx.tcx
-        .type_implements_trait((trait_id, ty, ty_params, cx.param_env))
+    cx.tcx.infer_ctxt().enter(|infcx|
+        infcx.type_implements_trait(trait_id, ty, ty_params, cx.param_env)
         .must_apply_modulo_regions()
+    )
 }
 
 /// Checks whether this type implements `Drop`.