@@ -9,7 +9,7 @@ use rustc_hir as hir;
99use rustc_hir:: def:: { CtorKind , CtorOf , DefKind , Res } ;
1010use rustc_hir:: def_id:: DefId ;
1111use rustc_hir:: { Expr , FnDecl , LangItem , TyKind , Unsafety } ;
12- use rustc_infer:: infer:: TyCtxtInferExt ;
12+ use rustc_infer:: infer:: { TyCtxtInferExt , type_variable :: { TypeVariableOrigin , TypeVariableOriginKind } } ;
1313use rustc_lint:: LateContext ;
1414use rustc_middle:: mir:: interpret:: { ConstValue , Scalar } ;
1515use rustc_middle:: ty:: {
@@ -18,7 +18,7 @@ use rustc_middle::ty::{
1818} ;
1919use rustc_middle:: ty:: { GenericArg , GenericArgKind } ;
2020use rustc_span:: symbol:: Ident ;
21- use rustc_span:: { sym, Span , Symbol } ;
21+ use rustc_span:: { sym, Span , Symbol , DUMMY_SP } ;
2222use rustc_target:: abi:: { Size , VariantIdx } ;
2323use rustc_trait_selection:: infer:: InferCtxtExt ;
2424use rustc_trait_selection:: traits:: query:: normalize:: AtExt ;
@@ -153,7 +153,7 @@ pub fn implements_trait<'tcx>(
153153 trait_id : DefId ,
154154 ty_params : & [ GenericArg < ' tcx > ] ,
155155) -> 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 ) ) )
157157}
158158
159159/// 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>(
162162 param_env : ParamEnv < ' tcx > ,
163163 ty : Ty < ' tcx > ,
164164 trait_id : DefId ,
165- ty_params : & [ GenericArg < ' tcx > ] ,
165+ ty_params : impl IntoIterator < Item = Option < GenericArg < ' tcx > > > ,
166166) -> bool {
167167 // Clippy shouldn't have infer types
168168 assert ! ( !ty. needs_infer( ) ) ;
@@ -171,8 +171,12 @@ pub fn implements_trait_with_env<'tcx>(
171171 if ty. has_escaping_bound_vars ( ) {
172172 return false ;
173173 }
174- let ty_params = tcx. mk_substs ( ty_params. iter ( ) ) ;
175174 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 ( ) ) ) ) ;
176180 infcx
177181 . type_implements_trait ( trait_id, ty, ty_params, param_env)
178182 . must_apply_modulo_regions ( )
0 commit comments