@@ -15,6 +15,7 @@ use rustc_span::sym;
15
15
use rustc_span:: symbol:: { Ident , Symbol } ;
16
16
use rustc_span:: DUMMY_SP ;
17
17
use rustc_trait_selection:: traits:: query:: normalize:: AtExt ;
18
+ use rustc_trait_selection:: infer:: InferCtxtExt ;
18
19
19
20
use crate :: { match_def_path, must_use_attr} ;
20
21
@@ -112,25 +113,26 @@ pub fn has_iter_method(cx: &LateContext<'_>, probably_ref_ty: Ty<'_>) -> Option<
112
113
}
113
114
114
115
/// Checks whether a type implements a trait.
116
+ /// The function returns false in case the type contains an inference variable.
115
117
/// See also `get_trait_def_id`.
116
118
pub fn implements_trait < ' tcx > (
117
119
cx : & LateContext < ' tcx > ,
118
120
ty : Ty < ' tcx > ,
119
121
trait_id : DefId ,
120
122
ty_params : & [ GenericArg < ' tcx > ] ,
121
123
) -> 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
+
126
127
let ty = cx. tcx . erase_regions ( ty) ;
127
128
if ty. has_escaping_bound_vars ( ) {
128
129
return false ;
129
130
}
130
131
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 )
133
134
. must_apply_modulo_regions ( )
135
+ )
134
136
}
135
137
136
138
/// Checks whether this type implements `Drop`.
0 commit comments