@@ -15,6 +15,7 @@ use rustc_span::sym;
1515use rustc_span:: symbol:: { Ident , Symbol } ;
1616use rustc_span:: DUMMY_SP ;
1717use rustc_trait_selection:: traits:: query:: normalize:: AtExt ;
18+ use rustc_trait_selection:: infer:: InferCtxtExt ;
1819
1920use crate :: { match_def_path, must_use_attr} ;
2021
@@ -112,25 +113,26 @@ pub fn has_iter_method(cx: &LateContext<'_>, probably_ref_ty: Ty<'_>) -> Option<
112113}
113114
114115/// Checks whether a type implements a trait.
116+ /// The function returns false in case the type contains an inference variable.
115117/// See also `get_trait_def_id`.
116118pub fn implements_trait < ' tcx > (
117119 cx : & LateContext < ' tcx > ,
118120 ty : Ty < ' tcx > ,
119121 trait_id : DefId ,
120122 ty_params : & [ GenericArg < ' tcx > ] ,
121123) -> bool {
122- // Do not check on infer_types to avoid panic in evaluate_obligation.
123- if ty. has_infer_types ( ) {
124- return false ;
125- }
124+ // Clippy shouldn't have infer types
125+ assert ! ( !ty. needs_infer( ) ) ;
126+
126127 let ty = cx. tcx . erase_regions ( ty) ;
127128 if ty. has_escaping_bound_vars ( ) {
128129 return false ;
129130 }
130131 let ty_params = cx. tcx . mk_substs ( ty_params. iter ( ) ) ;
131- cx. tcx
132- . type_implements_trait ( ( trait_id, ty, ty_params, cx. param_env ) )
132+ cx. tcx . infer_ctxt ( ) . enter ( |infcx|
133+ infcx . type_implements_trait ( trait_id, ty, ty_params, cx. param_env )
133134 . must_apply_modulo_regions ( )
135+ )
134136}
135137
136138/// Checks whether this type implements `Drop`.
0 commit comments