@@ -9,7 +9,7 @@ use rustc_hir as hir;
9
9
use rustc_hir:: def:: { CtorKind , CtorOf , DefKind , Res } ;
10
10
use rustc_hir:: def_id:: DefId ;
11
11
use rustc_hir:: { Expr , FnDecl , LangItem , TyKind , Unsafety } ;
12
- use rustc_infer:: infer:: TyCtxtInferExt ;
12
+ use rustc_infer:: infer:: { TyCtxtInferExt , type_variable :: { TypeVariableOrigin , TypeVariableOriginKind } } ;
13
13
use rustc_lint:: LateContext ;
14
14
use rustc_middle:: mir:: interpret:: { ConstValue , Scalar } ;
15
15
use rustc_middle:: ty:: {
@@ -18,7 +18,7 @@ use rustc_middle::ty::{
18
18
} ;
19
19
use rustc_middle:: ty:: { GenericArg , GenericArgKind } ;
20
20
use rustc_span:: symbol:: Ident ;
21
- use rustc_span:: { sym, Span , Symbol } ;
21
+ use rustc_span:: { sym, Span , Symbol , DUMMY_SP } ;
22
22
use rustc_target:: abi:: { Size , VariantIdx } ;
23
23
use rustc_trait_selection:: infer:: InferCtxtExt ;
24
24
use rustc_trait_selection:: traits:: query:: normalize:: AtExt ;
@@ -153,7 +153,7 @@ pub fn implements_trait<'tcx>(
153
153
trait_id : DefId ,
154
154
ty_params : & [ GenericArg < ' tcx > ] ,
155
155
) -> bool {
156
- implements_trait_with_env ( cx. tcx , cx. param_env , ty, trait_id, ty_params)
156
+ implements_trait_with_env ( cx. tcx , cx. param_env , ty, trait_id, ty_params. iter ( ) . map ( | & arg| Some ( arg ) ) )
157
157
}
158
158
159
159
/// Same as `implements_trait` but allows using a `ParamEnv` different from the lint context.
@@ -162,7 +162,7 @@ pub fn implements_trait_with_env<'tcx>(
162
162
param_env : ParamEnv < ' tcx > ,
163
163
ty : Ty < ' tcx > ,
164
164
trait_id : DefId ,
165
- ty_params : & [ GenericArg < ' tcx > ] ,
165
+ ty_params : impl IntoIterator < Item = Option < GenericArg < ' tcx > > > ,
166
166
) -> bool {
167
167
// Clippy shouldn't have infer types
168
168
assert ! ( !ty. needs_infer( ) ) ;
@@ -171,8 +171,12 @@ pub fn implements_trait_with_env<'tcx>(
171
171
if ty. has_escaping_bound_vars ( ) {
172
172
return false ;
173
173
}
174
- let ty_params = tcx. mk_substs ( ty_params. iter ( ) ) ;
175
174
let infcx = tcx. infer_ctxt ( ) . build ( ) ;
175
+ let orig = TypeVariableOrigin {
176
+ kind : TypeVariableOriginKind :: MiscVariable ,
177
+ span : DUMMY_SP ,
178
+ } ;
179
+ let ty_params = tcx. mk_substs ( ty_params. into_iter ( ) . map ( |arg| arg. unwrap_or_else ( || infcx. next_ty_var ( orig) . into ( ) ) ) ) ;
176
180
infcx
177
181
. type_implements_trait ( trait_id, ty, ty_params, param_env)
178
182
. must_apply_modulo_regions ( )
0 commit comments